public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/49213] New: [OOP] gfortran rejects structure constructor expression
@ 2011-05-28 18:15 neil.n.carlson at gmail dot com
  2011-06-16 19:44 ` [Bug fortran/49213] [OOP][F2008] " janus at gcc dot gnu.org
                   ` (31 more replies)
  0 siblings, 32 replies; 33+ messages in thread
From: neil.n.carlson at gmail dot com @ 2011-05-28 18:15 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2023-10-31  8:29 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-28 18:15 [Bug fortran/49213] New: [OOP] gfortran rejects structure constructor expression neil.n.carlson at gmail dot com
2011-06-16 19:44 ` [Bug fortran/49213] [OOP][F2008] " janus at gcc dot gnu.org
2011-06-16 19:50 ` [Bug fortran/49213] [OOP] " janus at gcc dot gnu.org
2011-06-16 20:36 ` neil.n.carlson at gmail dot com
2011-06-16 20:50 ` neil.n.carlson at gmail dot com
2011-06-16 21:29 ` janus at gcc dot gnu.org
2011-06-16 22:14 ` neil.n.carlson at gmail dot com
2011-06-16 22:18 ` neil.n.carlson at gmail dot com
2013-01-10 15:46 ` janus at gcc dot gnu.org
2013-01-10 16:07 ` janus at gcc dot gnu.org
2013-01-10 20:40 ` janus at gcc dot gnu.org
2013-01-11 12:04 ` janus at gcc dot gnu.org
2013-08-05  9:08 ` janus at gcc dot gnu.org
2013-08-05  9:22 ` janus at gcc dot gnu.org
2013-08-05 11:14 ` janus at gcc dot gnu.org
2013-08-06  8:42 ` janus at gcc dot gnu.org
2013-08-06  9:13 ` janus at gcc dot gnu.org
2013-08-06 10:50 ` janus at gcc dot gnu.org
2013-08-08 16:54 ` dominiq at lps dot ens.fr
2013-08-11 17:03 ` dominiq at lps dot ens.fr
2015-01-24 11:52 ` dominiq at lps dot ens.fr
2015-01-24 16:32 ` dominiq at lps dot ens.fr
2015-01-24 19:05 ` janus at gcc dot gnu.org
2015-02-05  8:09 ` pault at gcc dot gnu.org
2020-03-12 11:58 ` jakub at gcc dot gnu.org
2021-04-16 20:03 ` vladimir.fuka at gmail dot com
2021-06-01  8:05 ` rguenth at gcc dot gnu.org
2022-05-27  9:12 ` rguenth at gcc dot gnu.org
2023-06-22 16:45 ` pault at gcc dot gnu.org
2023-06-28 11:39 ` cvs-commit at gcc dot gnu.org
2023-10-31  8:23 ` pault at gcc dot gnu.org
2023-10-31  8:24 ` pault at gcc dot gnu.org
2023-10-31  8:29 ` pault at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).