https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81093
Bug ID: 81093
Summary: Accessing ranges of values in derived types leads to
wrong result
Product: gcc
Version: 6.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: thomas.jourdan at orange dot fr
Target Milestone: ---
Hello,
The following code leads to a correct or a wrong result, depending on whether
the select type construct is used or not. If it is not used, I get:
1 -1 1 -1
2 -2 2 -2
whereas if it is used, the result is
1 1 1 1
2 2 2 2
I am not quite sure that the program is standard conforming and that it is a
bug, since there is perhaps no reason for Gfortran to know how to retrieve data
if the complete data structure (data_type2) is not known.
Regards,
Thomas
-----------
program test
implicit none
type data_type1
integer, dimension(2) :: data1
end type data_type1
type, extends(data_type1) :: data_type2
integer, dimension(2) :: data2
end type data_type2
type data_gen
class(data_type1), dimension(:), allocatable :: mydata
end type data_gen
type(data_gen) :: gen_data
integer :: ii
integer, parameter :: nn = 4
allocate(data_type2::gen_data%mydata(nn))
select type(data => gen_data%mydata)
type is (data_type2)
do ii = 1, nn
data(ii)%data1(1:2) = (/1,2/)
data(ii)%data2(1:2) = (/-1,-2/)
end do
end select
! wrong result
write(*,*) gen_data%mydata(1:nn)%data1(1)
write(*,*) gen_data%mydata(1:nn)%data1(2)
! correct result
select type(data => gen_data%mydata)
type is (data_type2)
write(*,*) data(1:nn)%data1(1)
write(*,*) data(1:nn)%data1(2)
end select
end program test