1 |
298 |
jeremybenn |
/* Test for printf formats. Formats using C99 features, including cases
|
2 |
|
|
where C99 specifies some aspect of the format to be ignored or where
|
3 |
|
|
the behavior is undefined.
|
4 |
|
|
*/
|
5 |
|
|
/* Origin: Joseph Myers <jsm28@cam.ac.uk> */
|
6 |
|
|
/* { dg-do compile { target { *-*-mingw* } } } */
|
7 |
|
|
/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */
|
8 |
|
|
|
9 |
|
|
#define USE_SYSTEM_FORMATS
|
10 |
|
|
#include "format.h"
|
11 |
|
|
|
12 |
|
|
void
|
13 |
|
|
foo (int i, unsigned int u, double d, char *s, void *p, int *n,
|
14 |
|
|
long double ld, wint_t lc, wchar_t *ls, long long int ll,
|
15 |
|
|
unsigned long long int ull, signed char *ss, unsigned char *us,
|
16 |
|
|
long long int *lln, intmax_t j, uintmax_t uj, intmax_t *jn,
|
17 |
|
|
size_t z, signed_size_t sz, signed_size_t *zn,
|
18 |
|
|
ptrdiff_t t, ptrdiff_t *tn)
|
19 |
|
|
{
|
20 |
|
|
/* See ISO/IEC 9899:1999 (E) subclause 7.19.6.1 (pages 273-281).
|
21 |
|
|
We do not repeat here most of the checks for correct C90 formats
|
22 |
|
|
or completely broken formats.
|
23 |
|
|
*/
|
24 |
|
|
/* Valid and invalid %h, %hh, %l, %j, %z, %t, %L constructions. */
|
25 |
|
|
printf ("%hf", d); /* { dg-warning "length" "bad use of %h" } */
|
26 |
|
|
printf ("%hF", d); /* { dg-warning "unknown|format" "bad use of %hF" } */
|
27 |
|
|
printf ("%he", d); /* { dg-warning "length" "bad use of %h" } */
|
28 |
|
|
printf ("%hE", d); /* { dg-warning "length" "bad use of %h" } */
|
29 |
|
|
printf ("%hg", d); /* { dg-warning "length" "bad use of %h" } */
|
30 |
|
|
printf ("%hG", d); /* { dg-warning "length" "bad use of %h" } */
|
31 |
|
|
printf ("%ha", d); /* { dg-warning "unknown|format" "bad use of %ha" } */
|
32 |
|
|
printf ("%hA", d); /* { dg-warning "unknown|format" "bad use of %hA" } */
|
33 |
|
|
printf ("%hc", i);
|
34 |
|
|
printf ("%hs", (short *)s);
|
35 |
|
|
printf ("%hp", p); /* { dg-warning "length" "bad use of %h" } */
|
36 |
|
|
printf ("%lc", lc);
|
37 |
|
|
printf ("%ls", ls);
|
38 |
|
|
printf ("%lp", p); /* { dg-warning "length|C" "bad use of %l" } */
|
39 |
|
|
/* Valid uses of each bare conversion. */
|
40 |
|
|
printf ("%d%i%o%u%x%X%f%e%E%g%G%c%s%p%n%%", i, i, u, u, u, u,
|
41 |
|
|
d, d, d, d, d, i, s, p, n);
|
42 |
|
|
/* Uses of the - flag (valid on all non-%, non-n conversions). */
|
43 |
|
|
printf ("%-d%-i%-o%-u%-x%-X%-f%-e%-E%-g%-G%-c%-s%-p", i, i,
|
44 |
|
|
u, u, u, u, d, d, d, d, d, i, s, p);
|
45 |
|
|
printf ("%-n", n); /* { dg-warning "flag" "bad use of %-n" } */
|
46 |
|
|
/* Uses of the + flag (valid on signed conversions only). */
|
47 |
|
|
printf ("%+d%+i%+f%+e%+E%+g%+G\n", i, i, d, d, d, d, d);
|
48 |
|
|
printf ("%+o", u); /* { dg-warning "flag" "bad use of + flag" } */
|
49 |
|
|
printf ("%+u", u); /* { dg-warning "flag" "bad use of + flag" } */
|
50 |
|
|
printf ("%+x", u); /* { dg-warning "flag" "bad use of + flag" } */
|
51 |
|
|
printf ("%+X", u); /* { dg-warning "flag" "bad use of + flag" } */
|
52 |
|
|
printf ("%+c", i); /* { dg-warning "flag" "bad use of + flag" } */
|
53 |
|
|
printf ("%+s", s); /* { dg-warning "flag" "bad use of + flag" } */
|
54 |
|
|
printf ("%+p", p); /* { dg-warning "flag" "bad use of + flag" } */
|
55 |
|
|
printf ("%+n", n); /* { dg-warning "flag" "bad use of + flag" } */
|
56 |
|
|
/* Uses of the space flag (valid on signed conversions only, and ignored
|
57 |
|
|
with +).
|
58 |
|
|
*/
|
59 |
|
|
printf ("% +d", i); /* { dg-warning "use of both|ignored" "use of space and + flags" } */
|
60 |
|
|
printf ("%+ d", i); /* { dg-warning "use of both|ignored" "use of space and + flags" } */
|
61 |
|
|
printf ("% d% i% f% e% E% g% G\n", i, i, d, d, d, d, d);
|
62 |
|
|
printf ("% o", u); /* { dg-warning "flag" "bad use of space flag" } */
|
63 |
|
|
printf ("% u", u); /* { dg-warning "flag" "bad use of space flag" } */
|
64 |
|
|
printf ("% x", u); /* { dg-warning "flag" "bad use of space flag" } */
|
65 |
|
|
printf ("% X", u); /* { dg-warning "flag" "bad use of space flag" } */
|
66 |
|
|
printf ("% c", i); /* { dg-warning "flag" "bad use of space flag" } */
|
67 |
|
|
printf ("% s", s); /* { dg-warning "flag" "bad use of space flag" } */
|
68 |
|
|
printf ("% p", p); /* { dg-warning "flag" "bad use of space flag" } */
|
69 |
|
|
printf ("% n", n); /* { dg-warning "flag" "bad use of space flag" } */
|
70 |
|
|
/* Uses of the # flag. */
|
71 |
|
|
printf ("%#o%#x%#X%#e%#E%#f%#g%#G", u, u, u, d, d, d,
|
72 |
|
|
d, d);
|
73 |
|
|
printf ("%#d", i); /* { dg-warning "flag" "bad use of # flag" } */
|
74 |
|
|
printf ("%#i", i); /* { dg-warning "flag" "bad use of # flag" } */
|
75 |
|
|
printf ("%#u", u); /* { dg-warning "flag" "bad use of # flag" } */
|
76 |
|
|
printf ("%#c", i); /* { dg-warning "flag" "bad use of # flag" } */
|
77 |
|
|
printf ("%#s", s); /* { dg-warning "flag" "bad use of # flag" } */
|
78 |
|
|
printf ("%#p", p); /* { dg-warning "flag" "bad use of # flag" } */
|
79 |
|
|
printf ("%#n", n); /* { dg-warning "flag" "bad use of # flag" } */
|
80 |
|
|
/* Uses of the 0 flag. */
|
81 |
|
|
printf ("%08d%08i%08o%08u%08x%08X%08e%08E%08f%08g%08G", i, i,
|
82 |
|
|
u, u, u, u, d, d, d, d, d);
|
83 |
|
|
printf ("%0c", i); /* { dg-warning "flag" "bad use of 0 flag" } */
|
84 |
|
|
printf ("%0s", s); /* { dg-warning "flag" "bad use of 0 flag" } */
|
85 |
|
|
printf ("%0p", p); /* { dg-warning "flag" "bad use of 0 flag" } */
|
86 |
|
|
printf ("%0n", n); /* { dg-warning "flag" "bad use of 0 flag" } */
|
87 |
|
|
/* 0 flag ignored with - flag. */
|
88 |
|
|
printf ("%-08d", i); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
|
89 |
|
|
printf ("%-08i", i); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
|
90 |
|
|
printf ("%-08o", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
|
91 |
|
|
printf ("%-08u", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
|
92 |
|
|
printf ("%-08x", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
|
93 |
|
|
printf ("%-08X", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
|
94 |
|
|
printf ("%-08e", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
|
95 |
|
|
printf ("%-08E", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
|
96 |
|
|
printf ("%-08f", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
|
97 |
|
|
printf ("%-08F", d); /* { dg-warning "unknown|format" "0 flag ignored with - flag" } */
|
98 |
|
|
printf ("%-08g", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
|
99 |
|
|
printf ("%-08G", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */
|
100 |
|
|
printf ("%-08a", d); /* { dg-warning "unknown|format" "0 flag ignored with - flag" } */
|
101 |
|
|
printf ("%-08A", d); /* { dg-warning "unknown|format" "0 flag ignored with - flag" } */
|
102 |
|
|
/* Various tests of bad argument types. Mostly covered in c90-printf-1.c;
|
103 |
|
|
here just test for pointer target sign with %hhn. (Probably allowed
|
104 |
|
|
by the standard, but a bad idea, so GCC should diagnose if what
|
105 |
|
|
is used is not signed char *.)
|
106 |
|
|
*/
|
107 |
|
|
printf ("%hhn", s); /* { dg-warning "unknown|format" "%hhn is unsupported" } */
|
108 |
|
|
printf ("%hhn", us); /* { dg-warning "unknown|format" "%hhn is unsupported" } */
|
109 |
|
|
}
|