On 1/20/22 09:43, Jakub Jelinek wrote:
On Thu, Jan 20, 2022 at 09:33:30AM -0700, Martin Sebor wrote:
Oh, and one more thing, but this time not about this source file but about
the warning.  Does it handle the gettext case?
I think -Wformat generally does, gettext has format_arg attribute.
If the warning handles
    pp_printf ("<unnamed %s>", str);
and
    pp_printf (cond ? "<unnamed %s>" : "<unnamed %s>", str);
and
    pp_printf (cond ? "<unnamed %s>" : "something %s", str);
and
    pp_printf (gettext ("<unnamed %s>"), str);
then maybe it should also handle
    pp_printf (cond ? gettext ("<unnamed %s>") : "<unnamed %s>, str);
and
    pp_printf (cond ? gettext ("<unnamed %s>") : "something %s, str);
too?

-Wformat-diag is part of -Wformat so they both should handle the same
things.  Do you see a difference between what they handle?

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).

Martin


void
baz (int x)
{
   bar ("%ld", x);
   bar (x ? "%ld" : "%ld", x);
   bar (x ? "%ld" : "%lld", x);
   bar (foo ("%ld"), x);
   bar (x ? foo ("%ld") : "%ld", x);
   bar (x ? foo ("%ld") : "%lld", x);
   bar (foo (x ? "%ld" : "%ld"), x);
   bar (foo (x ? "%ld" : "%lld"), x);
}
(on all bar calls, on those with different strings or one in foo and other
not 2).
 From the fact that -Wformat-diag didn't warn on the
pp_printf (cond ? gettext ("<unnamed %s>") : "<unnamed %s>, str);
case I assume -Wformat-diag doesn't handle this.

        Jakub


Reply via email to