[Bug c++/77298] New: -Wnonnull-compare only emitted for code which is invoked
wipedout at yandex dot ru
gcc-bugzilla@gcc.gnu.org
Fri Aug 19 15:06:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77298
Bug ID: 77298
Summary: -Wnonnull-compare only emitted for code which is
invoked
Product: gcc
Version: 6.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: wipedout at yandex dot ru
Target Milestone: ---
On http://gcc.godbolt.org/ I select gcc 6.1 and specify -O3 -Wall
The code is:
struct CHandle {
int handle;
int GetHandle() const
{
if (this != 0) //[-Wnonnull-compare] emitted
return handle;
return 0;
}
};
int main()
{
CHandle* h = new CHandle();
return h->GetHandle();
}
Initially [-Wnonnull-compare] is emitted where "this" is checked for null. Now
I change main() to this:
int main()
{
CHandle* h = new CHandle();
return 0;//h->GetHandle();
}
and the warning is no longer emitted. The code is compiled and it's known at
compile time that there's a check of "this" against null yet not warning.
More information about the Gcc-bugs
mailing list