From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26403 invoked by alias); 28 May 2011 18:05:15 -0000 Received: (qmail 26392 invoked by uid 22791); 28 May 2011 18:05:14 -0000 X-SWARE-Spam-Status: No, hits=-2.7 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 28 May 2011 18:05:01 +0000 From: "neil.n.carlson at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/49213] New: [OOP] gfortran rejects structure constructor expression X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Keywords: X-Bugzilla-Severity: major X-Bugzilla-Who: neil.n.carlson at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Sat, 28 May 2011 18:15:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-05/txt/msg02859.txt.bz2 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: unassigned@gcc.gnu.org ReportedBy: neil.n.carlson@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