public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/106576] New: Finalization of temporaries from functions not occuring
@ 2022-08-10  7:45 tkoenig at gcc dot gnu.org
  2022-08-10 16:50 ` [Bug fortran/106576] " tkoenig at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: tkoenig at gcc dot gnu.org @ 2022-08-10  7:45 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-03-18 17:34 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-10  7:45 [Bug fortran/106576] New: Finalization of temporaries from functions not occuring tkoenig at gcc dot gnu.org
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

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).