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.")
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.
Same bug as 54293. *** This bug has been marked as a duplicate of bug 54293 ***