[cfe-dev] Warning for initializing a reference with literal
Richtarsky, Martin via cfe-dev
cfe-dev at lists.llvm.org
Fri Apr 21 01:38:12 PDT 2017
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;
}
Thanks and Best regards,
Martin
More information about the cfe-dev
mailing list