OSDN Git Service

6e2cb10063bba13f53a37960aad6658276a02e0e
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / format / ms_c90-scanf-1.c
1 /* Test for scanf formats.  Formats using C90 features, including cases
2    where C90 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:1990 -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      long int *lp, unsigned long int *ulp, float *fp, double *dp,
15      long double *ldp, char *s, signed char *ss, unsigned char *us,
16      void **pp, int *n, llong *llp, ullong *ullp, wchar_t *ls,
17      const int *cip, const int *cn, const char *cs, const void **ppc,
18      void *const *pcp, short int *hn, long int *ln, void *p, char **sp,
19      volatile void *ppv)
20 {
21   /* See ISO/IEC 9899:1990 (E) subclause 7.9.6.2 (pages 134-138).  */
22   /* Basic sanity checks for the different components of a format.  */
23   scanf ("%d", ip);
24   scanf ("%*d");
25   scanf ("%3d", ip);
26   scanf ("%hd", hp);
27   scanf ("%3ld", lp);
28   scanf ("%*3d");
29   scanf ("%d %ld", ip, lp);
30   /* Valid and invalid %% constructions.  */
31   scanf ("%%");
32   scanf ("%*%"); /* { dg-warning "format" "bogus %%" } */
33   scanf ("%*%\n"); /* { dg-warning "format" "bogus %%" } */
34   scanf ("%4%"); /* { dg-warning "format" "bogus %%" } */
35   scanf ("%4%\n"); /* { dg-warning "format" "bogus %%" } */
36   scanf ("%h%"); /* { dg-warning "format" "bogus %%" } */
37   scanf ("%h%\n"); /* { dg-warning "format" "bogus %%" } */
38   /* Valid, invalid and silly assignment-suppression constructions.  */
39   scanf ("%*d%*i%*o%*u%*x%*X%*e%*E%*f%*g%*G%*s%*[abc]%*c%*p");
40   scanf ("%*2d%*8s%*3c");
41   scanf ("%*n", n); /* { dg-warning "suppress" "suppression of %n" } */
42   scanf ("%*hd"); /* { dg-warning "together" "suppression with length" } */
43   /* Valid, invalid and silly width constructions.  */
44   scanf ("%2d%3i%4o%5u%6x%7X%8e%9E%10f%11g%12G%13s%14[abc]%15c%16p",
45          ip, ip, uip, uip, uip, uip, fp, fp, fp, fp, fp, s, s, s, pp);
46   scanf ("%0d", ip); /* { dg-warning "width" "warning for zero width" } */
47   scanf ("%3n", n); /* { dg-warning "width" "width with %n" } */
48   /* Valid and invalid %h, %l, %L constructions.  */
49   scanf ("%hd%hi%ho%hu%hx%hX%hn", hp, hp, uhp, uhp, uhp, uhp, hn);
50   scanf ("%he", fp); /* { dg-warning "length" "bad use of %h" } */
51   scanf ("%hE", fp); /* { dg-warning "length" "bad use of %h" } */
52   scanf ("%hf", fp); /* { dg-warning "length" "bad use of %h" } */
53   scanf ("%hg", fp); /* { dg-warning "length" "bad use of %h" } */
54   scanf ("%hG", fp); /* { dg-warning "length" "bad use of %h" } */
55   scanf ("%hs", hp);
56   scanf ("%h[ac]", s); /* { dg-warning "length" "bad use of %h" } */
57   scanf ("%hc", hp);
58   scanf ("%hp", pp); /* { dg-warning "length" "bad use of %h" } */
59   scanf ("%h"); /* { dg-warning "conversion lacks type" "bare %h" } */
60   scanf ("%h."); /* { dg-warning "conversion" "bogus %h" } */
61   scanf ("%ld%li%lo%lu%lx%lX%ln", lp, lp, ulp, ulp, ulp, ulp, ln);
62   scanf ("%le%lE%lf%lg%lG", dp, dp, dp, dp, dp);
63   scanf ("%lp", pp); /* { dg-warning "length" "bad use of %l" } */
64   /* These next three formats were added in C94.  */
65   scanf ("%ls", ls); /* { dg-warning "length|C" "bad use of %l" } */
66   scanf ("%l[ac]", ls); /* { dg-warning "length|C" "bad use of %l" } */
67   scanf ("%lc", ls); /* { dg-warning "length|C" "bad use of %l" } */
68   scanf ("%Ld", llp); /* { dg-warning "unknown|format" "%L is unsupported" } */
69   scanf ("%Li", llp); /* { dg-warning "unknown|format" "%L is unsupported" } */
70   scanf ("%Lo", ullp); /* { dg-warning "unknown|format" "%L is unsupported" } */
71   scanf ("%Lu", ullp); /* { dg-warning "unknown|format" "%L is unsupported" } */
72   scanf ("%Lx", ullp); /* { dg-warning "unknown|format" "%L is unsupported" } */
73   scanf ("%LX", ullp); /* { dg-warning "unknown|format" "%L is unsupported" } */
74   scanf ("%Ls", s); /* { dg-warning "unknown|format" "%L is unsupported" } */
75   scanf ("%L[ac]", s); /* { dg-warning "unknown|format" "%L is unsupported" } */
76   scanf ("%Lc", s); /* { dg-warning "unknown|format" "%L is unsupported" } */
77   scanf ("%Lp", pp); /* { dg-warning "unknown|format" "%L is unsupported" } */
78   scanf ("%Ln", n); /* { dg-warning "unknown|format" "%L is unsupported" } */
79   /* Valid uses of each bare conversion.  */
80   scanf ("%d%i%o%u%x%X%e%E%f%g%G%s%[abc]%c%p%n%%", ip, ip, uip, uip, uip,
81          uip, fp, fp, fp, fp, fp, s, s, s, pp, n);
82   /* Allow other character pointers with %s, %c, %[].  */
83   scanf ("%2s%3s%4c%5c%6[abc]%7[abc]", ss, us, ss, us, ss, us);
84   /* Further tests for %[].  */
85   scanf ("%[%d]%d", s, ip);
86   scanf ("%[^%d]%d", s, ip);
87   scanf ("%[]%d]%d", s, ip);
88   scanf ("%[^]%d]%d", s, ip);
89   scanf ("%[%d]%d", s, ip);
90   scanf ("%[]abcd", s); /* { dg-warning "no closing" "incomplete scanset" } */
91   /* Various tests of bad argument types.  Some of these are only pedantic
92      warnings.
93   */
94   scanf ("%d", lp); /* { dg-warning "format" "bad argument types" } */
95   scanf ("%d", uip); /* { dg-warning "format" "bad argument types" } */
96   scanf ("%d", pp); /* { dg-warning "format" "bad argument types" } */
97   scanf ("%p", ppc); /* { dg-warning "format" "bad argument types" } */
98   scanf ("%p", ppv); /* { dg-warning "format" "bad argument types" } */
99   scanf ("%s", n); /* { dg-warning "format" "bad argument types" } */
100   scanf ("%s", p); /* { dg-warning "format" "bad argument types" } */
101   scanf ("%p", p); /* { dg-warning "format" "bad argument types" } */
102   scanf ("%p", sp); /* { dg-warning "format" "bad argument types" } */
103   /* Tests for writing into constant values.  */
104   scanf ("%d", cip); /* { dg-warning "constant" "%d writing into const" } */
105   scanf ("%n", cn); /* { dg-warning "constant" "%n writing into const" } */
106   scanf ("%s", cs); /* { dg-warning "constant" "%s writing into const" } */
107   scanf ("%p", pcp); /* { dg-warning "constant" "%p writing into const" } */
108   /* Wrong number of arguments.  */
109   scanf ("%d%d", ip); /* { dg-warning "arguments" "wrong number of args" } */
110   scanf ("%d", ip, ip); /* { dg-warning "arguments" "wrong number of args" } */
111   /* Miscellaneous bogus constructions.  */
112   scanf (""); /* { dg-warning "zero-length" "warning for empty format" } */
113   scanf ("\0"); /* { dg-warning "embedded" "warning for embedded NUL" } */
114   scanf ("%d\0", ip); /* { dg-warning "embedded" "warning for embedded NUL" } */
115   scanf ("%d\0%d", ip, ip); /* { dg-warning "embedded|too many" "warning for embedded NUL" } */
116   scanf (NULL); /* { dg-warning "null" "null format string warning" } */
117   scanf ("%"); /* { dg-warning "trailing" "trailing % warning" } */
118   scanf ("%d", (int *)0); /* { dg-warning "null" "writing into NULL" } */
119 }