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

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