https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102223
Bug ID: 102223
Summary: no warning whel calling member function on dangling
reference
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: federico.kircheis at gmail dot com
Target Milestone: ---
Consider this code-snippet
----
struct s{
s() noexcept;
~s();
int value() const noexcept;
};
s foo() noexcept;
int bar(){
const auto& v = static_cast<s>(foo());
int res = v.value();
return res;
}
----
Normally life-extension would kick in, but because we added an unnecessary
static_cast, it does not kick in and v is a dangling reference.
GCC does not emit any warning