[Bug c++/81928] if(!this) optimization leads to possible errors without warnings

matthieu.brucher at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed Aug 23 11:33:00 GMT 2017


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.


More information about the Gcc-bugs mailing list