http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45828
Summary: No default initialization of derived type members? Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran AssignedTo: unassig...@gcc.gnu.org ReportedBy: j...@csc.fi Hi, program fail type a integer :: i end type a type b type(a), pointer :: a => null() end type b type(b), pointer :: c(:) print*,0.0 allocate(c(201)) do i=1,201 if ( associated(c(i) % a)) call abort() end do end program fail the attached program misbehaves using gfortran 4.6 (i think). The supposed output is: 0.0000000 using gfortran 4.6 i get 0.0000000 5 T 6 T 10 T Note that the output depends on trashing the stack (which is why the first print is there), and may depend on your setup. The trouble seems to be that no derived type default initialization code is generated after the ALLOCATE() by 4.6 as opposed to f.ex. 4.1.2, 4.3.2 & 4.4.3. At least this is my reading of the "fail.f90.003t.original" file. Also, this file is identical even if you remove the default initialization from the structure member. The program below also fails: program fail1 type a integer :: i end type a type b type(a) :: acomp = a(5) end type b type(b), allocatable :: c(:) allocate(c(1)) if (c(1) % acomp % i /= 5) call abort() end program fail1 Sorry, if i'm missing something... Regards, Juha gfortran -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/home/wrk/jpr/gcc-4.6/bin/../libexec/gcc/i686-pc-linux-gnu/4.6.0/lto-wrapper Target: i686-pc-linux-gnu Configured with: ../gcc/configure --enable-languages=c,c++,fortran --disable-bootstrap --prefix=/wrk/jpr/gcc-4.6 --with-gmp=/wrk/jpr/extralib --with-mpfr=/wrk/jpr/extralib Thread model: posix gcc version 4.6.0 20100928 (experimental) (GCC)