On Thu, Jan 20, 2022 at 10:52:10AM -0700, Martin Sebor wrote:
> 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).
Filed PR104148 now.
Jakub