https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84386
Bug ID: 84386
Summary: Implicitly declared variables in BLOCK have scope of
including program unit
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: kargl at gcc dot gnu.org
Target Milestone: ---
See
https://groups.google.com/forum/#!topic/comp.lang.fortran/62PqdmItLeI
for details of the problem. The following code should execute
without hitting a 'STOP 1'.
program foo
call block1
print *
call block2
end program foo
!
! For an implicitly declared variable (e.g., i and j here), the
! scope of the variable is from the inclusive scoping unit. That
! is, 'j = 1' in block1 is implicitly declared to be in the
! namespace of block1. In addition, the implicitly declared 'i'
! in block bah is also in the namespace of block1.
!
subroutine block1
j = 1
bah: block
i = 42
j = 42
end block bah
if (i /= 42) stop 1 ! i should be 42
if (j /= 42) stop 1
end subroutine block1
!
! In the following 'i' has an implicit declaration in the scope
! of block2. The explicit declaration of 'i' in block bah means
! that this 'i' has the scope of bah.
!
subroutine block2
i = 1
j = 1
bah: block
integer i
i = 42
j = 42
if (i /= 42) stop 1
if (j /= 42) stop 1
end block bah
if (i /= 1) stop 1
if (j /= 42) stop 1
end subroutine block2