public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/95625] New: missing detail in -Waddress initializing a function argument
@ 2020-06-10 17:09 msebor at gcc dot gnu.org
  2020-06-15 16:45 ` [Bug c/95625] " msebor at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-06-10 17:09 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c/95625] missing detail in -Waddress initializing a function argument
  2020-06-10 17:09 [Bug c/95625] New: missing detail in -Waddress initializing a function argument msebor at gcc dot gnu.org
@ 2020-06-15 16:45 ` msebor at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-06-15 16:45 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c++                         |c

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
As mentioned in comment #0, this is a generic C/C++ improvement: "The test case
is C++ but a similar improvement applies to the C front end."  In fact, it's
even more relevant to C where the warning doesn't underline the argument it
refers to:

Here's a corresponding C test case.  Wh

$ cat pr95625.c && gcc -O2 -S -Wall -Wextra pr95625.c
void f (int, int, int, _Bool, int *);

void g (int i)
{
  f (1, 2, 3, &i, &i);
}
pr95625.c: In function ‘g’:
pr95625.c:5:3: warning: the address of ‘i’ will always evaluate as ‘true’
[-Waddress]
    5 |   f (1, 2, 3, &i, &i);
      |   ^

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-06-15 16:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-10 17:09 [Bug c/95625] New: missing detail in -Waddress initializing a function argument msebor at gcc dot gnu.org
2020-06-15 16:45 ` [Bug c/95625] " msebor at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).