http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49213
Summary: [OOP] gfortran rejects structure constructor expression Product: gcc Version: 4.7.0 Status: UNCONFIRMED Severity: major Priority: P3 Component: fortran AssignedTo: unassig...@gcc.gnu.org ReportedBy: neil.n.carl...@gmail.com In the following program type-compatible variables are used as an expression in a structure constructor for an allocatable CLASS(S) component. In the first case a TYPE(S) variable is used, and in the second a TYPE(S2), where S2 extends S. The program compiles with nagfor 5.2 and (reportedly) with the cray compiler, but gfortran rejects the code with the error messages: Tobj = T(Sobj) 1 Error: Can't convert TYPE(s) to CLASS(s) at (1) Tobj = T(S2obj) 1 Error: Can't convert TYPE(s2) to CLASS(s) at (1) =============== >From the F2008 standard: "For a nonpointer component, the declared type and type parameters of the component and expr shall conform in the same way as for a variable and expr in an intrinsic assignment statement (7.2.1.2) [...]" (4.5.10p2) "if the variable is polymorphic it shall be type compatible with expr; [...]" (7.2.1.2p1(4)) Also 4.5.10 p6 applies to allocatable components. =============== program main type :: S integer :: n end type type(S) :: Sobj type, extends(S) :: S2 integer :: m end type type(S2) :: S2obj type :: T class(S), allocatable :: x end type type(T) :: Tobj Sobj = S(1) Tobj = T(Sobj) S2obj = S2(1,2) Tobj = T(S2obj) end program