http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47180
Summary: [OOP] EXTENDS_TYPE_OF returns the wrong result if the
polymorphic variable is unallocated
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: bur...@gcc.gnu.org
CC: ja...@gcc.gnu.org
Found when looking at PR 41580.
The following program should print 6 times "T" but it prints trice "F" followed
by trice "T".
>From Fortran 2008:
"13.7.60 EXTENDS_TYPE_OF (A, MOLD)"
"Result Value. [unlimited polymorphic] ; otherwise if the dynamic type of A or
MOLD is extensible, the result is true if and only if the dynamic type of A is
an extension type of the dynamic type of MOLD; otherwise the result is
processor dependent."
"NOTE 13.12 The dynamic type of a disassociated pointer or unallocated
allocatable variable is its declared type."
(NAG 5.1 ICEs and ifort prints the same result as gfortran; nevertheless, I
expect that the code is correct, which is in line with NOTE 13.12.)
implicit none
type t1
integer :: a
end type t1
type, extends(t1):: t11
integer :: b
end type t11
type(t1) a1
type(t11) a11
class(t1), allocatable :: b1
class(t11), allocatable :: b11
print *, extends_type_of(b1,a1) ! T - currently, gfortran prints "F"
print *, extends_type_of(b11,a1) ! T - currently, gfortran prints "F"
print *, extends_type_of(b11,a11) ! T - currently, gfortran prints "F"
allocate(t1 :: b1)
allocate(t11 :: b11)
print *, extends_type_of(b1,a1) ! T
print *, extends_type_of(b11,a1) ! T
print *, extends_type_of(b11,a11) ! T
end