[Bug fortran/34438] New: gfortran not compliant w.r.t default initialization of derived type component and implicit SAVE attribute

sven dot buijssen at math dot uni-dortmund dot de gcc-bugzilla@gcc.gnu.org
Tue Dec 11 23:14:00 GMT 2007


gfortran 4.1.x, 4.2.x and 4.3.x are not compliant with the standard, section
4.4

'Unlike explicit initialization, default initialization does not imply that
the object has the SAVE attribute'

for the following testcase:


--- cut here ---
program main
  type myint
    integer :: bar = 0
  end type myint

  call recfunc(1)

contains

  recursive subroutine recfunc(ivalue)
    integer, intent(in) :: ivalue
    type(myint) :: foo

    foo%bar = ivalue
    if (ivalue .le. 3) then
      print *, "recursion level", ivalue, "value of local variable:", foo%bar
      call recfunc(ivalue + 1)
      print *, "recursion level", ivalue, "value of local variable:", foo%bar
    endif

  end subroutine recfunc

end program main
--- cut here ---

The default initialization of the component "bar" leads to "type(myint) ::
foo" having the SAVE attribute when compiled with gfortran. But "foo" should
only get the SAVE attribute if it were explicitly initialized. (The constraint
in 11.3 does not hold here)

$ gfortran -Wall demo.f90  && ./a.out
 recursion level           1 value of local variable:           1
 recursion level           2 value of local variable:           2
 recursion level           3 value of local variable:           3
 recursion level           3 value of local variable:           4
 recursion level           2 value of local variable:           4
 recursion level           1 value of local variable:           4

Recent version of PGI, Pathscale, Intel, SunStudio and G95 yield instead:
 recursion level 1 value of local variable: 1
 recursion level 2 value of local variable: 2
 recursion level 3 value of local variable: 3
 recursion level 3 value of local variable: 3
 recursion level 2 value of local variable: 2
 recursion level 1 value of local variable: 1

gfortran behaves like the other compilers when the default initialization of
component "bar" in the type definition is removed:

  [...]
  type myint
    integer :: bar
  end type myint
  [...]


Conversely, the compilers mentioned behave like gfortran if the variable "foo"
explicitly gets the SAVE attribute:

    [...]
    type(myint), save :: foo
    [...]


For sake of completeness:
$ gfortran -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.1.x/configure --enable-shared
--enable-languages=c,c++,fortran --enable-threads --enable-__cxa_atexit
Thread model: posix
gcc version 4.1.3 20071211 (prerelease)

$ gfortran -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.2.x/configure --enable-shared
--enable-languages=c,c++,fortran --enable-threads --enable-__cxa_atexit
Thread model: posix
gcc version 4.2.3 20071211 (prerelease)

$ gfortran -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc-4.3.x/configure --enable-shared
--enable-languages=c,c++,fortran --enable-threads --enable-__cxa_atexit
Thread model: posix
gcc version 4.3.0 20071211 (experimental) (GCC)


-- 
           Summary: gfortran not compliant w.r.t default initialization of
                    derived type component and implicit SAVE attribute
           Product: gcc
           Version: 4.2.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sven dot buijssen at math dot uni-dortmund 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=34438



More information about the Gcc-bugs mailing list