Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28477 Discussions

Feature request: warn about duplicate USE

w_l_kleb
Beginner
689 Views
Hi,

I'd like to see the Intel compiler at least give a warning if a USE is duplicated, viz,

% cat > duplicate_use.f90 << EOF
module mod
integer :: var = 0
end module

program duplicate_use
use mod, only: var
use mod, only: var ! should produce error
print*, var
end program
EOF

% ifort --version | head -1
ifort (IFORT) 12.1.3 20120212

% ifort -c -warn -check duplicate_use.f90
[no complaints]

It's antecedent does:

alpha% fort -what
Compaq Fortran V1.2.0-1882
Compaq Fortran Compiler V1.2.0-1882-48BBF

alpha% fort -c duplicate_use.f90
f90: Warning: duplicate_use.f90, line 6: Conflicting attributes or multiple declaration of name. [VAR]
use mod, only: var
-----------------^
f90: Error: duplicate_use.f90, line 8: The same named entity from different modules and/or program units cannot be referenced. [VAR]
print*, var
----------^

Thanks for consideration,
--
Bil, 757.812.1805
0 Kudos
10 Replies
w_l_kleb
Beginner
689 Views
More by way of http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53940 feedback...

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 % ifort -warn -check duplicate_declaration.f90
duplicate_declaration.f90(3): error #6418: This name has already been assigned a data type. [VAR]
integer :: var ! should produce at least a warning?
-------------^
compilation aborted for duplicate_declaration.f90 (code 1) While the USE ONLY error is mostly harmless, we find it useful to know about to keep our code clean.
0 Kudos
Steven_L_Intel1
Employee
689 Views
You may see it as similar to a declaration, but the standard does not.

"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 of the USE statements have ONLY options, only those entities in one or more of the only-lists are accessible."

F2008, section 11.2.2, paragraph 6

The multiple USEs are legal and no warning or error should be produced.
0 Kudos
w_l_kleb
Beginner
689 Views
Multiple USEs are legal, but multiple USE-ONLYs of the same variable would not seem to be a reasonable?
0 Kudos
Steven_L_Intel1
Employee
689 Views
The standard explicitly says it's ok (see the last sentence of the quote). I see no basis for issuing a warning here.
0 Kudos
w_l_kleb
Beginner
689 Views
I think my original example conflates to things.

Would you agree that it would be helpful to receive a warning for the following?

use module_a, only : var, var

I.e., repeated instantiation of "var".
0 Kudos
Steven_L_Intel1
Employee
689 Views
To be honest, not really. It's conceptually no different than having it on two different USE statements and does no harm. There's nothing in the standard that would support giving a warning here.
0 Kudos
w_l_kleb
Beginner
689 Views
Likewise, I don't read the standard to say you couldn't provide a warning?

FWIW, it looks like gfortran will eventually: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53940
and so we'll probably use that for our compiler diagnostic builds.
0 Kudos
Steven_L_Intel1
Employee
689 Views
I don't draw the same conclusion you do from Tobias' comments. If you want a compiler for diagnostic builds, try NAG. We're happy to add warnings for things that may be harmful even if legal - we have a class of "usage" diagnostics - but this to me does not rise to that level.

Think about the circumstances where such a "mistake" might appear. Let's say that the programmer has some (unfortunately named) variables C1,C2,C3 in a module. He then writes:

USE MODNAME, ONLY: C1,C1,C3

where C2 was meant for the second symbol. So what happens? If C2 is referenced in the body of the program unit, it will probably trigger an error for an undeclared symbol (assuming IMPLICIT NONE). If it isn't used, so what?
0 Kudos
w_l_kleb
Beginner
689 Views
For whatever reason, our developers like the DEC's warnings about duplicate USE'd variables; and I don't see the downside of a usage warning about C1 being included twice. Again, it seems very parallel (an illegal) duplicate declaration sitatuation.
0 Kudos
Steven_L_Intel1
Employee
689 Views
The previous diagnostic was considered a bug that we fixed - especially with separate USE. Again, while it may seem parallel to a duplicate declaration, it isn't.
0 Kudos
Reply