URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Subversion Repositories openrisc
[/] [openrisc/] [trunk/] [gnu-stable/] [gcc-4.5.1/] [gcc/] [testsuite/] [gcc.dg/] [format/] [ms_c99-printf-1.c] - Rev 826
Compare with Previous | Blame | View Log
/* Test for printf formats. Formats using C99 features, including cases where C99 specifies some aspect of the format to be ignored or where the behavior is undefined. */ /* Origin: Joseph Myers <jsm28@cam.ac.uk> */ /* { dg-do compile { target { *-*-mingw* } } } */ /* { dg-options "-std=iso9899:1999 -pedantic -Wformat" } */ #define USE_SYSTEM_FORMATS #include "format.h" void foo (int i, unsigned int u, double d, char *s, void *p, int *n, long double ld, wint_t lc, wchar_t *ls, long long int ll, unsigned long long int ull, signed char *ss, unsigned char *us, long long int *lln, intmax_t j, uintmax_t uj, intmax_t *jn, size_t z, signed_size_t sz, signed_size_t *zn, ptrdiff_t t, ptrdiff_t *tn) { /* See ISO/IEC 9899:1999 (E) subclause 7.19.6.1 (pages 273-281). We do not repeat here most of the checks for correct C90 formats or completely broken formats. */ /* Valid and invalid %h, %hh, %l, %j, %z, %t, %L constructions. */ printf ("%hf", d); /* { dg-warning "length" "bad use of %h" } */ printf ("%hF", d); /* { dg-warning "unknown|format" "bad use of %hF" } */ printf ("%he", d); /* { dg-warning "length" "bad use of %h" } */ printf ("%hE", d); /* { dg-warning "length" "bad use of %h" } */ printf ("%hg", d); /* { dg-warning "length" "bad use of %h" } */ printf ("%hG", d); /* { dg-warning "length" "bad use of %h" } */ printf ("%ha", d); /* { dg-warning "unknown|format" "bad use of %ha" } */ printf ("%hA", d); /* { dg-warning "unknown|format" "bad use of %hA" } */ printf ("%hc", i); printf ("%hs", (short *)s); printf ("%hp", p); /* { dg-warning "length" "bad use of %h" } */ printf ("%lc", lc); printf ("%ls", ls); printf ("%lp", p); /* { dg-warning "length|C" "bad use of %l" } */ /* Valid uses of each bare conversion. */ printf ("%d%i%o%u%x%X%f%e%E%g%G%c%s%p%n%%", i, i, u, u, u, u, d, d, d, d, d, i, s, p, n); /* Uses of the - flag (valid on all non-%, non-n conversions). */ printf ("%-d%-i%-o%-u%-x%-X%-f%-e%-E%-g%-G%-c%-s%-p", i, i, u, u, u, u, d, d, d, d, d, i, s, p); printf ("%-n", n); /* { dg-warning "flag" "bad use of %-n" } */ /* Uses of the + flag (valid on signed conversions only). */ printf ("%+d%+i%+f%+e%+E%+g%+G\n", i, i, d, d, d, d, d); printf ("%+o", u); /* { dg-warning "flag" "bad use of + flag" } */ printf ("%+u", u); /* { dg-warning "flag" "bad use of + flag" } */ printf ("%+x", u); /* { dg-warning "flag" "bad use of + flag" } */ printf ("%+X", u); /* { dg-warning "flag" "bad use of + flag" } */ printf ("%+c", i); /* { dg-warning "flag" "bad use of + flag" } */ printf ("%+s", s); /* { dg-warning "flag" "bad use of + flag" } */ printf ("%+p", p); /* { dg-warning "flag" "bad use of + flag" } */ printf ("%+n", n); /* { dg-warning "flag" "bad use of + flag" } */ /* Uses of the space flag (valid on signed conversions only, and ignored with +). */ printf ("% +d", i); /* { dg-warning "use of both|ignored" "use of space and + flags" } */ printf ("%+ d", i); /* { dg-warning "use of both|ignored" "use of space and + flags" } */ printf ("% d% i% f% e% E% g% G\n", i, i, d, d, d, d, d); printf ("% o", u); /* { dg-warning "flag" "bad use of space flag" } */ printf ("% u", u); /* { dg-warning "flag" "bad use of space flag" } */ printf ("% x", u); /* { dg-warning "flag" "bad use of space flag" } */ printf ("% X", u); /* { dg-warning "flag" "bad use of space flag" } */ printf ("% c", i); /* { dg-warning "flag" "bad use of space flag" } */ printf ("% s", s); /* { dg-warning "flag" "bad use of space flag" } */ printf ("% p", p); /* { dg-warning "flag" "bad use of space flag" } */ printf ("% n", n); /* { dg-warning "flag" "bad use of space flag" } */ /* Uses of the # flag. */ printf ("%#o%#x%#X%#e%#E%#f%#g%#G", u, u, u, d, d, d, d, d); printf ("%#d", i); /* { dg-warning "flag" "bad use of # flag" } */ printf ("%#i", i); /* { dg-warning "flag" "bad use of # flag" } */ printf ("%#u", u); /* { dg-warning "flag" "bad use of # flag" } */ printf ("%#c", i); /* { dg-warning "flag" "bad use of # flag" } */ printf ("%#s", s); /* { dg-warning "flag" "bad use of # flag" } */ printf ("%#p", p); /* { dg-warning "flag" "bad use of # flag" } */ printf ("%#n", n); /* { dg-warning "flag" "bad use of # flag" } */ /* Uses of the 0 flag. */ printf ("%08d%08i%08o%08u%08x%08X%08e%08E%08f%08g%08G", i, i, u, u, u, u, d, d, d, d, d); printf ("%0c", i); /* { dg-warning "flag" "bad use of 0 flag" } */ printf ("%0s", s); /* { dg-warning "flag" "bad use of 0 flag" } */ printf ("%0p", p); /* { dg-warning "flag" "bad use of 0 flag" } */ printf ("%0n", n); /* { dg-warning "flag" "bad use of 0 flag" } */ /* 0 flag ignored with - flag. */ printf ("%-08d", i); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ printf ("%-08i", i); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ printf ("%-08o", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ printf ("%-08u", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ printf ("%-08x", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ printf ("%-08X", u); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ printf ("%-08e", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ printf ("%-08E", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ printf ("%-08f", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ printf ("%-08F", d); /* { dg-warning "unknown|format" "0 flag ignored with - flag" } */ printf ("%-08g", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ printf ("%-08G", d); /* { dg-warning "flags|ignored" "0 flag ignored with - flag" } */ printf ("%-08a", d); /* { dg-warning "unknown|format" "0 flag ignored with - flag" } */ printf ("%-08A", d); /* { dg-warning "unknown|format" "0 flag ignored with - flag" } */ /* Various tests of bad argument types. Mostly covered in c90-printf-1.c; here just test for pointer target sign with %hhn. (Probably allowed by the standard, but a bad idea, so GCC should diagnose if what is used is not signed char *.) */ printf ("%hhn", s); /* { dg-warning "unknown|format" "%hhn is unsupported" } */ printf ("%hhn", us); /* { dg-warning "unknown|format" "%hhn is unsupported" } */ }