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; }
                      ~~~~~^~~~~~~

Reply via email to