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 { 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 *ip, unsigned int *uip, short int *hp, unsigned short int *uhp,
|
14 |
|
|
signed char *hhp, unsigned char *uhhp, long int *lp,
|
15 |
|
|
unsigned long int *ulp, float *fp, double *dp, long double *ldp, char *s,
|
16 |
|
|
void **pp, int *n, long long *llp, unsigned long long *ullp, wchar_t *ls,
|
17 |
|
|
short int *hn, signed char *hhn, long int *ln, long long int *lln,
|
18 |
|
|
intmax_t *jp, uintmax_t *ujp, intmax_t *jn, size_t *zp,
|
19 |
|
|
signed_size_t *szp, signed_size_t *zn, ptrdiff_t *tp,
|
20 |
|
|
unsigned_ptrdiff_t *utp, ptrdiff_t *tn)
|
21 |
|
|
{
|
22 |
|
|
/* See ISO/IEC 9899:1999 (E) subclause 7.19.6.2 (pages 281-288).
|
23 |
|
|
We do not repeat here most of the checks for correct C90 formats
|
24 |
|
|
or completely broken formats.
|
25 |
|
|
*/
|
26 |
|
|
/* Valid, invalid and silly assignment-suppression
|
27 |
|
|
and width constructions.
|
28 |
|
|
*/
|
29 |
|
|
scanf ("%*d%*i%*o%*u%*x%*X%*e%*E%*f%*g%*G%*s%*[abc]%*c%*p");
|
30 |
|
|
scanf ("%*2d%*8s%*3c");
|
31 |
|
|
scanf ("%*n", n); /* { dg-warning "suppress" "suppression of %n" } */
|
32 |
|
|
scanf ("%*hd"); /* { dg-warning "together" "suppression with length" } */
|
33 |
|
|
scanf ("%2d%3i%4o%5u%6x%7X%10e%11E%12f%14g%15G%16s%3[abc]%4c%5p",
|
34 |
|
|
ip, ip, uip, uip, uip, uip, fp, fp, fp, fp, fp,
|
35 |
|
|
s, s, s, pp);
|
36 |
|
|
scanf ("%0d", ip); /* { dg-warning "width" "warning for zero width" } */
|
37 |
|
|
scanf ("%3n", n); /* { dg-warning "width" "width with %n" } */
|
38 |
|
|
/* Valid and invalid %h, %hh, %l, %j, %z, %t, %L constructions. */
|
39 |
|
|
scanf ("%hd%hi%ho%hu%hx%hX%hn", hp, hp, uhp, uhp, uhp, uhp, hn);
|
40 |
|
|
scanf ("%he", fp); /* { dg-warning "length" "bad use of %h" } */
|
41 |
|
|
scanf ("%hE", fp); /* { dg-warning "length" "bad use of %h" } */
|
42 |
|
|
scanf ("%hf", fp); /* { dg-warning "length" "bad use of %h" } */
|
43 |
|
|
scanf ("%hg", fp); /* { dg-warning "length" "bad use of %h" } */
|
44 |
|
|
scanf ("%hG", fp); /* { dg-warning "length" "bad use of %h" } */
|
45 |
|
|
scanf ("%hs", hp);
|
46 |
|
|
scanf ("%h[ac]", s); /* { dg-warning "length" "bad use of %h" } */
|
47 |
|
|
scanf ("%hc", (short *)s);
|
48 |
|
|
scanf ("%hp", pp); /* { dg-warning "length" "bad use of %h" } */
|
49 |
|
|
scanf ("%hhd", hhp); /* { dg-warning "unknown|format" "%hh is unsupported" } */
|
50 |
|
|
scanf ("%ld%li%lo%lu%lx%lX%ln", lp, lp, ulp, ulp, ulp, ulp, ln);
|
51 |
|
|
scanf ("%le%lE%lf%lg%lG", dp, dp, dp, dp, dp);
|
52 |
|
|
scanf ("%lp", pp); /* { dg-warning "length" "bad use of %l" } */
|
53 |
|
|
scanf ("%ls", ls);
|
54 |
|
|
scanf ("%l[ac]", ls);
|
55 |
|
|
scanf ("%lc", ls);
|
56 |
|
|
scanf ("%jd", jp); /* { dg-warning "unknown|format" "%j not supported" } */
|
57 |
|
|
scanf ("%zd", zp); /* { dg-warning "unknown|format" "%z not supported" } */
|
58 |
|
|
scanf ("%td", tp); /* { dg-warning "unknown|format" "%t not supported" } */
|
59 |
|
|
scanf ("%Lf", llp); /* { dg-warning "unknown|format" "bad use of %L is not supported" } */
|
60 |
|
|
/* Valid uses of each bare conversion. */
|
61 |
|
|
scanf ("%d%i%o%u%x%X%e%E%f%g%G%s%[abc]%c%p%n%%", ip, ip, uip, uip, uip,
|
62 |
|
|
uip, fp, fp, fp, fp, fp, s, s, s, pp, n);
|
63 |
|
|
}
|