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

Renaming of module variables to existing variable name does *not* produce an error

Espen_M_
Beginner
2,681 Views

I accedentally renamed a module variable (a parameter actually) to a name that also existed in the same module; I guess this should have produced an error, but it didn't.

0 Kudos
14 Replies
Lorri_M_Intel
Employee
2,681 Views

If I understand your program correctly, it was something like this:

module foo
integer, parameter :: limit=25
integer :: outer_limit = 10
end module foo
program main
use foo, only: limit => outer_limit
print *, limit   !! prints 10
end

Interestingly enough, this is legal.  There is a lot of leeway in renaming variables from modules, including reusing names that exist in the module.

                   --Lorri

0 Kudos
mecej4
Honored Contributor III
2,681 Views

I did not infer from the original description that the USE statement should contain a "only:" clause. Removing that from Lorri's test program and compiling with the 14.0.0.103 compiler gives the helpful message

 [fortran]only.f90(6): error #7837: Two or more accessible entities, other than generic interfaces,
may have the same name only if the name is not used to refer to an entity in the scoping unit. [LIMIT]
use foo, limit => outer_limit

[/fortran]

A specific code example from the OP would be helpful; in particular, the use of the PARAMETER attribute needs to be clarified.

0 Kudos
Espen_M_
Beginner
2,681 Views

Your example has an ONLY clause which makes it work, I didn't have that.

Do you mean that this is legal according to the sandard, or according to the compiler? It seems strange if it was allowed in the standard as it produces ambiguities unless the renaming happens after an ONLY clause...

0 Kudos
Espen_M_
Beginner
2,681 Views

mecej4:

Lorri's example is essentially similar to mine, except for her ONLY clause.

I did not get that error message. I'm using the XE 2013 compiler without SP1

0 Kudos
Steven_L_Intel1
Employee
2,681 Views

Please show us an example that gets the error. Feel free to modify Lorri's example to match yours.

0 Kudos
Espen_M_
Beginner
2,681 Views

module foo
integer, parameter :: limit=25
integer :: outer_limit = 10
end module foo
program main
use foo, limit => outer_limit    !no 'only:'
print *, limit   !! prints 25
end

This program induces the assumed bug (i.e. that no error is reported) for me.

0 Kudos
andrew_4619
Honored Contributor III
2,681 Views

The above sample gives "error #7837: Two or more accessible entities, other than generic interfaces, may have the same name only if the name is not used to refer to an entity in the scoping unit. [LIMIT] compilation aborted for C:\Users\An...."

0 Kudos
Espen_M_
Beginner
2,681 Views

app4619 wrote:

The above sample gives "error #7837: Two or more accessible entities, other than generic interfaces, may have the same name only if the name is not used to refer to an entity in the scoping unit. [LIMIT] compilation aborted for C:\Users\An...."

Strange, but I don't get that message... Could it be because I don't have the latest SP?

0 Kudos
andrew_4619
Honored Contributor III
2,681 Views

Dunno, I used "Compiling with Intel(R) Visual Fortran Compiler XE 13.1.3.198 [IA-32]"  what level are you using?

0 Kudos
Steven_L_Intel1
Employee
2,681 Views

I went back as far as 12.1 and still saw the error. Please show us a full build log (command line best, but buildlog.htm from VS would do) showing what you saw.

0 Kudos
Espen_M_
Beginner
2,681 Views

I guess there isn't much to see in the build log as nothing in particular is reported. The only problem is that the result, i.e. when printing the value is wrong. The version is 13.0.1.119 [IA-32]

0 Kudos
andrew_4619
Honored Contributor III
2,681 Views

The buildlog will among other things shown which options were used to allow someone else to try the replicate the problem.

0 Kudos
Espen_M_
Beginner
2,681 Views

Here is the BuildLog.htm from a build in debug config. (had to rename it to upload)

0 Kudos
Steven_L_Intel1
Employee
2,681 Views

Please attach the source file you used.

0 Kudos
Reply