Bug 59694 - [F03] no finalization of an unused variable
Summary: [F03] no finalization of an unused variable
Status: REOPENED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
: 67472 (view as bug list)
Depends on:
Blocks: Finalization
  Show dependency treegraph
 
Reported: 2014-01-06 06:51 UTC by Damian Rouson
Modified: 2020-12-15 10:14 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-01-06 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Damian Rouson 2014-01-06 06:51:20 UTC
With the current trunk, the final subroutine is not invoked when the variable "bar" goes out of scope in the following code:

localhost:~ rouson$ cat final.f90 
module foo_module
  implicit none
  type foo
  contains
    final :: hello
  end type
contains
  subroutine hello(this)
    type(foo) :: this
    print *,"Hello from finalizer."
  end subroutine
end module
program main
  use foo_module
  implicit none
  block
    type(foo) :: bar
  end block
end program
localhost:~ rouson$ /usr/local/bin/gfortran final.f90 
localhost:~ rouson$ ./a.out
localhost:~ rouson$ /usr/local/bin/gfortran --version
GNU Fortran (GCC) 4.9.0 20140104 (experimental)
Copyright (C) 2014 Free Software Foundation, Inc.

While this behavior seems reasonable at high optimization levels, I believe the final subroutine should at least be invoked for the default optimization level.  The NAG compiler invokes the final subroutine.

Damian
Comment 1 Ian Harvey 2015-09-07 09:54:43 UTC
*** Bug 67472 has been marked as a duplicate of this bug. ***
Comment 2 Damian Rouson 2016-12-01 21:56:05 UTC
Marking as invalid.
Comment 3 Ian Harvey 2016-12-03 10:45:24 UTC
Why has this been marked as invalid?
Comment 4 Damian Rouson 2016-12-04 02:30:09 UTC
I meant to mark a different PR as invalid but marked this one mistakenly.  Now I just tried to reset its status duplicate and got the following message:

"You cannot mark bug 59694 as a duplicate of bug 67472, because it would create a duplicate loop."
Comment 5 janus 2016-12-04 08:45:21 UTC
(In reply to Damian Rouson from comment #4)
> I meant to mark a different PR as invalid but marked this one mistakenly.

Which one? So, should we reopen this one?


> Now I just tried to reset its status duplicate and got the following message:
> 
> "You cannot mark bug 59694 as a duplicate of bug 67472, because it would
> create a duplicate loop."

That's because PR 67472 is already marked as a duplicate of PR 59694.
Comment 6 Damian Rouson 2016-12-04 08:52:28 UTC
Mistakenly closed. Reopening.
Comment 7 Damian Rouson 2016-12-04 08:55:15 UTC
> On Dec 4, 2016, at 12:45 AM, janus at gcc dot gnu.org <gcc-bugzilla@gcc.gnu.org> wrote:
> 
> --- Comment #5 from janus at gcc dot gnu.org ---
> (In reply to Damian Rouson from comment #4)
>> I meant to mark a different PR as invalid but marked this one mistakenly.
> 
> Which one?

78161, which I have now marked as invalid.

> So, should we reopen this one?

Yes.  I didn’t previously understand the options. I just discovered the “reopened” option and submitted the change to reopen this.  Hopefully this PR is finally back in the correct state.

Damian
Comment 8 janus 2016-12-04 09:03:39 UTC
(In reply to Damian Rouson from comment #7)
> Hopefully this PR is finally back in the correct state.

I think so. Thanks.