This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC 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]

Re: Two gfortran bugs


After sending the email below, I found that an older gfortran version,
4.4.6 20110731 (Red Hat 4.4.6-3) (GCC) does not have my bug 1 but does have bug 2. Version 4.6.2 20120120 (prerelease) (GCC) has both bugs,
like version 4.8.0 20120701 (experimental) (GCC) mentioned below.
I showed this by compiling and running the same program with std=f95
three times.


On Thu, 5 Jul 2012, John Harper wrote:

Date: Thu, 5 Jul 2012 11:38:39 +1200 (NZST)
From: John Harper <John.Harper@msor.vuw.ac.nz>
To: gcc@gcc.gnu.org
Subject: Two gfortran bugs

My program testpublic5.f90 (see below) when compiled with -std=f95
using gfortran version 4.8.0 20120701 (experimental) (GCC)
reveals two compiler bugs, giving an unjustified warning and failing
to mention that the program violates an f95 constraint. It compiles
and runs with -std=f95 the same way as with -std=f2003

1. Gfortran warns that the declaration character name*63 is obsolescent, but it is not. Character*63 name would be obsolescent, of course. (You will notice that the program contains several declarations of that
nature, but only the one in the declaration of a derived type triggers
the warning.)


2. The f95 constraint is that a function returning a private type must
not have a public generic identifier. That constraint is not in f2003.

ayley[~/Jfh] % cat testpublic5.f90
! Bad f95 (forbidden by 3rd constraint after R523 that functions of
! private type [e.g. namekindlen] can't have public generic identifiers
! [e.g. attributes].) The constraint does not apply to the private
! function chstring with the public generic identifier string because
! neither its argument nor its function value is of private type.
! Good f2003/2008.
!
module whattype
 private
 public properties,attributes
 interface attributes
    module procedure namekindlen
 end interface attributes
 interface properties
    module procedure charprops
 end interface properties
 type charints
    character name*63 ! Max length of a name in f2003
    integer   sort
    integer   leng
 end type charints
contains
 pure function    namekindlen(string)
   type(charints) namekindlen
   character(*),intent(in)::  string
   namekindlen = charints(string,kind(string),len(string))
 end function namekindlen

 pure integer function ilen(i) ! Minimum space to write integer i
   integer,intent(in)::     i
   character str*(range(i)+3)
   write(str,"(I0,A)") i,'?'
   ilen = index(str,'?')-1
 end function ilen

 pure function charprops(s) result(                answer)
   character,intent(in)::s*(*)
   character(len(s)+ilen(kind(s))+ilen(len(s))+32) answer
   type(charints) nkl
   nkl = attributes(s)
   write(answer,"(2(A,I0))") '"'//nkl%name(1:len(s))//'"'// &
        ' is type character, kind ',nkl%sort,' len ',nkl%leng
 end function charprops
end module whattype

program testpublic
use whattype
character,parameter:: stuff*(*) = 'foobar '
print "(A)",properties(stuff)
end program testpublic
cayley[~/Jfh] %
cayley[~/Jfh] % alias gf
/local/scratch/gf/bin/gfortran
cayley[~/Jfh] % gf -v
Using built-in specs.
COLLECT_GCC=/local/scratch/gf/bin/gfortran
COLLECT_LTO_WRAPPER=/local/scratch/gf/libexec/gcc/i686-pc-linux-gnu/4.8.0/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: /local/scratch/gcc-4.8-20120701/configure --prefix=/local/scratch/gf --enable-languages=c,fortran --disable-libada --with-local-prefix=/local/scratch --with-gmp=/local/scratch
Thread model: posix
gcc version 4.8.0 20120701 (experimental) (GCC)
cayley[~/Jfh] %
cayley[~/Jfh] % gf -std=f95 testpublic5.f90
testpublic5.f90:18.22:


    character name*63 ! Max length of a name in f2003
                     1
Warning: Obsolescent feature: Old-style character length at (1)
cayley[~/Jfh] % ./a.out
"foobar  " is type character, kind 1 len 8
cayley[~/Jfh] %

-- John Harper, School of Mathematics Statistics and Operations Research
Victoria University, PO Box 600, Wellington 6140, New Zealand
e-mail john.harper@vuw.ac.nz phone (+64)(4)463 5276 fax (+64)(4)463 5045



-- John Harper, School of Mathematics Statistics and Operations Research
Victoria University, PO Box 600, Wellington 6140, New Zealand
e-mail john.harper@vuw.ac.nz phone (+64)(4)463 5276 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]