public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/95625] New: missing detail in -Waddress initializing a function argument
Date: Wed, 10 Jun 2020 17:09:05 +0000	[thread overview]
Message-ID: <bug-95625-4@http.gcc.gnu.org/bugzilla/> (raw)

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	other threads:[~2020-06-10 17:09 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-10 17:09 msebor at gcc dot gnu.org [this message]
2020-06-15 16:45 ` [Bug c/95625] " msebor at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-95625-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).