OSDN Git Service

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