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

Harald Anlauf <anlauf at gmx dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |anlauf at gmx dot de

--- Comment #1 from Harald Anlauf <anlauf at gmx dot de> ---
Sergio,

I'm not sure about the first assignment, but the behavior in
the second case is certainly correct.

On the first assignment, a is not allocated.
On the second assignment, the shape of the RHS is the same,
so you get the same result.

If you modify your program as follows:

program return_allocatable
    implicit none

    real, allocatable :: a(:)

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

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

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

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

        allocate(foo(-3:n))

        foo=n
    end function
end program


You get:

           1 :           7
          -2 :           4

which is what you also get with Intel v14 and Crayftn 8.2.1.
However, xlf 14.1.0.5 agrees with you:

 -3 : 3
 -2 : 4

F2k8 states:

7.2.1.3 Interpretation of intrinsic assignments

If the variable is an unallocated allocatable array, expr shall have the same
rank. If the variable is an allocated
allocatable variable, it is deallocated if expr is an array of different shape, 
...
If the variable is or becomes an unallocated allocatable variable, it is then
allocated with
...
    • if expr is an array, the shape of expr with each lower bound equal to the
corresponding element of
      LBOUND (expr ).

Thus the assignment from the allocatable function result is broken.

Reply via email to