fpt and WinFPT Reference Manual - Command-line Commands

| SimCon Home | Ref Manual Home |

CHECK PROTECTED

Syntax:

[DO NOT] CHECK PROTECTED [SYMBOLS] [DO NOT] CHECK PROTECTED VARIABLES

fpt Version

This command is available in fpt versions 4.0-g and later.

Function:

In Fortran 2008 and later, the attribute PROTECTED may be specified for variables declared in modules. The protected variables may be assigned only in module sub-programs in the modules in which they are declared.

The implementation of the PROTECTED attribute suffers from the same problem as the INTENT(IN) attribute. It is not usually possible for a compiler to detect the situation where a protected variable is passed into an external routine with no defined interface and is assigned in that routine.

fpt makes the check.

The check is also carried out at the end of the symbol usage check. Please see the command CHECK USAGE.

Where to Use this Command

Operating system command line Yes
Configuration file, config.fsp Yes
Specification (fsp) files, *.fsp Yes
Interactively, to FPT> prompt Yes
Interactive command files Yes
Embedded in the Fortran code Yes

Default

No check is made by default (Note that defaults may be changed in the configuration file).

Examples

The test program shown below illustrates the problem. It compiles without error under gfortran.

MODULE m_protected INTEGER,PROTECTED :: prot_i1,prot_i2,prot_i3 CONTAINS ! ======== SUBROUTINE set_i1(i) INTEGER :: i prot_i1 = i END SUBROUTINE set_i1 : : END MODULE m_protected ! ****************************************************** ! Deliberately external to hide the assignment from the compiler SUBROUTINE set_integer(a,b) INTEGER :: a,b a = b END SUBROUTINE set_integer ! ************************************************** PROGRAM t_protected ! This should be illegal but gfortran can't trap it. ! It has been added to the fpt usage check CALL set_integer(prot_i1,1) WRITE(*,'("Protected test")') WRITE(*,*) prot_i1 END PROGRAM t_protected ! *****************************************************

The command CHECK PROTECTED generates the report:

Check of Protected Variables ============================ (fpt command: check protected variables) Illegal assignment of PROTECTED symbol: prot_i3 Line: 71, File: /home/john/projects/WinFPT/fpt/fpttest/f08.f90 ! ! This should be illegal but gfortran can't trap it. ! It has been added to the fpt usage check CALL set_integer(prot_i1,1) ------------------------------------------------------------------------------ !!! ERROR !!! Number 3901 Severity 2 (Worst 0) Count 1 Line 77 File: /home/john/projects/WinFPT/fpt/fpttest/f08.f90 CALL set_integer(prot_i1,1) ^ Illegal assignment of PROTECTED symbol ------------------------------------------------------------------------------ Protected Illegally Percentage Total variables assiged violations 3 1 33.333% 1 *******************************************************************************

The error message is also written in the code output by fpt.

See Also:

CHECK USAGE

Copyright ©1995 to 2024 Software Validation Ltd. All rights reserved.