[Bug fortran/104812] Construct-name with same variable name in scope

sgk at troutmask dot apl.washington.edu gcc-bugzilla@gcc.gnu.org
Thu Mar 10 14:57:33 GMT 2022


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104812

--- Comment #3 from Steve Kargl <sgk at troutmask dot apl.washington.edu> ---
On Thu, Mar 10, 2022 at 11:27:41AM +0000, fruitclover at gmail dot com wrote:
> 
> --- Comment #2 from Mike K. <fruitclover at gmail dot com> ---
> Thanks, and subroutine s2 conforming Fortran 2018, 19.4, right?
> 

No. The logical variable 'x' is a local entity.  You
have 'x:i block' where this 'x' is a construct name
and conflicts with the local variable.

Note, the prohibition in the standard is not a numbered
constraint, which means a compiler need not issue an
error or warning.  It is expected that the programmer
writes conforming code.

If you actually try to use the variable 'x', you'll get 
an error.

subroutine s2
  logical :: x
  x: block
    x = .true.
  end block x
  if (x) print *,'whoops'
end

% gfcx -c a.f90 
a.f90:4:6:

    4 |     x = .true.
      |      1
Error: 'x' at (1) is not a variable
a.f90:6:8:

    6 |   if (x) print *,'whoops'
      |        1
Error: Symbol at (1) is not appropriate for an expression'


More information about the Gcc-bugs mailing list