Bug 30135

Summary: [Regression 4.3] Error without comp. initialization: Module variable with a comp. initialization must have SAVE
Product: gcc Reporter: Tobias Burnus <burnus>
Component: fortranAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED WORKSFORME    
Severity: normal CC: gcc-bugs
Priority: P3 Keywords: diagnostic, rejects-valid
Version: 4.3.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:

Description Tobias Burnus 2006-12-10 09:14:40 UTC
The following code does not contain a component initialization, nonetheless, gfortran emits the following error:

  type(myT) :: t
               1
Error: Module variable 't' at (1) with a default initialization must have the SAVE attribute

This constrain is checked in result.c, excerpt from that file:

  /* 4th constraint in section 11.3:  "If an object of a type for which
     component-initialization is specified (R429) appears in the
     specification-part of a module and does not have the ALLOCATABLE
     or POINTER attribute, the object shall have the SAVE attribute."  */


module good2
  implicit none
  type myT
     integer :: j  ! = 5.5
     integer, pointer :: p ! => null()
  end type myT
  type(myT) :: t
end module good2

program main
  use good2
  implicit none
  t%j = 15
  nullify(t%p)
end program main

(Interestingly, only g95 (and gfortran) give an error if one uses component initialization, NAG f95, sunf95 and ifort don't.)
Comment 1 Tobias Burnus 2006-12-10 12:34:43 UTC
Bootstapped & re-tested => Works now.