Bug 29434 - array bounds of allocatable components of derived types?
Summary: array bounds of allocatable components of derived types?
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-10-11 19:12 UTC by Dominique d'Humieres
Modified: 2006-10-13 05:13 UTC (History)
1 user (show)

See Also:
Host:
Target: x86_64-unknown-linux-gnu
Build: 4.2.0 20061009
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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