This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/77298] -Wnonnull-compare only emitted for code which is invoked
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 19 Aug 2016 16:11:23 +0000
- Subject: [Bug c++/77298] -Wnonnull-compare only emitted for code which is invoked
- Authentication-results: sourceware.org; auth=none
- Auto-submitted: auto-generated
- References: <bug-77298-4@http.gcc.gnu.org/bugzilla/>
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.