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

            Bug ID: 113975
           Summary: function returning array is not fully evaluated before
                    assignement
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: comptes at ugo235 dot fr
  Target Milestone: ---

The following code is poorly designed, yet I think it is standard-conforming:
======================================
module foo
implicit none
    integer, parameter :: n=3
    integer :: a(n,n)
contains
    pure function bar()
    integer :: bar(n,n)
    bar = transpose(a)
    end function bar
end module foo

program main
use foo
implicit none
integer :: i

a = reshape([ 11, 12, 13 &
            , 21, 22, 23 &
            , 31, 32, 33 ], shape=[n,n], order=[2,1] )

a = bar()

do i = 1, n
    print*, a(i,:)
end do

end program main
======================================

In `a = bar()`, `bar()` should be fully evaluated before the result is assigned
to `a`, and it seems this is not the case. Consequently, the output of the
program compiled with gfortran 13.2 (without any option) is not the transpose
of the matrix that is entered in the code:

======================================
Program returned: 0
Program stdout

          11          12          13
          12          22          23
          13          23          33
======================================

Reply via email to