diff mbox series

[committed] c: Handle printf %B like %b for C2x

Message ID cca6c3b-79e-2ee2-d815-f58cc7e7b197@codesourcery.com
State New
Headers show
Series [committed] c: Handle printf %B like %b for C2x | expand

Commit Message

Joseph Myers May 18, 2023, 12:08 a.m. UTC
WG14 decided to change the printf %B format from a recommended
extension to an optional feature defined in normative text.  Thus,
change the format checking to handle %B like %b, so not diagnosing it
with -Wformat -std=c2x -pedantic, just as with other optional
normatively defined features (such as decimal floating point and its
associated formats, for example).

Bootstrapped with no regressions for x86_64-pc-linux-gnu.

gcc/c-family/
	* c-format.cc (print_char_table): Handle %B like %b.

gcc/testsuite/
	* gcc.dg/format/c2x-printf-1.c: Test %B here.
	* gcc.dg/format/ext-9.c: Do not test %B here.
diff mbox series

Patch

diff --git a/gcc/c-family/c-format.cc b/gcc/c-family/c-format.cc
index 32858ef7c17..b4eeebcb30e 100644
--- a/gcc/c-family/c-format.cc
+++ b/gcc/c-family/c-format.cc
@@ -722,13 +722,12 @@  static const format_char_info print_char_table[] =
   { "F",   0, STD_C99, { T99_D,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T99_LD,  BADLEN,  BADLEN,  BADLEN,  T2X_D32, T2X_D64, T2X_D128, BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,   BADLEN,   BADLEN }, "-wp0 +#'I", "",   NULL },
   { "aA",  0, STD_C99, { T99_D,   BADLEN,  BADLEN,  T99_D,   BADLEN,  T99_LD,  BADLEN,  BADLEN,  BADLEN,  T2X_D32, T2X_D64, T2X_D128, BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,   BADLEN,   BADLEN }, "-wp0 +#",   "",   NULL },
   /* C2X conversion specifiers.  */
-  { "b",   0, STD_C2X, { T2X_UI,  T2X_UC,  T2X_US,  T2X_UL,  T2X_ULL, TEX_ULL, T2X_ST,  T2X_UPD, T2X_UIM, BADLEN,  BADLEN,  BADLEN,   T2X_U8,  T2X_U16, T2X_U32, T2X_U64, T2X_UF8, T2X_UF16, T2X_UF32, T2X_UF64 }, "-wp0#",     "i",  NULL },
+  { "bB",  0, STD_C2X, { T2X_UI,  T2X_UC,  T2X_US,  T2X_UL,  T2X_ULL, TEX_ULL, T2X_ST,  T2X_UPD, T2X_UIM, BADLEN,  BADLEN,  BADLEN,   T2X_U8,  T2X_U16, T2X_U32, T2X_U64, T2X_UF8, T2X_UF16, T2X_UF32, T2X_UF64 }, "-wp0#",     "i",  NULL },
   /* X/Open conversion specifiers.  */
   { "C",   0, STD_EXT, { TEX_WI,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,   BADLEN,   BADLEN }, "-w",        "",   NULL },
   { "S",   1, STD_EXT, { TEX_W,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,   BADLEN,   BADLEN }, "-wp",       "R",  NULL },
   /* GNU conversion specifiers.  */
   { "m",   0, STD_EXT, { T89_V,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,   BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,  BADLEN,   BADLEN,   BADLEN }, "-wp",       "",   NULL },
-  { "B",   0, STD_EXT, { T2X_UI,  T2X_UC,  T2X_US,  T2X_UL,  T2X_ULL, TEX_ULL, T2X_ST,  T2X_UPD, T2X_UIM, BADLEN,  BADLEN,  BADLEN,   T2X_U8,  T2X_U16, T2X_U32, T2X_U64, T2X_UF8, T2X_UF16, T2X_UF32, T2X_UF64 }, "-wp0#",     "i",  NULL },
   { NULL,  0, STD_C89, NOLENGTHS, NULL, NULL, NULL }
 };
 
diff --git a/gcc/testsuite/gcc.dg/format/c2x-printf-1.c b/gcc/testsuite/gcc.dg/format/c2x-printf-1.c
index ca43d7997e5..9be7d4753d1 100644
--- a/gcc/testsuite/gcc.dg/format/c2x-printf-1.c
+++ b/gcc/testsuite/gcc.dg/format/c2x-printf-1.c
@@ -28,6 +28,18 @@  foo (unsigned int u, unsigned short us, unsigned char uc, unsigned long ul,
   /* Use of 'L' and 'q' for long long is an extension.  */
   printf ("%Lb", ull); /* { dg-warning "does not support" } */
   printf ("%qb", ull); /* { dg-warning "does not support" } */
+  /* Similar tests with %B.  */
+  printf ("%B %hB %hhB %lB %llB %jB %zB %tB\n", u, us, uc, ul, ull, uj, z, ut);
+  printf ("%*.*llB\n", 1, 2, ull);
+  printf ("%-B\n", u);
+  printf ("%#B\n", u);
+  printf ("%08B\n", u);
+  printf ("%+B\n", u); /* { dg-warning "flag" } */
+  printf ("% B\n", u); /* { dg-warning "flag" } */
+  printf ("%-08B\n", u); /* { dg-warning "ignored" } */
+  printf ("%08.5B\n", u); /* { dg-warning "ignored" } */
+  printf ("%LB", ull); /* { dg-warning "does not support" } */
+  printf ("%qB", ull); /* { dg-warning "does not support" } */
   /* Use of %wN and %wfN with each valid conversion specifier.  */
   printf ("%w8d %w16d %w32d %w64d %wf8d %wf16d %wf32d %wf64d",
 	  i8, i16, i32, i64, if8, if16, if32, if64);
@@ -35,6 +47,8 @@  foo (unsigned int u, unsigned short us, unsigned char uc, unsigned long ul,
 	  i8, i16, i32, i64, if8, if16, if32, if64);
   printf ("%w8b %w16b %w32b %w64b %wf8b %wf16b %wf32b %wf64b",
 	  u8, u16, u32, u64, uf8, uf16, uf32, uf64);
+  printf ("%w8B %w16B %w32B %w64B %wf8B %wf16B %wf32B %wf64B",
+	  u8, u16, u32, u64, uf8, uf16, uf32, uf64);
   printf ("%w8o %w16o %w32o %w64o %wf8o %wf16o %wf32o %wf64o",
 	  u8, u16, u32, u64, uf8, uf16, uf32, uf64);
   printf ("%w8u %w16u %w32u %w64u %wf8u %wf16u %wf32u %wf64u",
diff --git a/gcc/testsuite/gcc.dg/format/ext-9.c b/gcc/testsuite/gcc.dg/format/ext-9.c
index 0aeb365e767..8f091292b72 100644
--- a/gcc/testsuite/gcc.dg/format/ext-9.c
+++ b/gcc/testsuite/gcc.dg/format/ext-9.c
@@ -19,19 +19,4 @@  foo (u_quad_t uq, unsigned int u, unsigned short us, unsigned char uc,
   printf ("%qb%qB", uq, uq);
   printf ("%Lb%LB", ull, ull);
   printf ("%Zb%ZB", z, z);
-  /* Use of %B in cases valid for %b.  */
-  printf ("%B %hB %hhB %lB %llB %jB %zB %tB\n", u, us, uc, ul, ull, uj, z, ut);
-  printf ("%*.*llB\n", 1, 2, ull);
-  printf ("%-B\n", u);
-  printf ("%#B\n", u);
-  printf ("%08B\n", u);
-  /* Flags valid on signed conversions only.  */
-  printf ("%+B\n", u); /* { dg-warning "flag" } */
-  printf ("% B\n", u); /* { dg-warning "flag" } */
-  /* Flags ignored in certain combinations.  */
-  printf ("%-08B\n", u); /* { dg-warning "ignored" } */
-  printf ("%08.5B\n", u); /* { dg-warning "ignored" } */
-  /* Use of %wN and %wfN with %B.  */
-  printf ("%w8B %w16B %w32B %w64B %wf8B %wf16B %wf32B %wf64B",
-	  u8, u16, u32, u64, uf8, uf16, uf32, uf64);
 }