Bug 29434

Summary: array bounds of allocatable components of derived types?
Product: gcc Reporter: Dominique d'Humieres <dominiq>
Component: fortranAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED INVALID    
Severity: normal CC: gcc-bugs
Priority: P3    
Version: 4.2.0   
Target Milestone: ---   
Host: Target: x86_64-unknown-linux-gnu
Build: 4.2.0 20061009 Known to work:
Known to fail: Last reconfirmed:

Description Dominique d'Humieres 2006-10-11 19:12:15 UTC
The following code (derived from alloc_comp_constructor_1.f90):

! { dg-do run }
! { dg-options "-fdump-tree-original" }
! Test constructors of derived type with allocatable components (PR 20541).
!
! Contributed by Erik Edelmann  <eedelmann@gcc.gnu.org>
!            and Paul Thomas  <pault@gcc.gnu.org>
!

Program test_constructor

    implicit none

    type :: thytype
	integer(4) :: a(2,2)
    end type thytype

    type :: mytype
	integer(4), allocatable :: a(:, :)
	type(thytype), allocatable :: q(:)
    end type mytype

    type (mytype) :: x
    type (thytype) :: foo = thytype(reshape ([43, 100, 54, 76], [2,2]))
    integer :: y(0:1, -1:0) = reshape ([42, 99, 55, 77], [2,2])

    x = mytype(y, [foo, foo])
    if (.not.allocated(x%a) .or. .not.allocated(x%q)) call abort()
    print *, 'y bounds'
    print *, lbound(y)
    print *, ubound(y)
    print *, 'x%a bounds'
    print *, lbound(x%a)
    print *, ubound(x%a)

end program test_constructor

compiled with ifort or gfortran, it returns

y bounds
	  0          -1
	  1           0
x%a bounds
	  0          -1
	  1           0

while compiled with g95, it returns

y bounds
0 -1
1 0
x%a bounds
1 1
2 2

What is the "standard conforming" answer?

Dominique
Comment 1 Brooks Moses 2006-10-11 22:00:59 UTC
As per discussion on the fortran@ mailing list, the answer returned by gfortran and ifort (namely, that LBOUND(x%a) is the same as LBOUND(y)) is standard-conforming, and g95 is in error.
Comment 2 Paul Thomas 2006-10-13 05:13:55 UTC
Thanks, Dominique, for provoking the discussion and to veryone else for the discussion and the resolution of the PR.

Paul