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

            Bug ID: 95625
           Summary: missing detail in -Waddress initializing a function
                    argument
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: minor
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

In a real-world scenario where the declaration of the called function was
removed from the call it took me a few minutes to understand what the warning
below was trying to tell me (I passed the address to the wrong argument):

$ cat t.C && gcc -O2 -S -Wall -Wextra t.C
void f (int, int, int, bool = false, int * = 0);

void g (int i)
{
  f (1, 2, 3, &i);
}
t.C: In function ‘void g(int)’:
t.C:5:15: warning: the address of ‘i’ will never be NULL [-Waddress]
    5 |   f (1, 2, 3, &i);
      |               ^~

Clang issues an almost identical message (so not much better) but the name of
the warning option it prints makes the problem much clearer:

t.C:5:16: warning: address of 'i' will always evaluate to 'true'
[-Wpointer-bool-conversion]
  f (1, 2, 3, &i);
  ~            ^
1 warning generated.


Printing a note pointing to the called function and referencing the argument to
which the address is passed would be even better.

The test case is C++ but a similar improvement applies to the C front end.

Reply via email to