------- Comment #6 from burnus at gcc dot gnu dot org 2006-12-06 21:30 ------- > Created an attachment (id=12760) --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=12760&action=view) [edit] > Fix and testcases. Thanks.
> It is there, up to some adjustments to interpretation of the standard. Ok, I did some reading and got an email with a quote by Malcolm Cohen and a reply to that quote by Richard Main. See: http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/44aa13e0102ec83d/) The relevant part of the standard is as follows (and no, I don't want to discuss the meaning of the word "is" [cf. c.l.fortran]) -- Fortran 2003, Section 11.2.1; F95, Sec 11.3.2: "Two or more accessible entities, other than generic interfaces or defined operators, may have the same identifier only if the identifier is not used to refer to an entity in the scoping unit. Generic interfaces and defined operators are handled as described in section 16.2.3. Except for these cases, the local identifier of any entity given accessibility by a USE statement shall differ from the local identifiers of all other entities accessible to the scoping unit through USE statements and otherwise." [plus some other places for some of the following remarks] That means (if I understand it correctly): a) Using an ambigious symbol in a program, module, procedure twice, which is ambious is forbidden. This makes the BAD8 and BAD9 of the Fortran standard invalid, if they are put in one "module foo ... end module" or "program bar ... end program" or "subroutine func ... end subroutine" block. Or when one is locally declared, which is imported ("use") from a module. b) Importing a symbol (subroutine, variable) from two module, which are ambiguous is ok as long as they are not referred. ",only:" is enough to count as referred to. c) For generic interfaces and operators the standard is ambiguous. Richard Main thinks that they are treated alike (b), Malcolm Cohn thinks they should be treated more strictly, which already makes "use mod1; use mod2" of my example invalid. d) Having e.g. a variable in module and an interface/procedure in another routine is always invalid. Assuming my understanding is correct, the following cases are not correctly treated: a) BAD8 and BAD9 as already the module ("module x" in the patch) shouldn't compile - or give a warning. [I would go for the warning as the intel compiler does] b) May "use mod1; use mod2" should also produce a warning even without ", only:" as there the generic interface "generic" is ambigious. Or not. NAG f95 (future version) produces an error, following Malcolm Cohen of NAG which is what sunf95 and g95 are doing as well; ifort accepts it without any warning and Richard Main thinks it is ok. Do either one. [Maybe a warning is not bad - it is between error (some compilers) and silence (other compilers) and we don't take sides ;-) ] c) Gfortran is a bit inconsequent with regards to ", only:" use mod1 use mod2,only: foo compiles without an error/warning whereas for use mod1,only: foo use mod2 it gives a warning. ifort is consequent in this regard and warns in both cases (for generic interfaces) - or in none (see d). d) Interestingly, if I have module mod1; contains; subroutine foo(); end subroutine foo; end module module mod2; contains; subroutine foo(); end subroutine foo; end module program use mod1, only: foo use mod2 end program Neither ifort nor sunf95 give error or warnings. (For generic interfaces they give a warning (ifort) or an error (sunf95).) (g95 and f95 don't count since they give currently either always an error nor never.) I don't see a reason why generic interfaces should be treated more strictly and thus go with this patch [gfortran gives then a warning]. e) Slightly related: use mod1 ! imports subroutine foo real :: foo end gives the error: Error: Symbol 'foo' at (1) cannot have a type -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30068