[Bug fortran/59398] Wrong bounds for allocatable result and for

dominiq at lps dot ens.fr gcc-bugzilla@gcc.gnu.org
Sun Aug 30 15:39:00 GMT 2015


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59398

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pault at gcc dot gnu.org

--- Comment #10 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
> That seems to be the case. For the moment, the lesson I learnt is never
> to return arrays with a lower bound different from 1.

The following variant

program return_allocatable
    implicit none

    real, allocatable :: a(:)

    real, parameter :: b(-2:4)=[1,2,3,4,5,6,7]

    a=b
    print*,lbound(a),':',ubound(a)

    deallocate(a)
    a=foo(3)
    print*,lbound(a),':',ubound(a)

contains
    function foo(n) result(res)
        integer :: n
        real, allocatable :: res(:)

        allocate(res(-3:n))

        res=n
        print *, lbound(res), ubound(res)
    end function
end program

gives (with the default -frealloc-lhs)

          -2 :           4
          -3           3
           1 :           7

Is this correct?

> This kind of sucks. Why having lower bounds different than 0 sometimes only?
> Either have them, or don't!

In Fortran the default lower bounds are always 1 and never 0.



More information about the Gcc-bugs mailing list