This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/81928] if(!this) optimization leads to possible errors without warnings
- From: "matthieu.brucher at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 23 Aug 2017 08:23:33 +0000
- Subject: [Bug c++/81928] if(!this) optimization leads to possible errors without warnings
- Auto-submitted: auto-generated
- References: <bug-81928-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81928
--- Comment #2 from Matthieu Brucher <matthieu.brucher at gmail dot com> ---
No, I think the optimization is more than correct.
The warning doesn't warn of the actual problem, if you check against nullptr,
you won't even get a warning.
Comparing this to anything from Null to nullptr should be an error, not be
silently passed. Some people still think that it is valid because it worked in
the past and because it's a bad anti pattern.
So yes, it should be rejected because it's only point is to compare the pointer
to nullptr, which is not sane. And it must be rejected because gcc in optimized
mode considers this to be always not nullptr, and doesn't even warn that the
expression is thus constant. The user doesn't know that he screwed big time.