https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71904
Bug ID: 71904
Summary: comparing this to NULL should give a warning by
default (this == NULL)
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: manu at gcc dot gnu.org
Target Milestone: ---
Given the grief brought by the null-pointer check elimination for this, it
would be good if C++ diagnosed the simplest cases, so that users are not
shocked when their code starts segfaulting:
https://gcc.gnu.org/bugzilla/PR71892
void bar();
class A {
void test(void) { if (this == 0) bar();}
};
Clang:
rog.cc:3:25: warning: 'this' pointer cannot be null in well-defined C++ code;
comparison may be assumed to always evaluate to false
[-Wtautological-undefined-compare]
void test(void) { if (this == 0) bar();}
^~~~ ~