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

            Bug ID: 111281
           Summary: unhelpful warning output ('nonnull' argument 'v'
                    compared to NULL)
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: f.heckenb...@fh-soft.de
  Target Milestone: ---

% cat test.cpp
#include <iostream>

void f (const auto &v) { std::cout << v; }

int t ();

int main ()
{
  f (t);
}
% g++ -c -std=c++20 -Wall test.cpp
test.cpp: In function 'void f(const auto:11&) [with auto:11 = int()]':
test.cpp:3:36: warning: 'nonnull' argument 'v' compared to NULL
[-Wnonnull-compare]
    3 | void f (const auto &v) { std::cout << v; }
      |                          ~~~~~~~~~~^~~~

Of course, there is an error in the code (trying to output a function pointer),
but the message given is completely useless:

- There is no "nonnull" in the code.

- There is no comparison (to NULL or anything else for that matter) in the
code.

Most importantly, the message points to an innocent function that doesn't
contain the actual error. While other times (e.g.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109561) GCC likes to give pages
upon pages of questionable context, here it's giving clearly too little for the
message to be of any use.

I guess it's hard to determine a good amount of context to give, but the
following two pieces of information seem essential to me:

- The actual location of the code that the message refers to. Here, it must be
somewhere in the library which is often hard to read, but at least may give a
clue about what's going on. But the message doesn't say where.

- The source code location that ultimately causes the code to be generated
(here, the line in main). Of course, in the case of template instantiations it
must be tracked (but in other cases GCC does this already) and there may be
several places doing the same instantiation (but giving any of them would be
better than none).

As it is, the message doesn't say anything relevant about the code and doesn't
point to any relevant location, so when I got it in my actual code, I wouldn't
even know where to start looking. (Other than, as usual, guessing one of the
most recent changes, but for that we only need "something's wrong" messages. ;)

Reply via email to