gfortran from the current trunk gives a warning for the code below: module fitsmod2 implicit none
contains function char2type (char) character, intent(in) :: char integer :: char2type select case (char) case ('E','e') char2type=1 case default char2type=-1234 end select end function function fixkey (input) character(len=*), intent(in) :: input character(len=1024) fixkey fixkey=input end function end module fitsmod2 /scratch/blah5/planck/LevelS/bugrep>gfortran -v -Wuninitialized -c -O fitsmod2.f90 Using built-in specs. Target: i686-pc-linux-gnu Configured with: /scratch/martin/gcc/configure --prefix=/afs/mpa/data/martin/ugcc --with-mpfr-include=/usr/include --with-mpfr-lib=/usr/lib --with-gmp-include=/usr/include --with-gmp-lib=/usr/lib --enable-languages=c++,fortran --enable-checking=release Thread model: posix gcc version 4.5.0 20090520 (experimental) [trunk revision 147731] (GCC) COLLECT_GCC_OPTIONS='-v' '-Wuninitialized' '-c' '-O' '-mtune=generic' /afs/mpa/data/martin/ugcc/libexec/gcc/i686-pc-linux-gnu/4.5.0/f951 fitsmod2.f90 -quiet -dumpbase fitsmod2.f90 -mtune=generic -auxbase fitsmod2 -O -Wuninitialized -version -fintrinsic-modules-path /afs/mpa/data/martin/ugcc/lib/gcc/i686-pc-linux-gnu/4.5.0/finclude -o /tmp/ccPgtd3C.s GNU Fortran (GCC) version 4.5.0 20090520 (experimental) [trunk revision 147731] (i686-pc-linux-gnu) compiled by GNU C version 4.5.0 20090520 (experimental) [trunk revision 147731], GMP version 4.2.1, MPFR version 2.3.2 warning: GMP header version 4.2.1 differs from library version 4.2.4. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 GNU Fortran (GCC) version 4.5.0 20090520 (experimental) [trunk revision 147731] (i686-pc-linux-gnu) compiled by GNU C version 4.5.0 20090520 (experimental) [trunk revision 147731], GMP version 4.2.1, MPFR version 2.3.2 warning: GMP header version 4.2.1 differs from library version 4.2.4. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 fitsmod2.f90: In function 'char2type': fitsmod2.f90:23: warning: '__result_char2type' may be used uninitialized in this function fitsmod2.f90:23: note: '__result_char2type' was declared here COLLECT_GCC_OPTIONS='-v' '-Wuninitialized' '-c' '-O' '-mtune=generic' as -V -Qy -o fitsmod2.o /tmp/ccPgtd3C.s GNU assembler version 2.18 (i686-pc-linux-gnu) using BFD version (GNU Binutils) 2.18 COMPILER_PATH=/afs/mpa/data/martin/ugcc/libexec/gcc/i686-pc-linux-gnu/4.5.0/:/afs/mpa/data/martin/ugcc/libexec/gcc/i686-pc-linux-gnu/4.5.0/:/afs/mpa/data/martin/ugcc/libexec/gcc/i686-pc-linux-gnu/:/afs/mpa/data/martin/ugcc/lib/gcc/i686-pc-linux-gnu/4.5.0/:/afs/mpa/data/martin/ugcc/lib/gcc/i686-pc-linux-gnu/:/usr/libexec/gcc/i686-pc-linux-gnu/:/usr/lib/gcc/i686-pc-linux-gnu/ LIBRARY_PATH=/afs/mpa/data/martin/ugcc/lib/gcc/i686-pc-linux-gnu/4.5.0/:/afs/mpa/data/martin/ugcc/lib/gcc/i686-pc-linux-gnu/4.5.0/../../../:/lib/:/usr/lib/ COLLECT_GCC_OPTIONS='-v' '-Wuninitialized' '-c' '-O' '-mtune=generic' Several things are odd about this warning: - the line number in question is not inside the function "char2type" - the warning is given for a variable that is not defined by the user - the result of "char2type" is actually initialised in all code paths -- Summary: [gfortran] Incorrect warning with -Wuninitialized Product: gcc Version: 4.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: martin at mpa-garching dot mpg dot de GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40206