public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jonathan.leffler at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/106039] Inconsistent error reporting for printf() when format string is a macro
Date: Tue, 21 Jun 2022 01:46:05 +0000	[thread overview]
Message-ID: <bug-106039-4-LRrFcljNQK@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-106039-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #4 from Jonathan Leffler <jonathan.leffler at gmail dot com> ---
Thank you for looking at this.

In the second and subsequent errors, the line number of the macro is used
in all three lines of the error report, whereas in the first, the second
line of the messages is the `printf()` line and not the macro line again.

On Mon, Jun 20, 2022 at 19:10 pinskia at gcc dot gnu.org <
gcc-bugzilla@gcc.gnu.org> wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106039
>
> --- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
> I don't see an issue with the diagnostic here really.
>
> For the single line case (without the format as a macro):
>     printf("%-21s %-16x %-16x %-18s %-18s\n", "GHI", (intptr_t) val1,
> (intptr_t) val1, "ABC", "DEF");
>
>
> We get:
>
> <source>:22:23: warning: format '%x' expects argument of type 'unsigned
> int',
> but argument 3 has type 'long int' [-Wformat=]
>    22 |     printf("%-21s %-16x %-16x %-18s %-18s\n", "GHI", (intptr_t)
> val1,
> (intptr_t) val1, "ABC", "DEF");
>       |                   ~~~~^
> ~~~~~~~~~~~~~~~
>       |                       |                              |
>       |                       unsigned int                   long int
>       |                   %-16lx
> <source>:22:29: warning: format '%x' expects argument of type 'unsigned
> int',
> but argument 4 has type 'long int' [-Wformat=]
>    22 |     printf("%-21s %-16x %-16x %-18s %-18s\n", "GHI", (intptr_t)
> val1,
> (intptr_t) val1, "ABC", "DEF");
>       |                         ~~~~^
>
> ~~~~~~~~~~~~~~~
>       |                             |
>    |
>       |                             unsigned int
>
> long int
>       |                         %-16lx
>
> are you asking to point out where the arguments were for the macro case?
>
> --
> You are receiving this mail because:
> You reported the bug.

  parent reply	other threads:[~2022-06-21  1:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-21  0:44 [Bug c/106039] New: " jonathan.leffler at gmail dot com
2022-06-21  0:47 ` [Bug c/106039] " jonathan.leffler at gmail dot com
2022-06-21  0:50 ` jonathan.leffler at gmail dot com
2022-06-21  1:10 ` pinskia at gcc dot gnu.org
2022-06-21  1:46 ` jonathan.leffler at gmail dot com [this message]
2022-06-21  2:52 ` jonathan.leffler at gmail dot com

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-106039-4-LRrFcljNQK@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).