[Bug c++/77298] -Wnonnull-compare only emitted for code which is invoked

msebor at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Aug 19 16:11:00 GMT 2016


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77298

--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
I should add that Clang issues the warning for all three functions:

$ /build/llvm-trunk/bin/clang -S -Wall -Wextra -Wpedantic z.C
z.C:2:21: warning: 'this' pointer cannot be null in well-defined C++ code;
      pointer may be assumed to always convert to true
      [-Wundefined-bool-conversion]
  int f () { return this ? 1 : 0; }
                    ^~~~ ~
z.C:6:21: warning: 'this' pointer cannot be null in well-defined C++ code;
      pointer may be assumed to always convert to true
      [-Wundefined-bool-conversion]
  int f () { return this ? 1 : 0; }
                    ^~~~ ~
z.C:13:22: warning: 'this' pointer cannot be null in well-defined C++ code;
      pointer may be assumed to always convert to true
      [-Wundefined-bool-conversion]
int C::f () { return this ? 1 : 0; }
                     ^~~~ ~
3 warnings generated.


More information about the Gcc-bugs mailing list