Movatterモバイル変換


[0]ホーム

URL:


This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 118e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-11-05


464. Wording nit on lifetime of temporaries to which references are bound

Section:6.8.7  [class.temporary]    Status:CD1    Submitter:Allan Odgaard    Date:21 Feb 2004

[Voted into WP at April, 2006 meeting.]

Section 6.8.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 hasstatic storage, I would say that the reference to the temporary shouldalso have static storage, but that is IMHO not clear from theparagraph.

Example:

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

Here the temporary would be destoyedbefore obj2, contrary to therule above.

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

Notes from October 2004 meeting:

We agreed with Steve Adamczyk's suggestion.

Proposed resolution (October, 2005):

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

... In addition, the destruction of temporaries bound to referencesshall take into account the ordering of destruction of objects withstatic or automatic storage duration (6.8.6.2 [basic.stc.static],6.8.6.4 [basic.stc.auto]); that is, ifobj1 is an objectwith static or automatic storage duration created before thetemporary is createdwith the same storage duration as thetemporary, the temporary shall be destroyed beforeobj1is destroyed; ifobj2 is an objectwith static orautomatic storage duration created after the temporary iscreatedwith the same storage duration as the temporary, thetemporary shall be destroyed afterobj2 is destroyed...



[8]ページ先頭

©2009-2025 Movatter.jp