public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Martin Sebor <msebor@gmail.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: "Martin Liška" <mliska@suse.cz>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] Fix Werror=format-diag with --disable-nls.
Date: Thu, 20 Jan 2022 10:52:10 -0700	[thread overview]
Message-ID: <1a329e61-fee3-3c85-d1ac-72273a27e095@gmail.com> (raw)
In-Reply-To: <20220120170352.GS2646553@tucnak>

On 1/20/22 10:03, Jakub Jelinek wrote:
> On Thu, Jan 20, 2022 at 09:56:59AM -0700, Martin Sebor wrote:
>>> With normal -Wformat I see all expected warnings in:
>>> char *foo (const char *) __attribute__((format_arg(1)));
>>> void bar (const char *, ...) __attribute__((format(printf, 1, 2)));
>>
>> -Wformat-diag is internal to GCC and needs one of the GCC-internal
>> attributes to enable, like __gcc_cxxdiag__, for example like this:
>>
>>    __attribute__ ((format (__gcc_cxxdiag__, 1, 2)))
>>    void bar (const char *, ...);
>>
>> With that it triggers in all the same instances as -Wformat below
>> (as near I can tell for a modified test case).
> 
> Glad to hear that, but then I don't understand why we didn't warn on
> cp/error.cc before Martin L.'s change when --disable-nls wasn't used.

Good question!  There does seem to be some strange interplay between
parentheses and -Wformat for __gcc_cdiag__ functions in the C++ front
end:

__attribute__ ((format (__gcc_cxxdiag__, 1, 2)))
void bar (const char *, ...);

void
baz (int x)
{
   bar (x ? "<%s" : "%i", x);           // -Wformat-diag
   bar ((x ? "<%s" : "%i"), x);         // silence
   bar ((x ? ("<%s") : ("%i")), x);     // silence
}

The C front end warns on all three calls.

With attribute printf both the C and C++ front ends issue a -Wformat
for all three calls as expected (passing an int to %s).

Martin

  reply	other threads:[~2022-01-20 17:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-20  9:43 Martin Liška
2022-01-20 10:17 ` Jakub Jelinek
2022-01-20 10:28   ` Jakub Jelinek
2022-01-20 16:33     ` Martin Sebor
2022-01-20 16:43       ` Jakub Jelinek
2022-01-20 16:56         ` Martin Sebor
2022-01-20 17:03           ` Jakub Jelinek
2022-01-20 17:52             ` Martin Sebor [this message]
2022-01-20 18:18               ` Jakub Jelinek

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=1a329e61-fee3-3c85-d1ac-72273a27e095@gmail.com \
    --to=msebor@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=mliska@suse.cz \
    /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).