Bug 52202 - [C++11][DR 1376] Should not extend lifetime of temporary wrapped in static_cast to reference type
Summary: [C++11][DR 1376] Should not extend lifetime of temporary wrapped in static_ca...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Marek Polacek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-02-10 21:28 UTC by Jason Merrill
Modified: 2021-04-07 02:20 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-08-19 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jason Merrill 2012-02-10 21:28:24 UTC
// Core 1376                                                                                   
// { dg-options -std=c++0x }                                                                   

extern "C" void abort();
bool x;
struct T { ~T() { if (x) abort (); } };
int main()
{
  T&& r = static_cast<T&&>(T());
  x = true;
}
Comment 1 Eric Gallager 2017-08-19 21:55:39 UTC
Confirmed that the testcase aborts when run
Comment 2 ensadc 2017-10-21 13:30:56 UTC
Superseded by issue 1299? See http://wg21.link/p0727.
Comment 3 Eric Gallager 2017-10-25 18:39:53 UTC
(In reply to ensadc from comment #2)
> Superseded by issue 1299? See http://wg21.link/p0727.

To clarify for people who don't click on the link, that's C++ Core Issue 1299, not GCC's bug 1299.
Comment 4 Eric Gallager 2019-01-25 04:41:59 UTC
(In reply to ensadc from comment #2)
> Superseded by issue 1299? See http://wg21.link/p0727.

cc-ing Jens from that
Comment 5 Jens Maurer 2021-04-06 07:07:52 UTC
Core issue 1299 resolved via http://wg21.link/p0727 does in fact lifetime-extend the temporary in the example.

This bug report should therefore be closed without action.
(If a test case is missing that lifetime-extension does happen, the example code can have its "abort" condition reversed to suit that purpose.)
Comment 6 Marek Polacek 2021-04-07 02:12:36 UTC
I'll add the test.
Comment 7 CVS Commits 2021-04-07 02:19:39 UTC
The master branch has been updated by Marek Polacek <mpolacek@gcc.gnu.org>:

https://gcc.gnu.org/g:a7698c0e1ecad65b1ab651acc82b34e12c7efd35

commit r11-8022-ga7698c0e1ecad65b1ab651acc82b34e12c7efd35
Author: Marek Polacek <polacek@redhat.com>
Date:   Tue Apr 6 22:17:33 2021 -0400

    c++: Add test for Core issue 1376 [PR52202]
    
    As Jens says in the PR, we handle this correctly.
    
    gcc/testsuite/ChangeLog:
    
            PR c++/52202
            * g++.dg/cpp0x/rv-life.C: New test.
Comment 8 Marek Polacek 2021-04-07 02:20:23 UTC
Done.