This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/71904] New: comparing this to NULL should give a warning by default (this == NULL)
- From: "manu at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sat, 16 Jul 2016 15:35:00 +0000
- Subject: [Bug c++/71904] New: comparing this to NULL should give a warning by default (this == NULL)
- Auto-submitted: auto-generated
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();}
^~~~ ~