[llvm-bugs] [Bug 32800] New: Emit warning for initializing a reference with literal/temporary
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Apr 26 03:54:58 PDT 2017
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: unassignedclangbugs at nondot.org
Reporter: clang at martinien.de
CC: llvm-bugs at 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170426/2dfe02cb/attachment.html>
More information about the llvm-bugs
mailing list