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: "daniel.kruegler at googlemail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 23 Aug 2017 17:32:47 +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
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.