public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "tkoenig at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/106576] New: Finalization of temporaries from functions not occuring
Date: Wed, 10 Aug 2022 07:45:27 +0000	[thread overview]
Message-ID: <bug-106576-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 106576
           Summary: Finalization of temporaries from functions not
                    occuring
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tkoenig at gcc dot gnu.org
  Target Milestone: ---

Test case:

$ cat g2.f90
module y
  implicit none
  type foo
     integer :: n
   contains
     final :: cleanup
  end type foo
  interface assignment (=)
     module procedure assign
  end interface assignment (=)
contains

  subroutine assign (rop, op)
    type(foo), intent(inout) :: rop
    type(foo), intent(in) :: op
    rop%n = op%n + 1
    print '(A12,I3)',"assign", rop%n
  end subroutine assign

  function to_foo(n) result(res)
    integer, intent(in) :: n
    type (foo) :: res
    res%n = n
    print '(A12,I3)', "to_foo", res%n
  end function to_foo

  subroutine cleanup (self)
    type (foo), intent(inout) :: self
    print '(A12,I3)', "cleanup", self%n
  end subroutine cleanup
end module y

program memain
  use y
  implicit none
  call chk
contains
  subroutine chk
    type (foo) :: a
    a = to_foo(3)
  end subroutine chk
end program memain
$ gfortran g2.f90 && ./a.out
      to_foo  3
      assign  4
     cleanup  4
$ nagfor g2.f90 && ./a.out
NAG Fortran Compiler Release 7.1(Hanzomon) Build 7101
[NAG Fortran Compiler normal termination]
      to_foo  3
      assign  4
     cleanup  3
     cleanup  4

NAG is in fact correct, the temporary from the function results should also
be finalized.

This actually blocks my little FMPFR library, so I might have a stab
at this myself.

             reply	other threads:[~2022-08-10  7:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-10  7:45 tkoenig at gcc dot gnu.org [this message]
2022-08-10 16:50 ` [Bug fortran/106576] " tkoenig at gcc dot gnu.org
2022-08-13 16:09 ` tkoenig at gcc dot gnu.org
2022-11-12 15:55 ` tkoenig at gcc dot gnu.org
2022-11-28 15:11 ` pault at gcc dot gnu.org
2022-11-28 15:12 ` pault at gcc dot gnu.org
2022-12-04 17:27 ` tkoenig at gcc dot gnu.org
2022-12-06  6:12 ` pault at gcc dot gnu.org
2023-03-18  7:56 ` cvs-commit at gcc dot gnu.org
2023-03-18 17:34 ` pault 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-106576-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).