public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "bourdin at mcmaster dot ca" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/105807] New: ICE / error when defining a class containing polymorphic components
Date: Wed, 01 Jun 2022 18:45:44 +0000	[thread overview]
Message-ID: <bug-105807-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105807

            Bug ID: 105807
           Summary: ICE / error when defining a class containing
                    polymorphic components
           Product: gcc
           Version: 11.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bourdin at mcmaster dot ca
  Target Milestone: ---

defining a class whose components are polymorphic variables fails:

Consider the following (legal) source code:
module Vect_class
    type, abstract :: Vect_Type
    end type
end module Vect_class

module Elem_class
    use Vect_class
    type, abstract :: Elem_Type
        integer                      :: numDof
        class(Vect_type),allocatable :: v
    end type
end module Elem_class

module Vect
    use Vect_class

    type, extends(Vect_Type) :: Vect2D 
       real :: X,Y
    end type Vect2D   

    type, extends(Vect_Type) :: Vect3D 
       real :: X,Y,Z
    end type Vect3D   
end module Vect

module Elem
    use Elem_class

    type, extends(Elem_type)  :: elem2D
    end type
end module Elem

program testElem
    use Vect_class
    use Vect
    use Elem_class
    use Elem

    type(Vect2D) :: a
    type(Vect3D) :: b
    class(Vect_type),allocatable :: c,d
    class(Elem_type),allocatable :: e
    real       :: x,y,z

    x = 1.0
    y =-2.0
    z = 3.0

    a = Vect2D(x,y)
    b = Vect3D(x,y,z)
    c = Vect2D(x,y)
    d = Vect3D(x,y,z)
    e = Elem2D(10,b)
    write(*,*) e%numDof
end program testElem

It fails to compile with error message with GNU Fortran (GCC) 11.2.1 20210728
(Red Hat 11.2.1-1) (RHEL7 devtoolset 11)

   53 |     e = Elem2D(10,b)
      |                  1
Error: Cannot convert TYPE(vect3d) to CLASS(__class_vect_class_Vect_type_a) at
(1)

Under macOS (monterey, M1 processor) GNU Fortran (Homebrew GCC 11.3.0_1)
11.3.0, I get an ICE:

TestNestedClass3.f90:53:20:

   53 |     e = Elem2D(10,b)
      |                    1
internal compiler error: in fold_convert_loc, at fold-const.c:2563

             reply	other threads:[~2022-06-01 18:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-01 18:45 bourdin at mcmaster dot ca [this message]
2022-06-16 12:53 ` [Bug fortran/105807] " marxin at gcc dot gnu.org
2022-06-21 18:48 ` gscfq@t-online.de
2022-06-23 15:38 ` gscfq@t-online.de
2023-01-25  3:42 ` abensonca at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-105807-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).