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 15:59:31 +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
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |msebor at gcc dot gnu.org
--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
I was about to comment on this but Manuel beat me to it.
The problem seems to be that the function is defined inline. When it's
out-of-line, the warning is emitted.
I'm inclined to agree with the submitter. The warning should be issued
consistently for inline functions as well as out-of-line ones, regardless of
whether they are called. Otherwise it will miss the problem in inline
functions in class libraries (that aren't being sufficiently tested).
$ cat z.C && /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc -O0
-Wall -Wextra z.C
struct A {
int f () { return this ? 1 : 0; }
};
struct B {
int f () { return this ? 1 : 0; } // missing -Wnonnull-compare
};
struct C {
int f ();
};
int C::f () { return this ? 1 : 0; }
int main()
{
return A ().f ();
}
z.C: In member function ‘int A::f()’:
z.C:2:26: warning: nonnull argument ‘this’ compared to NULL [-Wnonnull-compare]
int f () { return this ? 1 : 0; }
~~~~~^~~~~~~
z.C: In member function ‘int C::f()’:
z.C:13:27: warning: nonnull argument ‘this’ compared to NULL
[-Wnonnull-compare]
int C::f () { return this ? 1 : 0; }
~~~~~^~~~~~~