This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gfortran bug? USE and USE ONLY


Apologies if what I suspect is a bug has been fixed in a gfortran or gcc later than mine; I have no control over when our systems are updated.

The following program with USE and USE ... ONLY statements for the same module is IMHO standard-conforming f95, but it prints different outputs
with different compilers. I think gfortran is wrong, for reasons in the comment lines at the end of the program itself.


harper@RHEL5 test system: ~ 20 >cat test2uses.f90
MODULE xmod
  REAL(kind(1d0)) :: x = -666
END MODULE xmod

PROGRAM test2uses
  USE xmod
  USE xmod, ONLY: xrenamed => x ! kind(1d0)
  x = 666                       ! kind(1.0): see below
  PRINT *,'kind(xrenamed)==kind(x)?',kind(xrenamed)==kind(x)
  PRINT *,'That should have printed',.FALSE.
END PROGRAM test2uses

!The f95 standard 11.3.2 says
!   More than one USE statement for a given module may appear in a
!   scoping unit. If one of the USE statements is without an ONLY
!   qualifier, all public entities in the module are accessible. ...
!
![The above paragraph says that X is accessible, but later text from
!the same section specifies under what name it's accessible.]
!
!   An accessible entity in the referenced module has one or more
!   local names.  These names are
!
!(1) The name of the entity in the referenced module if that name
!   appears as an only-use-name in any only for that module,
![X doesn't]
!
!(2) Each of the local-names the entity is given in any rename or
!    only-rename for that module,
![X is accessible through the name XRENAMED]
!
!and
!(3) The name of the entity in the referenced module if that name does
!    not appear as a use-name in any rename or only-rename for that
!    module.
![X appears as a use-name in the only-rename for the second USE
!statement, therefore X in module XMOD is inaccessible in the main
!program under the name X, so the X that = 666 there is default real]

harper@RHEL5 test system: ~ 22 >gfortran -v test2uses.f90
Driving: gfortran -v test2uses.f90 -lgfortranbegin -lgfortran -lm -shared-libgcc
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --with-cpu=generic --host=i386-redhat-linux
Thread model: posix
gcc version 4.1.1 20070105 (Red Hat 4.1.1-52)
/usr/libexec/gcc/i386-redhat-linux/4.1.1/f951 test2uses.f90 -quiet -dumpbase test2uses.f90 -mtune=generic -auxbase test2uses -version -I /usr/lib/gcc/i386-redhat-linux/4.1.1/finclude -o /tmp/ccXK9ztL.s
GNU F95 version 4.1.1 20070105 (Red Hat 4.1.1-52) (i386-redhat-linux)
compiled by GNU C version 4.1.1 20070105 (Red Hat 4.1.1-52).
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
as -V -Qy -o /tmp/ccufEP1o.o /tmp/ccXK9ztL.s
GNU assembler version 2.17.50.0.6-2.el5 (i386-redhat-linux) using BFD version 2.17.50.0.6-2.el5 20061020
/usr/libexec/gcc/i386-redhat-linux/4.1.1/collect2 --eh-frame-hdr -m elf_i386 --hash-style=gnu -dynamic-linker /lib/ld-linux.so.2 /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../crt1.o /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../crti.o /usr/lib/gcc/i386-redhat-linux/4.1.1/crtbegin.o -L/usr/lib/gcc/i386-redhat-linux/4.1.1 -L/usr/lib/gcc/i386-redhat-linux/4.1.1 -L/usr/lib/gcc/i386-redhat-linux/4.1.1/../../.. /tmp/ccufEP1o.o -lgfortranbegin -lgfortran -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/i386-redhat-linux/4.1.1/crtend.o /usr/lib/gcc/i386-redhat-linux/4.1.1/../../../crtn.o
harper@RHEL5 test system: ~ 23 >./a.out
kind(xrenamed)==kind(x)? T
That should have printed F
harper@RHEL5 test system: ~ 24 > -- John Harper, School of Mathematics, Statistics and Computer Science,
Victoria University, PO Box 600, Wellington 6140, New Zealand
e-mail john.harper@vuw.ac.nz phone (+64)(4)463 5341 fax (+64)(4)463 5045



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]