public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "comptes at ugo235 dot fr" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/113975] New: function returning array is not fully evaluated before assignement
Date: Sat, 17 Feb 2024 19:36:34 +0000	[thread overview]
Message-ID: <bug-113975-4@http.gcc.gnu.org/bugzilla/> (raw)

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	other threads:[~2024-02-17 19:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-17 19:36 comptes at ugo235 dot fr [this message]
2024-02-17 20:21 ` [Bug fortran/113975] " anlauf at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-113975-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).