OSDN Git Service

* gcc.dg/testsuite/c++98.c,c++98-pedantic.c,c89.c,c89-pedantic.c,
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / c90-printf-2.c
1 /* Test for printf formats.  Formats using C99 features should be rejected
2    outside of C99 mode.
3 */
4 /* Origin: Joseph Myers <jsm28@cam.ac.uk> */
5 /* { dg-do compile } */
6 /* { dg-options "-std=iso9899:1990 -pedantic -Wformat" } */
7
8 typedef __SIZE_TYPE__ size_t;
9 typedef __PTRDIFF_TYPE__ ptrdiff_t;
10
11 __extension__ typedef long long int llong;
12
13 /* This next definition is a kludge.  When GCC has a <stdint.h> it
14    should be used.
15 */
16 /* (T *) if E is zero, (void *) otherwise.  */
17 #define type_if_not(T, E) __typeof__(0 ? (T *)0 : (void *)(E))
18
19 /* (T *) if E is nonzero, (void *) otherwise.  */
20 #define type_if(T, E) type_if_not(T, !(E))
21
22 /* Combine pointer types, all but one (void *).  */
23 #define type_comb2(T1, T2) __typeof__(0 ? (T1)0 : (T2)0)
24 #define type_comb3(T1, T2, T3) type_comb2(T1, type_comb2(T2, T3))
25
26 #define maybe_int_ptr type_if(int, sizeof(int) == sizeof(llong))
27 #define maybe_long_ptr type_if(long, sizeof(long) == sizeof(llong) && sizeof(long) > sizeof(int))
28 #define maybe_long_long_ptr type_if(llong, sizeof(llong) > sizeof(long))
29
30 #define intmax_type_ptr type_comb3(maybe_int_ptr, maybe_long_ptr, maybe_long_long_ptr)
31
32 typedef __typeof__(*((intmax_type_ptr)0)) intmax_t;
33
34 extern int printf (const char *, ...);
35
36 void
37 foo (int i, double d, llong ll, intmax_t j, size_t z, ptrdiff_t t)
38 {
39   /* Some tests already in c90-printf-1.c, e.g. %lf.  */
40   /* The widths hh, ll, j, z, t are new.  */
41   printf ("%hhd", i); /* { dg-warning "length|C" "%hh in C90" } */
42   printf ("%lld", ll); /* { dg-warning "length|C" "%ll in C90" } */
43   printf ("%jd", j); /* { dg-warning "length|C" "%j in C90" } */
44   printf ("%zu", z); /* { dg-warning "length|C" "%z in C90" } */
45   printf ("%td", t); /* { dg-warning "length|C" "%t in C90" } */
46   /* The formats F, a, A are new.  */
47   printf ("%F", d); /* { dg-warning "C" "%F in C90" } */
48   printf ("%a", d); /* { dg-warning "C" "%a in C90" } */
49   printf ("%A", d); /* { dg-warning "C" "%A in C90" } */
50 }