1 |
689 |
jeremybenn |
/* Test for scanf 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 } */
|
7 |
|
|
/* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */
|
8 |
|
|
|
9 |
|
|
#include "format.h"
|
10 |
|
|
|
11 |
|
|
void
|
12 |
|
|
foo (int *ip, unsigned int *uip, short int *hp, unsigned short int *uhp,
|
13 |
|
|
signed char *hhp, unsigned char *uhhp, long int *lp,
|
14 |
|
|
unsigned long int *ulp, float *fp, double *dp, long double *ldp, char *s,
|
15 |
|
|
void **pp, int *n, long long *llp, unsigned long long *ullp, wchar_t *ls,
|
16 |
|
|
short int *hn, signed char *hhn, long int *ln, long long int *lln,
|
17 |
|
|
intmax_t *jp, uintmax_t *ujp, intmax_t *jn, size_t *zp,
|
18 |
|
|
signed_size_t *szp, signed_size_t *zn, ptrdiff_t *tp,
|
19 |
|
|
unsigned_ptrdiff_t *utp, ptrdiff_t *tn)
|
20 |
|
|
{
|
21 |
|
|
/* See ISO/IEC 9899:1999 (E) subclause 7.19.6.2 (pages 281-288).
|
22 |
|
|
We do not repeat here most of the checks for correct C90 formats
|
23 |
|
|
or completely broken formats.
|
24 |
|
|
*/
|
25 |
|
|
/* Valid, invalid and silly assignment-suppression
|
26 |
|
|
and width constructions.
|
27 |
|
|
*/
|
28 |
|
|
scanf ("%*d%*i%*o%*u%*x%*X%*a%*A%*e%*E%*f%*F%*g%*G%*s%*[abc]%*c%*p");
|
29 |
|
|
scanf ("%*2d%*8s%*3c");
|
30 |
|
|
scanf ("%*n", n); /* { dg-warning "suppress" "suppression of %n" } */
|
31 |
|
|
scanf ("%*hd"); /* { dg-warning "together" "suppression with length" } */
|
32 |
|
|
scanf ("%2d%3i%4o%5u%6x%7X%8a%9A%10e%11E%12f%13F%14g%15G%16s%3[abc]%4c%5p",
|
33 |
|
|
ip, ip, uip, uip, uip, uip, fp, fp, fp, fp, fp, fp, fp, fp,
|
34 |
|
|
s, s, s, pp);
|
35 |
|
|
scanf ("%0d", ip); /* { dg-warning "width" "warning for zero width" } */
|
36 |
|
|
scanf ("%3n", n); /* { dg-warning "width" "width with %n" } */
|
37 |
|
|
/* Valid and invalid %h, %hh, %l, %ll, %j, %z, %t, %L constructions. */
|
38 |
|
|
scanf ("%hd%hi%ho%hu%hx%hX%hn", hp, hp, uhp, uhp, uhp, uhp, hn);
|
39 |
|
|
scanf ("%ha", fp); /* { dg-warning "length" "bad use of %h" } */
|
40 |
|
|
scanf ("%hA", fp); /* { dg-warning "length" "bad use of %h" } */
|
41 |
|
|
scanf ("%he", fp); /* { dg-warning "length" "bad use of %h" } */
|
42 |
|
|
scanf ("%hE", fp); /* { dg-warning "length" "bad use of %h" } */
|
43 |
|
|
scanf ("%hf", fp); /* { dg-warning "length" "bad use of %h" } */
|
44 |
|
|
scanf ("%hF", fp); /* { dg-warning "length" "bad use of %h" } */
|
45 |
|
|
scanf ("%hg", fp); /* { dg-warning "length" "bad use of %h" } */
|
46 |
|
|
scanf ("%hG", fp); /* { dg-warning "length" "bad use of %h" } */
|
47 |
|
|
scanf ("%hs", s); /* { dg-warning "length" "bad use of %h" } */
|
48 |
|
|
scanf ("%h[ac]", s); /* { dg-warning "length" "bad use of %h" } */
|
49 |
|
|
scanf ("%hc", s); /* { dg-warning "length" "bad use of %h" } */
|
50 |
|
|
scanf ("%hp", pp); /* { dg-warning "length" "bad use of %h" } */
|
51 |
|
|
scanf ("%hhd%hhi%hho%hhu%hhx%hhX%hhn", hhp, hhp, uhhp, uhhp, uhhp, uhhp,
|
52 |
|
|
hhn);
|
53 |
|
|
scanf ("%hha", fp); /* { dg-warning "length" "bad use of %hh" } */
|
54 |
|
|
scanf ("%hhA", fp); /* { dg-warning "length" "bad use of %hh" } */
|
55 |
|
|
scanf ("%hhe", fp); /* { dg-warning "length" "bad use of %hh" } */
|
56 |
|
|
scanf ("%hhE", fp); /* { dg-warning "length" "bad use of %hh" } */
|
57 |
|
|
scanf ("%hhf", fp); /* { dg-warning "length" "bad use of %hh" } */
|
58 |
|
|
scanf ("%hhF", fp); /* { dg-warning "length" "bad use of %hh" } */
|
59 |
|
|
scanf ("%hhg", fp); /* { dg-warning "length" "bad use of %hh" } */
|
60 |
|
|
scanf ("%hhG", fp); /* { dg-warning "length" "bad use of %hh" } */
|
61 |
|
|
scanf ("%hhs", s); /* { dg-warning "length" "bad use of %hh" } */
|
62 |
|
|
scanf ("%hh[ac]", s); /* { dg-warning "length" "bad use of %hh" } */
|
63 |
|
|
scanf ("%hhc", s); /* { dg-warning "length" "bad use of %hh" } */
|
64 |
|
|
scanf ("%hhp", pp); /* { dg-warning "length" "bad use of %hh" } */
|
65 |
|
|
scanf ("%ld%li%lo%lu%lx%lX%ln", lp, lp, ulp, ulp, ulp, ulp, ln);
|
66 |
|
|
scanf ("%la%lA%le%lE%lf%lF%lg%lG", dp, dp, dp, dp, dp, dp, dp, dp);
|
67 |
|
|
scanf ("%lp", pp); /* { dg-warning "length" "bad use of %l" } */
|
68 |
|
|
scanf ("%ls", ls);
|
69 |
|
|
scanf ("%l[ac]", ls);
|
70 |
|
|
scanf ("%lc", ls);
|
71 |
|
|
scanf ("%lld%lli%llo%llu%llx%llX%lln", llp, llp, ullp, ullp, ullp, ullp,
|
72 |
|
|
lln);
|
73 |
|
|
scanf ("%lla", fp); /* { dg-warning "length" "bad use of %ll" } */
|
74 |
|
|
scanf ("%llA", fp); /* { dg-warning "length" "bad use of %ll" } */
|
75 |
|
|
scanf ("%lle", fp); /* { dg-warning "length" "bad use of %ll" } */
|
76 |
|
|
scanf ("%llE", fp); /* { dg-warning "length" "bad use of %ll" } */
|
77 |
|
|
scanf ("%llf", fp); /* { dg-warning "length" "bad use of %ll" } */
|
78 |
|
|
scanf ("%llF", fp); /* { dg-warning "length" "bad use of %ll" } */
|
79 |
|
|
scanf ("%llg", fp); /* { dg-warning "length" "bad use of %ll" } */
|
80 |
|
|
scanf ("%llG", fp); /* { dg-warning "length" "bad use of %ll" } */
|
81 |
|
|
scanf ("%lls", s); /* { dg-warning "length" "bad use of %ll" } */
|
82 |
|
|
scanf ("%ll[ac]", s); /* { dg-warning "length" "bad use of %ll" } */
|
83 |
|
|
scanf ("%llc", s); /* { dg-warning "length" "bad use of %ll" } */
|
84 |
|
|
scanf ("%llp", pp); /* { dg-warning "length" "bad use of %ll" } */
|
85 |
|
|
scanf ("%jd%ji%jo%ju%jx%jX%jn", jp, jp, ujp, ujp, ujp, ujp, jn); /* { dg-bogus "length" "bogus %j warning" { target *-*-* } } */
|
86 |
|
|
scanf ("%ja", fp); /* { dg-warning "length" "bad use of %j" } */
|
87 |
|
|
scanf ("%jA", fp); /* { dg-warning "length" "bad use of %j" } */
|
88 |
|
|
scanf ("%je", fp); /* { dg-warning "length" "bad use of %j" } */
|
89 |
|
|
scanf ("%jE", fp); /* { dg-warning "length" "bad use of %j" } */
|
90 |
|
|
scanf ("%jf", fp); /* { dg-warning "length" "bad use of %j" } */
|
91 |
|
|
scanf ("%jF", fp); /* { dg-warning "length" "bad use of %j" } */
|
92 |
|
|
scanf ("%jg", fp); /* { dg-warning "length" "bad use of %j" } */
|
93 |
|
|
scanf ("%jG", fp); /* { dg-warning "length" "bad use of %j" } */
|
94 |
|
|
scanf ("%js", s); /* { dg-warning "length" "bad use of %j" } */
|
95 |
|
|
scanf ("%j[ac]", s); /* { dg-warning "length" "bad use of %j" } */
|
96 |
|
|
scanf ("%jc", s); /* { dg-warning "length" "bad use of %j" } */
|
97 |
|
|
scanf ("%jp", pp); /* { dg-warning "length" "bad use of %j" } */
|
98 |
|
|
scanf ("%zd%zi%zo%zu%zx%zX%zn", szp, szp, zp, zp, zp, zp, zn);
|
99 |
|
|
scanf ("%za", fp); /* { dg-warning "length" "bad use of %z" } */
|
100 |
|
|
scanf ("%zA", fp); /* { dg-warning "length" "bad use of %z" } */
|
101 |
|
|
scanf ("%ze", fp); /* { dg-warning "length" "bad use of %z" } */
|
102 |
|
|
scanf ("%zE", fp); /* { dg-warning "length" "bad use of %z" } */
|
103 |
|
|
scanf ("%zf", fp); /* { dg-warning "length" "bad use of %z" } */
|
104 |
|
|
scanf ("%zF", fp); /* { dg-warning "length" "bad use of %z" } */
|
105 |
|
|
scanf ("%zg", fp); /* { dg-warning "length" "bad use of %z" } */
|
106 |
|
|
scanf ("%zG", fp); /* { dg-warning "length" "bad use of %z" } */
|
107 |
|
|
scanf ("%zs", s); /* { dg-warning "length" "bad use of %z" } */
|
108 |
|
|
scanf ("%z[ac]", s); /* { dg-warning "length" "bad use of %z" } */
|
109 |
|
|
scanf ("%zc", s); /* { dg-warning "length" "bad use of %z" } */
|
110 |
|
|
scanf ("%zp", pp); /* { dg-warning "length" "bad use of %z" } */
|
111 |
|
|
scanf ("%td%ti%to%tu%tx%tX%tn", tp, tp, utp, utp, utp, utp, tn);
|
112 |
|
|
scanf ("%ta", fp); /* { dg-warning "length" "bad use of %t" } */
|
113 |
|
|
scanf ("%tA", fp); /* { dg-warning "length" "bad use of %t" } */
|
114 |
|
|
scanf ("%te", fp); /* { dg-warning "length" "bad use of %t" } */
|
115 |
|
|
scanf ("%tE", fp); /* { dg-warning "length" "bad use of %t" } */
|
116 |
|
|
scanf ("%tf", fp); /* { dg-warning "length" "bad use of %t" } */
|
117 |
|
|
scanf ("%tF", fp); /* { dg-warning "length" "bad use of %t" } */
|
118 |
|
|
scanf ("%tg", fp); /* { dg-warning "length" "bad use of %t" } */
|
119 |
|
|
scanf ("%tG", fp); /* { dg-warning "length" "bad use of %t" } */
|
120 |
|
|
scanf ("%ts", s); /* { dg-warning "length" "bad use of %t" } */
|
121 |
|
|
scanf ("%t[ac]", s); /* { dg-warning "length" "bad use of %t" } */
|
122 |
|
|
scanf ("%tc", s); /* { dg-warning "length" "bad use of %t" } */
|
123 |
|
|
scanf ("%tp", pp); /* { dg-warning "length" "bad use of %t" } */
|
124 |
|
|
scanf ("%La%LA%Le%LE%Lf%LF%Lg%LG", ldp, ldp, ldp, ldp, ldp, ldp, ldp, ldp);
|
125 |
|
|
scanf ("%Ld", llp); /* { dg-warning "does not support" "bad use of %L" } */
|
126 |
|
|
scanf ("%Li", llp); /* { dg-warning "does not support" "bad use of %L" } */
|
127 |
|
|
scanf ("%Lo", ullp); /* { dg-warning "does not support" "bad use of %L" } */
|
128 |
|
|
scanf ("%Lu", ullp); /* { dg-warning "does not support" "bad use of %L" } */
|
129 |
|
|
scanf ("%Lx", ullp); /* { dg-warning "does not support" "bad use of %L" } */
|
130 |
|
|
scanf ("%LX", ullp); /* { dg-warning "does not support" "bad use of %L" } */
|
131 |
|
|
scanf ("%Ls", s); /* { dg-warning "length" "bad use of %L" } */
|
132 |
|
|
scanf ("%L[ac]", s); /* { dg-warning "length" "bad use of %L" } */
|
133 |
|
|
scanf ("%Lc", s); /* { dg-warning "length" "bad use of %L" } */
|
134 |
|
|
scanf ("%Lp", pp); /* { dg-warning "length" "bad use of %L" } */
|
135 |
|
|
scanf ("%Ln", n); /* { dg-warning "length" "bad use of %L" } */
|
136 |
|
|
/* Valid uses of each bare conversion. */
|
137 |
|
|
scanf ("%d%i%o%u%x%X%a%A%e%E%f%F%g%G%s%[abc]%c%p%n%%", ip, ip, uip, uip, uip,
|
138 |
|
|
uip, fp, fp, fp, fp, fp, fp, fp, fp, s, s, s, pp, n);
|
139 |
|
|
/* Assert that %as is not treated as an extension in C99 mode. */
|
140 |
|
|
scanf ("%as", fp);
|
141 |
|
|
scanf ("%a[", fp);
|
142 |
|
|
/* Tests for bad argument types: pointer target sign with %hh. */
|
143 |
|
|
scanf ("%hhd", uhhp); /* { dg-warning "format" "%hhd sign" } */
|
144 |
|
|
scanf ("%hhu", hhp); /* { dg-warning "format" "%hhu sign" } */
|
145 |
|
|
}
|