[Bug fortran/53940] warn about duplicate USE

2012-07-12 Thread burnus at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53940

Tobias Burnus burnus at gcc dot gnu.org changed:

   What|Removed |Added

 CC||burnus at gcc dot gnu.org

--- Comment #1 from Tobias Burnus burnus at gcc dot gnu.org 2012-07-12 
13:08:51 UTC ---
(In reply to comment #0)
 The old DEC Alpha compiler does:
[...]
 f90: Error: duplicate_use.f90, line 8: The same named entity from different
 modules and/or program units cannot be referenced.   [VAR]
   print*, var
 --^

That that one is completely bogus. The standard allows multiple inclusion of
the same variable; and your variable is - contrary to the error message - from
the same module. For instance, the following is valid:

  use mod
  use mod, var2 = var

That way one has use-associated the variable var under the name var and
under the name var2.


The Fortran standard (here: Fortran 2008, 11.2.2 The USE statement and use
association) has:

More than one USE statement for a given module may appear in a specification
part. If one of the USE statements is without an ONLY option, all public
entities in the module are accessible. If all the USE statements have ONLY
options, only those entities in one or more of the only-lists are accessible.

An accessible entity in the referenced module has one or more local
identifiers. [...] (Cf. http://gcc.gnu.org/wiki/GFortranStandards)


Hence, I am inclined to reject the warning proposal. (The request to print an 
error is simply invalid.)

However, if you can give a good argument why you want to have a special warning
and when it exactly should be triggered, one could consider it. However, I
currently fail to see a real use case for that.

Note: module entities which have been explicitly use associated but aren't used
are warned for. Thus, one could consider to warn if the same entity under the
same name is multiple times use associated. However, that's not only valid but
seems to be also harmless and a rather special case.


[Bug fortran/53940] warn about duplicate USE

2012-07-12 Thread Bil.Kleb at NASA dot gov
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53940

--- Comment #2 from Bil Kleb Bil.Kleb at NASA dot gov 2012-07-12 13:25:29 UTC 
---
I guess I see the USE ONLY as similar to a declaration, and to have two of the
same declarations in a program is an error, e.g.,

$ cat duplicate_declaration.f90  EOF
program duplicate_declaration
  integer :: var
  integer :: var ! should produce at least a warning?
  var = 1
  print*, var
end program
EOF

% gfortran duplicate_declaration.f90 
duplicate_declaration.f90:3.16:

  integer :: var ! should produce at least a warning?
1
Error: Symbol 'var' at (1) already has basic type of INTEGER

While the error is mostly harmless, we find it useful to know about to keep our
code clean.