Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Construct-name constraints

OP1
New Contributor III
444 Views

Does the fortran standard has rules regarding  construct-name conflicts with other entity names? I tried to figure this out, but given the size of the fortran standard it's quite likely that I overlooked the relevant part.

In other words, is a code like the one below compliant, or is ifx correct to issue the error message "error #6444: Not a valid construct name."?

 

INTEGER :: S1
S1 : BLOCK
END BLOCK S1
END

 

0 Kudos
1 Solution
Steve_Lionel
Honored Contributor III
422 Views

Yes, there are rules, in clause 19 (Scopes, association, and definition).  19.3.1 defines various "classes" of local identifiers.  Named variables and named constructs are both "Class 1" local identifiers, and paragraph 3 then goes on to say:

Within its scope, a local identifier of one class shall not be the same as another local identifier of the same class, except that a generic name may be the same as the name of a procedure as explained in 15.4.3.4 or the same as the name of a derived type (7.5.10). A local identifier of one class may be the same as a local identifier of another class.

Therefore, the compiler is correct in complaining, though I'd prefer that the message be clearer.

View solution in original post

2 Replies
Steve_Lionel
Honored Contributor III
423 Views

Yes, there are rules, in clause 19 (Scopes, association, and definition).  19.3.1 defines various "classes" of local identifiers.  Named variables and named constructs are both "Class 1" local identifiers, and paragraph 3 then goes on to say:

Within its scope, a local identifier of one class shall not be the same as another local identifier of the same class, except that a generic name may be the same as the name of a procedure as explained in 15.4.3.4 or the same as the name of a derived type (7.5.10). A local identifier of one class may be the same as a local identifier of another class.

Therefore, the compiler is correct in complaining, though I'd prefer that the message be clearer.

Ron_Green
Moderator
377 Views

Our Standards guru is out on vacation this week.  I can ask when he returns.  gfortran 13.2.0 accepts this code FWIW

As a data point, NAG does not like this syntax either.  I'm not saying it's the final answer, but NAG is pretty darn good at following the Standard:

nagfor block.f90
NAG Fortran Compiler Release 7.2(Shin-Urayasu) Build 7203
Error: block.f90, line 2: Multiply defined symbol S1
       detected at <end-of-statement>@S1
Error: block.f90, line 3: Inappropriate use of symbol S1
       detected at END BLOCK@S1
Warning: block.f90, line 4: Unused local variable S1
[NAG Fortran Compiler pass 1 error termination, 2 errors, 1 warning]

 

 

0 Kudos
Reply