This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/59398] Wrong bounds for allocatable result and for
- From: "dominiq at lps dot ens.fr" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 30 Aug 2015 15:38:57 +0000
- Subject: [Bug fortran/59398] Wrong bounds for allocatable result and for
- Auto-submitted: auto-generated
- References: <bug-59398-4 at http dot gcc dot gnu dot org/bugzilla/>
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.