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