c-family: Support format checking C2X %b, %B formats
[official-gcc.git] / gcc / testsuite / gcc.dg / format / ext-9.c
blob15f59e21dbe3ec15331f785b2cbd55f1c74b9bed
1 /* Test for printf format extensions using formats from or recommended by
2 C2X. */
3 /* { dg-do compile } */
4 /* { dg-options "-std=gnu2x -Wformat" } */
6 #include "format.h"
8 void
9 foo (u_quad_t uq, unsigned int u, unsigned short us, unsigned char uc,
10 unsigned long ul, unsigned long long ull, uintmax_t uj, size_t z,
11 unsigned_ptrdiff_t ut)
13 /* Deprecated length modifiers with %b and %B. */
14 printf ("%qb%qB", uq, uq);
15 printf ("%Lb%LB", ull, ull);
16 printf ("%Zb%ZB", z, z);
17 /* Use of %B in cases valid for %b. */
18 printf ("%B %hB %hhB %lB %llB %jB %zB %tB\n", u, us, uc, ul, ull, uj, z, ut);
19 printf ("%*.*llB\n", 1, 2, ull);
20 printf ("%-B\n", u);
21 printf ("%#B\n", u);
22 printf ("%08B\n", u);
23 /* Flags valid on signed conversions only. */
24 printf ("%+B\n", u); /* { dg-warning "flag" } */
25 printf ("% B\n", u); /* { dg-warning "flag" } */
26 /* Flags ignored in certain combinations. */
27 printf ("%-08B\n", u); /* { dg-warning "ignored" } */
28 printf ("%08.5B\n", u); /* { dg-warning "ignored" } */