http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51514
Bug #: 51514
Summary: [OOP] Wrong code when passing a CLASS to a TYPE
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: fortran
AssignedTo: [email protected]
ReportedBy: [email protected]
The following program (subprog_poly_nonpoly_01_pos.f90) of Reinhold Bader's
test suite fails with at run time with:
==17368== Invalid read of size 4
==17368== at 0x400AB4: MAIN__ (subprog_poly_nonpoly_01_pos.f90:21)
==17368== by 0x400BCD: main (subprog_poly_nonpoly_01_pos.f90:16)
That's the line:
if (xx%i == 3) then
The problem is that one passes the CLASS and not the TYPE to the subroutine:
subpr (&xx);
if (xx._data->i == 3)
The first line should have been subpr(&xx._data)
It works with the Intel Compiler 12.1. (See also PR 46990.)
module mod_subpr
implicit none
type :: foo
integer :: i = 2
end type
type, extends(foo) :: foo_1
real :: r(2)
end type
contains
subroutine subpr(x)
type(foo) :: x
x%i = 3
end subroutine
end module
program prog
use mod_subpr
implicit none
class(foo), allocatable :: xx
allocate(foo_1 :: xx)
call subpr(xx)
if (xx%i == 3) then
write(*,*) 'OK'
else
write(*,*) 'FAIL'
end if
end program