| 1 |
/* Test for multiple format_arg attributes. Test for both branches |
| 2 |
getting checked. */ |
| 3 |
/* Origin: Joseph Myers <[email protected]> */ |
| 4 |
/* { dg-do compile } */ |
| 5 |
/* { dg-options "-std=gnu99 -Wformat" } */ |
| 6 |
|
| 7 |
#include "format.h" |
| 8 |
|
| 9 |
extern char *ngettext (const char *, const char *, unsigned long int) |
| 10 |
__attribute__((__format_arg__(1))) __attribute__((__format_arg__(2))); |
| 11 |
|
| 12 |
void |
| 13 |
foo (long l, int nfoo) |
| 14 |
{ |
| 15 |
printf (ngettext ("%d foo", "%d foos", nfoo), nfoo); |
| 16 |
printf (ngettext ("%d foo", "%d foos", l), l); /* { dg-warning "int" "wrong type in conditional expr" } */ |
| 17 |
printf (ngettext ("%d foo", "%ld foos", l), l); /* { dg-warning "int" "wrong type in conditional expr" } */ |
| 18 |
printf (ngettext ("%ld foo", "%d foos", l), l); /* { dg-warning "int" "wrong type in conditional expr" } */ |
| 19 |
/* Should allow one case to have extra arguments. */ |
| 20 |
printf (ngettext ("1 foo", "%d foos", nfoo), nfoo); |
| 21 |
printf (ngettext ("1 foo", "many foos", nfoo), nfoo); /* { dg-warning "too many" "too many args in all branches" } */ |
| 22 |
printf (ngettext ("", "%d foos", nfoo), nfoo); |
| 23 |
printf (ngettext ("1 foo", (nfoo > 0) ? "%d foos" : "no foos", nfoo), nfoo); |
| 24 |
printf (ngettext ("%d foo", (nfoo > 0) ? "%d foos" : "no foos", nfoo), nfoo); |
| 25 |
printf (ngettext ("%ld foo", (nfoo > 0) ? "%d foos" : "no foos", nfoo), nfoo); /* { dg-warning "long int" "wrong type" } */ |
| 26 |
printf (ngettext ("%d foo", (nfoo > 0) ? "%ld foos" : "no foos", nfoo), nfoo); /* { dg-warning "long int" "wrong type" } */ |
| 27 |
printf (ngettext ("%d foo", (nfoo > 0) ? "%d foos" : "%ld foos", nfoo), nfoo); /* { dg-warning "long int" "wrong type" } */ |
| 28 |
} |