diff options
Diffstat (limited to 'gcc/testsuite/gcc.dg/format/c90-printf-1.c')
-rw-r--r-- | gcc/testsuite/gcc.dg/format/c90-printf-1.c | 183 |
1 files changed, 97 insertions, 86 deletions
diff --git a/gcc/testsuite/gcc.dg/format/c90-printf-1.c b/gcc/testsuite/gcc.dg/format/c90-printf-1.c index 55ba8bdb719..5329dad83a4 100644 --- a/gcc/testsuite/gcc.dg/format/c90-printf-1.c +++ b/gcc/testsuite/gcc.dg/format/c90-printf-1.c @@ -34,28 +34,35 @@ foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p, */ printf ("%.e\n", d); /* { dg-bogus "precision" "bogus precision warning" } */ /* Bogus use of width. */ - printf ("%5n\n", n); /* { dg-warning "11:width" "width with %n" } */ + printf ("%5n\n", n); /* { dg-warning "14:width" "width with %n" } */ /* Erroneous, ignored or pointless constructs with precision. */ /* Whether negative values for precision may be included in the format string is not entirely clear; presume not, following Clive Feather's proposed resolution to DR#220 against C99. In any case, such a construct should be warned about. */ - printf ("%.-5d\n", i); /* { dg-warning "11:format|precision" "negative precision warning" } */ - printf ("%.-*d\n", i); /* { dg-warning "11:format" "broken %.-*d format" } */ - printf ("%.3c\n", i); /* { dg-warning "11:precision" "precision with %c" } */ - printf ("%.3p\n", p); /* { dg-warning "11:precision" "precision with %p" } */ - printf ("%.3n\n", n); /* { dg-warning "11:precision" "precision with %n" } */ + printf ("%.-5d\n", i); /* { dg-warning "14:format|precision" "negative precision warning" } */ + /* { dg-warning "too many arguments for format" "too many arguments" { target *-*-* } 44 } */ + printf ("%.-*d\n", i); /* { dg-warning "14:format" "broken %.-*d format" } */ + /* { dg-warning "too many arguments for format" "too many arguments" { target *-*-* } 46 } */ + printf ("%.3c\n", i); /* { dg-warning "15:precision" "precision with %c" } */ + printf ("%.3p\n", p); /* { dg-warning "15:precision" "precision with %p" } */ + printf ("%.3n\n", n); /* { dg-warning "15:precision" "precision with %n" } */ /* Valid and invalid %% constructions. Some of the warning messages are non-optimal, but they do detect the errorneous nature of the format string. */ printf ("%%"); - printf ("%.3%"); /* { dg-warning "11:format" "bogus %%" } */ - printf ("%-%"); /* { dg-warning "11:format" "bogus %%" } */ - printf ("%-%\n"); /* { dg-warning "11:format" "bogus %%" } */ - printf ("%5%\n"); /* { dg-warning "11:format" "bogus %%" } */ - printf ("%h%\n"); /* { dg-warning "11:format" "bogus %%" } */ + printf ("%.3%"); /* { dg-warning "14:type" "missing type" } */ + /* { dg-warning "15:trailing" "bogus %%" { target *-*-* } 56 } */ + printf ("%-%"); /* { dg-warning "13:type" "missing type" } */ + /* { dg-warning "14:trailing" "bogus %%" { target *-*-* } 58 } */ + printf ("%-%\n"); /* { dg-warning "13:format" "bogus %%" } */ + /* { dg-warning "15:format" "bogus %%" { target *-*-* } 60 } */ + printf ("%5%\n"); /* { dg-warning "13:format" "bogus %%" } */ + /* { dg-warning "15:format" "bogus %%" { target *-*-* } 62 } */ + printf ("%h%\n"); /* { dg-warning "13:format" "bogus %%" } */ + /* { dg-warning "15:format" "bogus %%" { target *-*-* } 64 } */ /* Valid and invalid %h, %l, %L constructions. */ printf ("%hd", i); printf ("%hi", i); @@ -67,30 +74,30 @@ foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p, */ printf ("%ho%hu%hx%hX", u, u, u, u); printf ("%hn", hn); - printf ("%hf", d); /* { dg-warning "11:length" "bad use of %h" } */ - printf ("%he", d); /* { dg-warning "11:length" "bad use of %h" } */ - printf ("%hE", d); /* { dg-warning "11:length" "bad use of %h" } */ - printf ("%hg", d); /* { dg-warning "11:length" "bad use of %h" } */ - printf ("%hG", d); /* { dg-warning "11:length" "bad use of %h" } */ - printf ("%hc", i); /* { dg-warning "11:length" "bad use of %h" } */ - printf ("%hs", s); /* { dg-warning "11:length" "bad use of %h" } */ - printf ("%hp", p); /* { dg-warning "11:length" "bad use of %h" } */ - printf ("%h"); /* { dg-warning "11:conversion lacks type" "bare %h" } */ - printf ("%h."); /* { dg-warning "11:conversion" "bogus %h." } */ - printf ("%ld%li%lo%lu%lx%lX", l, l, ul, ul, ul, ul); - printf ("%ln", ln); - printf ("%lf", d); /* { dg-warning "11:length|C" "bad use of %l" } */ - printf ("%le", d); /* { dg-warning "11:length|C" "bad use of %l" } */ - printf ("%lE", d); /* { dg-warning "11:length|C" "bad use of %l" } */ - printf ("%lg", d); /* { dg-warning "11:length|C" "bad use of %l" } */ - printf ("%lG", d); /* { dg-warning "11:length|C" "bad use of %l" } */ - printf ("%lp", p); /* { dg-warning "11:length|C" "bad use of %l" } */ + printf (" %hf", d); /* { dg-warning "15:length" "bad use of %h" } */ + printf (" %he", d); /* { dg-warning "15:length" "bad use of %h" } */ + printf (" %hE", d); /* { dg-warning "15:length" "bad use of %h" } */ + printf (" %hg", d); /* { dg-warning "15:length" "bad use of %h" } */ + printf (" %hG", d); /* { dg-warning "15:length" "bad use of %h" } */ + printf (" %hc", i); /* { dg-warning "15:length" "bad use of %h" } */ + printf (" %hs", s); /* { dg-warning "15:length" "bad use of %h" } */ + printf (" %hp", p); /* { dg-warning "15:length" "bad use of %h" } */ + printf (" %h"); /* { dg-warning "14:conversion lacks type" "bare %h" } */ + printf (" %h."); /* { dg-warning "15:conversion" "bogus %h." } */ + printf (" %ld%li%lo%lu%lx%lX", l, l, ul, ul, ul, ul); + printf (" %ln", ln); + printf (" %lf", d); /* { dg-warning "15:length|C" "bad use of %l" } */ + printf (" %le", d); /* { dg-warning "15:length|C" "bad use of %l" } */ + printf (" %lE", d); /* { dg-warning "15:length|C" "bad use of %l" } */ + printf (" %lg", d); /* { dg-warning "15:length|C" "bad use of %l" } */ + printf (" %lG", d); /* { dg-warning "15:length|C" "bad use of %l" } */ + printf (" %lp", p); /* { dg-warning "15:length|C" "bad use of %l" } */ /* These next two were added in C94, but should be objected to in C90. For the first one, GCC has wanted wchar_t instead of the correct C94 and C99 wint_t. */ - printf ("%lc", lc); /* { dg-warning "11:length|C" "C90 bad use of %l" } */ - printf ("%ls", ls); /* { dg-warning "11:length|C" "C90 bad use of %l" } */ + printf ("%lc", lc); /* { dg-warning "14:length|C" "C90 bad use of %l" } */ + printf ("%ls", ls); /* { dg-warning "14:length|C" "C90 bad use of %l" } */ /* These uses of %L are legitimate, though GCC has wrongly warned for them in the past. */ @@ -98,63 +105,63 @@ foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p, /* These next six are accepted by GCC as referring to long long, but -pedantic correctly warns. */ - printf ("%Ld", ll); /* { dg-warning "11:does not support" "bad use of %L" } */ - printf ("%Li", ll); /* { dg-warning "11:does not support" "bad use of %L" } */ - printf ("%Lo", ull); /* { dg-warning "11:does not support" "bad use of %L" } */ - printf ("%Lu", ull); /* { dg-warning "11:does not support" "bad use of %L" } */ - printf ("%Lx", ull); /* { dg-warning "11:does not support" "bad use of %L" } */ - printf ("%LX", ull); /* { dg-warning "11:does not support" "bad use of %L" } */ - printf ("%Lc", i); /* { dg-warning "11:length" "bad use of %L" } */ - printf ("%Ls", s); /* { dg-warning "11:length" "bad use of %L" } */ - printf ("%Lp", p); /* { dg-warning "11:length" "bad use of %L" } */ - printf ("%Ln", n); /* { dg-warning "11:length" "bad use of %L" } */ + printf ("%Ld", ll); /* { dg-warning "14:does not support" "bad use of %L" } */ + printf ("%Li", ll); /* { dg-warning "14:does not support" "bad use of %L" } */ + printf ("%Lo", ull); /* { dg-warning "14:does not support" "bad use of %L" } */ + printf ("%Lu", ull); /* { dg-warning "14:does not support" "bad use of %L" } */ + printf ("%Lx", ull); /* { dg-warning "14:does not support" "bad use of %L" } */ + printf ("%LX", ull); /* { dg-warning "14:does not support" "bad use of %L" } */ + printf ("%Lc", i); /* { dg-warning "14:length" "bad use of %L" } */ + printf ("%Ls", s); /* { dg-warning "14:length" "bad use of %L" } */ + printf ("%Lp", p); /* { dg-warning "14:length" "bad use of %L" } */ + printf ("%Ln", n); /* { dg-warning "14:length" "bad use of %L" } */ /* Valid uses of each bare conversion. */ printf ("%d%i%o%u%x%X%f%e%E%g%G%c%s%p%n%%", i, i, u, u, u, u, d, d, d, d, d, i, s, p, n); /* Uses of the - flag (valid on all non-%, non-n conversions). */ printf ("%-d%-i%-o%-u%-x%-X%-f%-e%-E%-g%-G%-c%-s%-p", i, i, u, u, u, u, d, d, d, d, d, i, s, p); - printf ("%-n", n); /* { dg-warning "11:flag" "bad use of %-n" } */ + printf ("%-n", n); /* { dg-warning "14:flag" "bad use of %-n" } */ /* Uses of the + flag (valid on signed conversions only). */ printf ("%+d%+i%+f%+e%+E%+g%+G\n", i, i, d, d, d, d, d); - printf ("%+o", u); /* { dg-warning "11:flag" "bad use of + flag" } */ - printf ("%+u", u); /* { dg-warning "11:flag" "bad use of + flag" } */ - printf ("%+x", u); /* { dg-warning "11:flag" "bad use of + flag" } */ - printf ("%+X", u); /* { dg-warning "11:flag" "bad use of + flag" } */ - printf ("%+c", i); /* { dg-warning "11:flag" "bad use of + flag" } */ - printf ("%+s", s); /* { dg-warning "11:flag" "bad use of + flag" } */ - printf ("%+p", p); /* { dg-warning "11:flag" "bad use of + flag" } */ - printf ("%+n", n); /* { dg-warning "11:flag" "bad use of + flag" } */ + printf ("%+o", u); /* { dg-warning "14:flag" "bad use of + flag" } */ + printf ("%+u", u); /* { dg-warning "14:flag" "bad use of + flag" } */ + printf ("%+x", u); /* { dg-warning "14:flag" "bad use of + flag" } */ + printf ("%+X", u); /* { dg-warning "14:flag" "bad use of + flag" } */ + printf ("%+c", i); /* { dg-warning "14:flag" "bad use of + flag" } */ + printf ("%+s", s); /* { dg-warning "14:flag" "bad use of + flag" } */ + printf ("%+p", p); /* { dg-warning "14:flag" "bad use of + flag" } */ + printf ("%+n", n); /* { dg-warning "14:flag" "bad use of + flag" } */ /* Uses of the space flag (valid on signed conversions only, and ignored with +). */ printf ("% +d", i); /* { dg-warning "11:use of both|ignored" "use of space and + flags" } */ printf ("%+ d", i); /* { dg-warning "11:use of both|ignored" "use of space and + flags" } */ printf ("% d% i% f% e% E% g% G\n", i, i, d, d, d, d, d); - printf ("% o", u); /* { dg-warning "11:flag" "bad use of space flag" } */ - printf ("% u", u); /* { dg-warning "11:flag" "bad use of space flag" } */ - printf ("% x", u); /* { dg-warning "11:flag" "bad use of space flag" } */ - printf ("% X", u); /* { dg-warning "11:flag" "bad use of space flag" } */ - printf ("% c", i); /* { dg-warning "11:flag" "bad use of space flag" } */ - printf ("% s", s); /* { dg-warning "11:flag" "bad use of space flag" } */ - printf ("% p", p); /* { dg-warning "11:flag" "bad use of space flag" } */ - printf ("% n", n); /* { dg-warning "11:flag" "bad use of space flag" } */ + printf ("% o", u); /* { dg-warning "14:flag" "bad use of space flag" } */ + printf ("% u", u); /* { dg-warning "14:flag" "bad use of space flag" } */ + printf ("% x", u); /* { dg-warning "14:flag" "bad use of space flag" } */ + printf ("% X", u); /* { dg-warning "14:flag" "bad use of space flag" } */ + printf ("% c", i); /* { dg-warning "14:flag" "bad use of space flag" } */ + printf ("% s", s); /* { dg-warning "14:flag" "bad use of space flag" } */ + printf ("% p", p); /* { dg-warning "14:flag" "bad use of space flag" } */ + printf ("% n", n); /* { dg-warning "14:flag" "bad use of space flag" } */ /* Uses of the # flag. */ printf ("%#o%#x%#X%#e%#E%#f%#g%#G", u, u, u, d, d, d, d, d); - printf ("%#d", i); /* { dg-warning "11:flag" "bad use of # flag" } */ - printf ("%#i", i); /* { dg-warning "11:flag" "bad use of # flag" } */ - printf ("%#u", u); /* { dg-warning "11:flag" "bad use of # flag" } */ - printf ("%#c", i); /* { dg-warning "11:flag" "bad use of # flag" } */ - printf ("%#s", s); /* { dg-warning "11:flag" "bad use of # flag" } */ - printf ("%#p", p); /* { dg-warning "11:flag" "bad use of # flag" } */ - printf ("%#n", n); /* { dg-warning "11:flag" "bad use of # flag" } */ + printf ("%#d", i); /* { dg-warning "14:flag" "bad use of # flag" } */ + printf ("%#i", i); /* { dg-warning "14:flag" "bad use of # flag" } */ + printf ("%#u", u); /* { dg-warning "14:flag" "bad use of # flag" } */ + printf ("%#c", i); /* { dg-warning "14:flag" "bad use of # flag" } */ + printf ("%#s", s); /* { dg-warning "14:flag" "bad use of # flag" } */ + printf ("%#p", p); /* { dg-warning "14:flag" "bad use of # flag" } */ + printf ("%#n", n); /* { dg-warning "14:flag" "bad use of # flag" } */ /* Uses of the 0 flag. */ printf ("%08d%08i%08o%08u%08x%08X%08e%08E%08f%08g%08G", i, i, u, u, u, u, d, d, d, d, d); - printf ("%0c", i); /* { dg-warning "11:flag" "bad use of 0 flag" } */ - printf ("%0s", s); /* { dg-warning "11:flag" "bad use of 0 flag" } */ - printf ("%0p", p); /* { dg-warning "11:flag" "bad use of 0 flag" } */ - printf ("%0n", n); /* { dg-warning "11:flag" "bad use of 0 flag" } */ + printf ("%0c", i); /* { dg-warning "14:flag" "bad use of 0 flag" } */ + printf ("%0s", s); /* { dg-warning "14:flag" "bad use of 0 flag" } */ + printf ("%0p", p); /* { dg-warning "14:flag" "bad use of 0 flag" } */ + printf ("%0n", n); /* { dg-warning "14:flag" "bad use of 0 flag" } */ /* 0 flag ignored with precision for certain types, not others. */ printf ("%08.5d", i); /* { dg-warning "11:ignored" "0 flag ignored with precision" } */ printf ("%08.5i", i); /* { dg-warning "11:ignored" "0 flag ignored with precision" } */ @@ -176,13 +183,13 @@ foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p, printf ("%-08g", d); /* { dg-warning "11:flags|ignored" "0 flag ignored with - flag" } */ printf ("%-08G", d); /* { dg-warning "11:flags|ignored" "0 flag ignored with - flag" } */ /* Various tests of bad argument types. */ - printf ("%d", l); /* { dg-warning "11:format" "bad argument types" } */ - printf ("%*.*d", l, i2, i); /* { dg-warning "11:field" "bad * argument types" } */ - printf ("%*.*d", i1, l, i); /* { dg-warning "11:field" "bad * argument types" } */ - printf ("%ld", i); /* { dg-warning "11:format" "bad argument types" } */ - printf ("%s", n); /* { dg-warning "11:format" "bad argument types" } */ - printf ("%p", i); /* { dg-warning "11:format" "bad argument types" } */ - printf ("%n", p); /* { dg-warning "11:format" "bad argument types" } */ + printf ("%d", l); /* { dg-warning "13:format" "bad argument types" } */ + printf ("%*.*d", l, i2, i); /* { dg-warning "13:field" "bad * argument types" } */ + printf ("%*.*d", i1, l, i); /* { dg-warning "15:field" "bad * argument types" } */ + printf ("%ld", i); /* { dg-warning "14:format" "bad argument types" } */ + printf ("%s", n); /* { dg-warning "13:format" "bad argument types" } */ + printf ("%p", i); /* { dg-warning "13:format" "bad argument types" } */ + printf ("%n", p); /* { dg-warning "13:format" "bad argument types" } */ /* With -pedantic, we want some further checks for pointer targets: %p should allow only pointers to void (possibly qualified) and to character types (possibly qualified), but not function pointers @@ -196,9 +203,9 @@ foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p, char * or unsigned char * being passed to %hhn, even if strictly legitimate by the standard.) */ - printf ("%p", foo); /* { dg-warning "11:format" "bad argument types" } */ - printf ("%n", un); /* { dg-warning "11:format" "bad argument types" } */ - printf ("%p", n); /* { dg-warning "11:format" "bad argument types" } */ + printf ("%p", foo); /* { dg-warning "13:format" "bad argument types" } */ + printf ("%n", un); /* { dg-warning "13:format" "bad argument types" } */ + printf ("%p", n); /* { dg-warning "13:format" "bad argument types" } */ /* Allow character pointers with %p. */ printf ("%p%p%p%p", s, ss, us, css); /* %s allows any character type. */ @@ -207,7 +214,7 @@ foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p, and seems useful to keep, even if some standard versions might be read to permit it. */ - printf ("%s", p); /* { dg-warning "11:format" "bad argument types" } */ + printf ("%s", p); /* { dg-warning "13:format" "bad argument types" } */ /* The historical behavior is to allow signed / unsigned types interchangeably as arguments. For values representable in both types, such usage may be correct. For now preserve the behavior of GCC @@ -220,18 +227,22 @@ foo (int i, int i1, int i2, unsigned int u, double d, char *s, void *p, */ printf ("%*.*d", u1, u2, i); /* Wrong number of arguments. */ - printf ("%d%d", i); /* { dg-warning "11:matching" "wrong number of args" } */ + printf ("%d%d", i); /* { dg-warning "15:matching" "wrong number of args" } */ printf ("%d", i, i); /* { dg-warning "11:arguments" "wrong number of args" } */ /* Miscellaneous bogus constructions. */ printf (""); /* { dg-warning "11:zero-length" "warning for empty format" } */ - printf ("\0"); /* { dg-warning "11:embedded" "warning for embedded NUL" } */ - printf ("%d\0", i); /* { dg-warning "11:embedded" "warning for embedded NUL" } */ - printf ("%d\0%d", i, i); /* { dg-warning "11:embedded|too many" "warning for embedded NUL" } */ + printf ("\0"); /* { dg-warning "12:embedded" "warning for embedded NUL" } */ + printf ("%d\0", i); /* { dg-warning "14:embedded" "warning for embedded NUL" } */ + printf ("%d\0%d", i, i); /* { dg-warning "embedded|too many" "warning for embedded NUL" } */ printf (NULL); /* { dg-warning "3:null" "null format string warning" } */ - printf ("%"); /* { dg-warning "11:trailing" "trailing % warning" } */ - printf ("%++d", i); /* { dg-warning "11:repeated" "repeated flag warning" } */ + printf ("%"); /* { dg-warning "12:trailing" "trailing % warning" } */ + printf ("%++d", i); /* { dg-warning "14:repeated" "repeated flag warning" } */ printf ("%n", cn); /* { dg-warning "3:constant" "%n with const" } */ printf ((const char *)L"foo"); /* { dg-warning "25:wide" "wide string" } */ printf ("%n", (int *)0); /* { dg-warning "3:null" "%n with NULL" } */ printf ("%s", (char *)0); /* { dg-warning "3:null" "%s with NULL" } */ + /* Test for correct column locations within strings with embedded + escape sequences. */ + printf ("\\\a\n \"\t%5n\n", n); /* { dg-warning "25:width" "width with %n" } */ + printf ("\\a\\n%5n\n", n); /* { dg-warning "20:width" "width with %n" } */ } |