Shape intrinsic does not allow scalar arguments as required by f90/f95/f03 standards. Example code follows: program test_shape ! Segmentation fault generated when executable executed integer :: i print *, shape( i ) ! Shape of a scalar allowed by f90, f95, f03 ! standards. end program test_shape Kind intrinsic with character argument in type declaration fails: Example follows: ! Compiler version: ! GNU Fortran (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu3) ! Copyright (C) 2007 Free Software Foundation, Inc. character (len = 3, kind = kind("a" ) c ! Compiler fails with internal error -- invalid syntax ! character (len = 3, kind = kind("a") ) c ! Fails compilation -- invalid kind ! value returned -- that is, minus ! integer huge. Notice the ! kind("a") is correctly returned ! as 1 in print statement below and ! kind=1 works in a character ! declaration. ! character (len = 3, kind = 1) c ! Works c = "b" print *, kind("a"), c end program
Code works with 4.3.2 and trunk. Note you probably want to 1) Update to a 4.3.2 or newer compiler. 2) Change the example to program test_shape integer :: i print *, size(shape(i)) ! Shape of a scalar allowed by f95 standards. end program test_shape because shape(i) is a zero sized array.
Subject: Re: Fortran shape and kind intrinsic Thanks for the response. I will download the latest compiler, which I thought I had. I guess the autoupdate for my Mint Linux is not working promptly or this has been updated in the last two weeks. With the new version, I will check the second problem I reported as well and report back (kind intrinsic with character argument in a type declararation statement). Thanks again and appreciate you help -- you have saved me of creating a workaround for the GNU compilers for my large application code for the shape intrinsic -- the code I gave is the simplest extraction I could think of but your recommendation for this test is clearly better. ----- Original Message ----- From: "kargl at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> To: <carbess@swcp.com> Sent: Sunday, November 02, 2008 5:00 PM Subject: [Bug fortran/37999] Fortran shape and kind intrinsic > > > ------- Comment #1 from kargl at gcc dot gnu dot org 2008-11-03 > 00:00 ------- > Code works with 4.3.2 and trunk. > > Note you probably want to > > 1) Update to a 4.3.2 or newer compiler. > 2) Change the example to > > program test_shape > integer :: i > print *, size(shape(i)) ! Shape of a scalar allowed by f95 standards. > end program test_shape > > because shape(i) is a zero sized array. > > > -- > > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37999 > > ------- You are receiving this mail because: ------- > You reported the bug, or are watching the reporter. >
(In reply to comment #2) > With the new version, I will check the second problem I reported > as well and report back (kind intrinsic with character argument > in a type declararation statement) The 2nd problem is also fixed in 4.3.2 and newer gfortran. character (len = 3, kind = kind("a" ) c c = "b" print *, kind("a"), c end program troutmask:kargl[203] ~/../sgk/work/4x/bin/gfortran -static -o z t.f90 t.f90:1.42: character (len = 3, kind = kind("a" ) c 1 Error: Syntax error in CHARACTER declaration at (1) t.f90:2.7: c = "b" 1 Error: Can't convert CHARACTER(1) to REAL(4) at (1) The second error is a side effect of the first error.
"print *, shape( i )" That program works here with GCC 4.1.3, 4.2.1 and 4.3.3-20081002 of openSUSE, and with 4.3.3-20081103 and 4.4.0 of today. I not even get any valgrind error. Character tests: I can reproduce the ICE with 4.2, it works with 4.3/4.4. > I will download the latest compiler, which I thought I had. > I guess the autoupdate for my Mint Linux is not working > promptly or this has been updated in the last two weeks. Note: Distributions are slow at updating the compiler as it is the core part and can cause a lot of problem. 4.3.0 was released 2008-03-05 and 4.3.x is said to be a very well working version from the C/middle-end part. Also the Fortran part is in a pretty good shape. 4.4.0 is not yet released but exists as developer version, which is daily updated but can only get regression fixes. Nightly Linux builds are available from: http://gcc.gnu.org/wiki/GFortranBinaries
Closing, not a bug any more.