https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81928
Daniel Krügler <daniel.kruegler at googlemail dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |daniel.kruegler@googlemail. | |com --- Comment #5 from Daniel Krügler <daniel.kruegler at googlemail dot com> --- (In reply to Matthieu Brucher from comment #4) > I would agree if the debug and optimized versions had the same behavior. > They do not. As such there should be a huge warning about the undefined > behavior. The test alone is not undefined behaviour. This is like requesting that the following code has undefined behaviour: int main() { int i = 12; int* that = &i; if (!that) {} } > And no, it's not valid code, it's an undefined behavior, you can do whatever > you want with it. Outputting an error is a better solution, even adding a > warning is. Silently optimizing an undefined behavior away is not. This argumentation is wrong. There is nothing fundamentally wrong to compare 'this' against null. The only reason to request a warning is because this test cannot evaluate to true in conforming programs.