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

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

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.

15 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione
Ritratto di Lorri Menard (Intel)

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

Ritratto di mecej4

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

 

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

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

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...

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

Ritratto di Steve Lionel (Intel)

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

Steve

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.

Ritratto di app4619

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...."

Citazione:

app4619 ha scritto:

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?

Ritratto di app4619

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

Ritratto di Steve Lionel (Intel)

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.

Steve

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]

Ritratto di app4619

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

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

Allegati: 

AllegatoDimensione
Download debug.log8.12 KB
Ritratto di Steve Lionel (Intel)

Please attach the source file you used.

Steve

Accedere per lasciare un commento.