This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/34704] New: Derived-type initialization ignored unless save attribute is present
- From: "p dot giannozzi at fisica dot uniud dot it" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 7 Jan 2008 15:19:40 -0000
- Subject: [Bug fortran/34704] New: Derived-type initialization ignored unless save attribute is present
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
It looks like a derived-type variable, containing an allocatable array and
a variable set to an initial value, picks some random number instead of the
initial value, unless it has the "save" attribute. The following piece of
code demonstrates the problem: the only difference between the first and the
second subroutine is the presence of the save attribute to t. No problem if
"t%a" is a fixed-dimension array. "t%n" should be 1023.
!
program boh
!
call mah0
call mah1
!
end program boh
!
subroutine mah0
!
type mix_type
real(8), allocatable :: a(:)
integer :: n=1023
end type mix_type
type(mix_type) :: t
!
allocate(t%a(1))
t%a=3.1415926
print *, 'n,a=',t%n,t%a
deallocate(t%a)
!
end subroutine mah0
!
subroutine mah1
!
type mix_type
real(8), allocatable :: a(:)
integer :: n=1023
end type mix_type
type(mix_type), save :: t
!
allocate(t%a(1))
t%a=3.1415926
print *, 'n,a=',t%n,t%a
deallocate(t%a)
!
end subroutine mah1
gfortran -v
Using built-in specs.
Target: i386-apple-darwin8.10.1
Configured with: /tmp/gfortran-20071231/ibin/../gcc/configure
--prefix=/usr/local/gfortran --enable-languages=c,fortran
--with-gmp=/tmp/gfortran-20071231/gfortran_libs --enable-bootstrap
Thread model: posix
gcc version 4.3.0 20071231 (experimental) [trunk revision 131236] (GCC)
$ gfortran boh.f90
$ ./a.out
n,a= 2123354 3.1415925025939941
n,a= 1023 3.1415925025939941
$ gfortran -O3 boh.f90
$ ./a.out
n,a= -1 3.1415925025939941
n,a= 1023 3.1415925025939941
--
Summary: Derived-type initialization ignored unless save
attribute is present
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: p dot giannozzi at fisica dot uniud dot it
GCC build triplet: i386-apple-darwin8.10.1
GCC host triplet: i386-apple-darwin8.10.1
GCC target triplet: i386-apple-darwin8.10.1
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34704