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

            Bug ID: 87542
           Summary: bogus error on attribute format with a named constant
                    argument
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

The following program is accepted by GCC and triggers the expected diagnostic:

$ cat x.c && gcc -O2 -S -Wall x.c
enum { n = 1 };
__attribute__ ((format (printf, n, 2))) void f (const char*, ...);

void g (void)
{
  f ("%i", "");
}
x.c: In function ‘g’:
x.c:6:8: warning: format ‘%i’ expects argument of type ‘int’, but argument 2
has type ‘char *’ [-Wformat=]
   f ("%i", "");
       ~^   ~~
       %s


However, the same program in rejected in C++ with:

x.c:2:65: error: format string has invalid operand number
 __attribute__ ((format (printf, n, 2))) void f (const char*, ...);
                                                                 ^

Reply via email to