[cfe-dev] Warning for initializing a reference with literal
Daniel Marjamäki via cfe-dev
cfe-dev at lists.llvm.org
Mon Apr 24 02:31:46 PDT 2017
> Should I file an (enhancement) bug?
yes please.
Best regards,
Daniel Marjamäki
..................................................................................................................
Daniel Marjamäki Senior Engineer
Evidente ES East AB Warfvinges väg 34 SE-112 51 Stockholm Sweden
Mobile: +46 (0)709 12 42 62
E-mail: Daniel.Marjamaki at evidente.se
www.evidente.se
________________________________________
From: Richtarsky, Martin [martin.richtarsky at sap.com]
Sent: 24 April 2017 09:32
To: Daniel Marjamäki; cfe-dev at lists.llvm.org
Subject: RE: Warning for initializing a reference with literal
> We need path sensitive analysis.
I agree, those more complicated cases should be detected as well (including a helpful warning text that makes it clear why this is bad)
Should I file an (enhancement) bug?
Best regards,
Martin
-----Original Message-----
From: Daniel Marjamäki [mailto:Daniel.Marjamaki at evidente.se]
Sent: Freitag, 21. April 2017 12:08
To: Richtarsky, Martin <martin.richtarsky at sap.com>; cfe-dev at lists.llvm.org
Subject: RE: Warning for initializing a reference with literal
Hello!
It's not enough to just warn about passing literal. Imagine the user fixes the warning like this:
RefStorer getRefStorer()
{
bool b = false;
return RefStorer(b);
}
If warning goes away with this solution, I guess many users will probably do that.
We need path sensitive analysis.
Writing a warning for this bug sounds very good, if we add a proper path sensitive check.
Best regards,
Daniel Marjamäki
..................................................................................................................
Daniel Marjamäki Senior Engineer
Evidente ES East AB Warfvinges väg 34 SE-112 51 Stockholm Sweden
Mobile: +46 (0)709 12 42 62
E-mail: Daniel.Marjamaki at evidente.se
www.evidente.se
________________________________________
From: cfe-dev [cfe-dev-bounces at lists.llvm.org] on behalf of Richtarsky, Martin via cfe-dev [cfe-dev at lists.llvm.org]
Sent: 21 April 2017 10:38
To: cfe-dev at lists.llvm.org
Subject: [cfe-dev] Warning for initializing a reference with literal
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
_______________________________________________
cfe-dev mailing list
cfe-dev at lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
More information about the cfe-dev
mailing list