Bug 67444 - [F03] RHS in assignment of polymorphic types not finalized
Summary: [F03] RHS in assignment of polymorphic types not finalized
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 5.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks: Finalization
  Show dependency treegraph
 
Reported: 2015-09-03 12:46 UTC by Bálint Aradi
Modified: 2016-11-16 20:25 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2015-09-03 00:00:00


Attachments
Fortran file demonstrating the issue (437 bytes, text/plain)
2015-09-03 12:46 UTC, Bálint Aradi
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bálint Aradi 2015-09-03 12:46:49 UTC
Created attachment 36291 [details]
Fortran file demonstrating the issue

Dear developer,

Thank you for your continuous effort to provide a free Fortran compiler with OOP-features.

In my oppinion, Gfortran behaves incorrectly, when instances of polymorphic types with user defined constructors are assigned to each other. Having an assignment of the type

a = MyType()

where also "a" is type(MyType) I'd expect expect following calling sequence:

* Constructor for MyType() producing the LHS
* Destructor (final procedure) of MyType finalizing instance "a"
* Assignment of MyType
* Destructor for MyType to finalize the RHS of the assignment.

According to the attached example, however, the last step is missing. I've checked the example with two other compilers, they all produced the sequence as given above. With gfortran, I get the output

Starting using Basic:
initBasic START
initBasic END
Destructing Basic -1
assignBasic START
assignBasic END
Values in basic:  43
Destructing Basic 43

while the correct one (with the additional line 7) should be.

Starting using Basic:
initBasic START
initBasic END
Destructing Basic -1
assignBasic START
assignBasic END
Destructing Basic 42
Values in basic:  43
Destructing Basic 43
Comment 1 Dominique d'Humieres 2015-09-03 16:17:31 UTC
Confirmed from 4.9 up to trunk (6.0). I have marked this PR as blocking pr37336. I have also added several other PRs to the list blocking pr37336. Could you please check that this PR is not a duplicate of one of them (being OOP challenged I have no idea of what finalization is doing)?
Comment 2 Bálint Aradi 2015-09-04 12:29:17 UTC
Apparently, this is point c) in PR 37336 comment 27.