n = 10
call foo
contains
subroutine foo
real :: a(n)
common /blk/ n
print *, size(a)
end subroutine
end
block data
common /blk/ n
data n/20/
end
I have two Fortran compilers that print 10 and three that print 20. The specific text in the Fortran 2018 standard allows for both host-associated objects in specification expressions (10.1.11) as well as for forward-referenced implicitly-typed objects in COMMON. Is this case truly ambiguous, or is there text that I missed that resolves the problem?
For whatever it’s worth, I too think it’s section 19.5.1.4 on Host Association that governs the outcome, specifically paragraph 2 as indicated by
17 A name
18 that appears in the scoping unit as
…
27 (7) a variable-name in a common-block-object in a common-stmt,
…
38 is a local identifier in the scoping unit and any entity of the host that has this as its nongeneric name is inaccessible
39 by that name by host association.
Going by this verbiage, it makes sense the program outputs 20.