https://bugs.llvm.org/show_bug.cgi?id=32800
Bug ID: 32800
Summary: Emit warning for initializing a reference with
literal/temporary
Product: clang
Version: unspecified
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: -New Bugs
Assignee: unassignedclangb...@nondot.org
Reporter: cl...@martinien.de
CC: llvm-bugs@lists.llvm.org
Hi,
would it be possible to emit a warning for the code below? I could imagine this
case could be detected easily in the frontend / middleend.
ASan finds this with detect_stack_use_after_return enabled, but this option is
sometimes not feasible due to high memory usage.
struct RefStorer
{
RefStorer(const bool& ref): m_ref(ref) {}
const bool& m_ref;
};
RefStorer getRefStorer()
{
return RefStorer(false); // false passed as reference
}
int main()
{
RefStorer r = getRefStorer(); // m_ref now dangling
return 0;
}
Additionally such cases should also be handled:
RefStorer getRefStorer()
{
bool b = false;
return RefStorer(b);
}
Best regards,
Martin
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs