Hmm. Tricky. I'm sure it is a bad idea. I think it is legal (but still a
bad idea).
C1201 is not relevant; that part I'm sure of. It is about "An interface
block in a subprogram...". The interface block here is not in the
subprogram. It is accessed via USE in the suprogram, but that is not the
same thing as being in the subprogram. Yes, the distinction is
important. A USE statement is not like INCLUDE in this regard.
I think the most important bit of the standard on this is in 16.4.1.3
(of f2003; I don't pay much attention to f2008 and am certainly not well
equipped to give interpretations of it, except insomuch as f2003
pertains.)
"If an entity that is accessed by use association has the same name as
a host entity, the host entity is inaccessible by that name."
So basically, the USE statement blocks the host association. Within
INTERNAL, the name SUB refers to what is accessed via the USE. One
slightly tricky part is that the names are the same in this case. I
think the wording of the standard is a little off in that the "by that
name" doesn't quite catch it. I think it is more accurately that the
host entity is not accessible via host association. That seems to me to
fit the intention better, but I'll admit that the literal words of the
standard do say "by that name", which reads like you can't access it by
that name via the USE association either.
If I take the literal reading there (which I don't think is the right
reading), then I think the code would still be legal, but only because
you never access the name in internal so it doesn't matter if it is
inaccessible.
If you actually call sub from within internal, you have invalid code
anyway because that would count as recursion and you haven't declared
SUB to be recursive. But something like
call some_other_subroutine(sub)
would count as accessing the name without being recursive. So I think
that's the only case where I see much question. I think that would be
legal, but a literal reading seems to imply otherwise.
Do note that the restriction in question is not a constraint, so
compilers aren't required to diagnose it anyway, even with the literal
reading. (Good thing because the literal reading makes it a strange
special case that I could well see as being unreasonable to diagnose
with separate compilation of the module.)
--
Richard Maine | Good judgment comes from experience;
email: last name at domain . net | experience comes from bad judgment.
domain: summertriangle | -- Mark Twain