Title
Wording nit on lifetime of temporaries to which references are bound
Status
cd1
Section
6.7.7 [class.temporary]
Submitter
Allan Odgaard

Created on 2004-02-21.00:00:00 last changed 196 months ago

Messages

Date: 2006-04-15.00:00:00

[Voted into WP at April, 2006 meeting.]

Date: 2005-10-15.00:00:00

Proposed resolution (October, 2005):

Change 6.7.7 [class.temporary] paragraph 5 as follows:

... In addition, the destruction of temporaries bound to references shall take into account the ordering of destruction of objects with static or automatic storage duration (6.7.5.2 [basic.stc.static], 6.7.5.4 [basic.stc.auto]); that is, if obj1 is an object with static or automatic storage duration created before the temporary is created with the same storage duration as the temporary, the temporary shall be destroyed before obj1 is destroyed; if obj2 is an object with static or automatic storage duration created after the temporary is created with the same storage duration as the temporary, the temporary shall be destroyed after obj2 is destroyed...
Date: 2004-10-15.00:00:00

Notes from October 2004 meeting:

We agreed with Steve Adamczyk's suggestion.

Date: 2004-11-07.00:00:00

Section 6.7.7 [class.temporary] paragraph 5 ends with this "rule":

[...] if obj2 is an object with static or automatic storage duration created after the temporary is created, the temporary shall be destroyed after obj2 is destroyed.

For the temporary to be destroyed after obj2 is destroyed, when obj2 has static storage, I would say that the reference to the temporary should also have static storage, but that is IMHO not clear from the paragraph.

Example:

    void f ()
    {
       const T1& ref = T1();
       static T2 obj2;
       ...
    }

Here the temporary would be destoyed before obj2, contrary to the rule above.

Steve Adamczyk: I agree there's a minor issue here. I think the clause quoted above meant for obj1 and obj2 to have the same storage duration. Replacing "obj2 is an object with static or automatic storage duration" by "obj2 is an object with the same storage duration as obj1" would, I believe, fix the problem.

History
Date User Action Args
2008-10-05 00:00:00adminsetstatus: wp -> cd1
2006-11-05 00:00:00adminsetstatus: dr -> wp
2006-04-22 00:00:00adminsetmessages: + msg1365
2006-04-22 00:00:00adminsetstatus: ready -> dr
2005-10-22 00:00:00adminsetstatus: review -> ready
2005-05-01 00:00:00adminsetmessages: + msg1148
2005-05-01 00:00:00adminsetstatus: drafting -> review
2004-11-07 00:00:00adminsetmessages: + msg1078
2004-11-07 00:00:00adminsetstatus: open -> drafting
2004-02-21 00:00:00admincreate