Bug 60297 - Temporary lifetime not extended by reference bound to scalar member
Summary: Temporary lifetime not extended by reference bound to scalar member
Status: RESOLVED DUPLICATE of bug 54293
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-21 04:30 UTC by David Krauss
Modified: 2016-10-05 20:20 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Krauss 2014-02-21 04:30:29 UTC
The resolution to DR 1651 seems inconsistently applied. This program should print "check" before "destroy", but if the reference is bound to member "i" instead of "np" the lifetime is not extended.

#include <iostream>

struct notpod {
    ~notpod() {}
};

struct noisy {
    ~noisy() { std::cout << "destroy\n"; }
};

struct cont {
    noisy o;
    notpod np;
    int i;
};

int main() {
    {
        notpod && q = cont().np;
        std::cout << "check\n";
    } // cont::~cont here

    {
        int && i = cont().i;
        // cont::~cont here; i is dangling.
        std::cout << "check\n";
    }
}

The problem may be broader than DR 1651 because the results are the same if "const &" is substituted for "&&".

(Note, I submitted a trivial, somewhat similar bug yesterday but this issue is completely unrelated, and it's "for real.")
Comment 1 David Krauss 2014-02-21 05:33:24 UTC
Woops, I neglected to check a POD class type. Removing the destructor from "notpod" has no effect. The condition seems to apply to all scalar types instead.
Comment 2 Jason Merrill 2016-10-05 20:20:06 UTC
Same bug as 54293.

*** This bug has been marked as a duplicate of bug 54293 ***