[committed] c: Add -std=c23, -std=gnu23, -Wc11-c23-compat options [PR107954]

Message ID f232d697-dff3-8aed-2e27-516903bcfe8@codesourcery.com
State Unresolved
Headers
Series [committed] c: Add -std=c23, -std=gnu23, -Wc11-c23-compat options [PR107954] |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Joseph Myers Nov. 6, 2023, 3:03 p.m. UTC
  At the June WG14 meeting, WG14 decided it preferred to keep C23 as the
informal name for the next revision of the C standard, despite
publication not being before 2024 (publication is due in 2024 whether
or not technical changes at the January meeting result in an FDIS
ballot being needed).  At the Cauldron I raised the question of
whether we should thus now add option names such as -std=c23 to GCC,
and there was support for doing so.

Add -std=c23, making -std=c2x a deprecated alias; also add the alias
-std=iso9899:2024.  Likewise, add -std=gnu23, making -std=gnu2x a
deprecated alias, and add -Wc11-c23-compat, making -Wc11-c2x-compat a
deprecated alias.

Here, I'm generally just adding the new options and making the minimum
changes required to do so, with documentation changed to refer to C23
instead of C2X only where directly associated with documentation of
these options.  It's intended that future changes will update
documentation, diagnostics, comments, variable names, testcase names,
etc. to refer consistently to C23.  When such changes are made, the
new tests c23-opts-3.c, c23-opts-5.c and gnu23-opts-2.c are intended
to keep using the old option names they are specifically testing,
while other tests would start using the c23/gnu23 versions of the
names (as well as the tests themselves being renamed).

Updating option names is independent of updating to the final
__STDC_VERSION__ value.  There, the question is whether we should
update the value now or wait for the remaining significant features to
be implemented first.  (I intend to review Martin's tag compatibility
patches for GCC 14.  I'm not aware of anyone working on #embed - or on
the [[unsequenced]] and [[reproducible]] attributes, though support
for standard attributes is optional.)

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

	PR c/107954

gcc/
	* doc/cpp.texi (__STDC_VERSION__): Refer to -std=c23 and
	-std=gnu23 instead of -std=c2x and -std=gnu2x.
	* doc/extend.texi (Attribute Syntax): Refer to C23 and -std=c23
	instead of C2x and -std=c2x.
	* doc/invoke.texi (-Wc11-c23-compat, -std=c23, -std=gnu23)
	(-std=iso9899:2024): Document, with -Wc11-c2x-compat, -std=c2x and
	-std=gnu2x as deprecated aliases.  Update descriptions of C23.
	* doc/standards.texi (Standards): Describe C23 with C2X as an old
	name.

gcc/c-family/
	* c.opt (Wc11-c2x-compat): Rename to Wc11-c23-compat and make into
	a deprecated alias of Wc11-c23-compat.
	(std=c2x): Rename to std=c23 and make into a deprecated alias of
	std=c23.
	(std=gnu2x): Rename to std=gnu23 and make into a deprecated alias
	of std=gnu23.
	(std=iso9899:2024): New option.  Alias of std=c23.
	* c-lex.cc (interpret_float): Use OPT_Wc11_c23_compat instead of
	OPT_Wc11_c2x_compat.
	* c-opts.cc (c_common_handle_option): Use OPT_std_c23 instead of
	OPT_std_c2x and OPT_std_gnu23 instead of OPT_std_gnu2x.

gcc/c/
	* c-errors.cc (pedwarn_c11): Use OPT_Wc11_c23_compat instead of
	OPT_Wc11_c2x_compat.
	* c-typeck.cc (build_conditional_expr, convert_for_assignment):
	Use OPT_Wc11_c23_compat instead of OPT_Wc11_c2x_compat.

gcc/testsuite/
	* gcc.dg/c23-opts-1.c, gcc.dg/c23-opts-2.c, gcc.dg/c23-opts-3.c,
	gcc.dg/c23-opts-4.c, gcc.dg/c23-opts-5.c, gcc.dg/gnu23-opts-1.c,
	gcc.dg/gnu23-opts-2.c: New tests.
  

Patch

diff --git a/gcc/c-family/c-lex.cc b/gcc/c-family/c-lex.cc
index 5e457b78cdd..a05632295cf 100644
--- a/gcc/c-family/c-lex.cc
+++ b/gcc/c-family/c-lex.cc
@@ -1190,11 +1190,11 @@  interpret_float (const cpp_token *token, unsigned int flags,
 	    if (warn_c11_c2x_compat > 0)
 	      {
 		if (pedantic && !flag_isoc2x)
-		  pedwarn (input_location, OPT_Wc11_c2x_compat,
+		  pedwarn (input_location, OPT_Wc11_c23_compat,
 			   "non-standard suffix on floating constant "
 			   "before C2X");
 		else
-		  warning (OPT_Wc11_c2x_compat,
+		  warning (OPT_Wc11_c23_compat,
 			   "non-standard suffix on floating constant "
 			   "before C2X");
 	      }
diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
index e9f7e6d424d..6b64821cbf0 100644
--- a/gcc/c-family/c-opts.cc
+++ b/gcc/c-family/c-opts.cc
@@ -732,12 +732,12 @@  c_common_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
 	set_std_c17 (false /* ISO */);
       break;
 
-    case OPT_std_c2x:
+    case OPT_std_c23:
       if (!preprocessing_asm_p)
 	set_std_c2x (true /* ISO */);
       break;
 
-    case OPT_std_gnu2x:
+    case OPT_std_gnu23:
       if (!preprocessing_asm_p)
 	set_std_c2x (false /* ISO */);
       break;
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 29d3d789a49..359f071e632 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -433,9 +433,13 @@  Wbuiltin-macro-redefined
 C ObjC C++ ObjC++ CPP(warn_builtin_macro_redefined) CppReason(CPP_W_BUILTIN_MACRO_REDEFINED) Var(cpp_warn_builtin_macro_redefined) Init(1) Warning
 Warn when a built-in preprocessor macro is undefined or redefined.
 
-Wc11-c2x-compat
+Wc11-c23-compat
 C ObjC CPP(cpp_warn_c11_c2x_compat) CppReason(CPP_W_C11_C2X_COMPAT) Var(warn_c11_c2x_compat) Init(-1) Warning
-Warn about features not present in ISO C11, but present in ISO C2X.
+Warn about features not present in ISO C11, but present in ISO C23.
+
+Wc11-c2x-compat
+C ObjC Alias(Wc11-c23-compat)
+Deprecated in favor of -Wc11-c23-compat.
 
 Wc90-c99-compat
 C ObjC CPP(cpp_warn_c90_c99_compat) CppReason(CPP_W_C90_C99_COMPAT) Var(warn_c90_c99_compat) Init(-1) Warning
@@ -2463,9 +2467,13 @@  std=c18
 C ObjC Alias(std=c17)
 Conform to the ISO 2017 C standard (published in 2018).
 
-std=c2x
+std=c23
 C ObjC
-Conform to the ISO 202X C standard draft (experimental and incomplete support).
+Conform to the ISO 2023 C standard draft (expected to be published in 2024) (experimental and incomplete support).
+
+std=c2x
+C ObjC Alias(std=c23)
+Deprecated in favor of -std=c23.
 
 std=c89
 C ObjC Alias(std=c90)
@@ -2557,9 +2565,13 @@  std=gnu18
 C ObjC Alias(std=gnu17)
 Conform to the ISO 2017 C standard (published in 2018) with GNU extensions.
 
-std=gnu2x
+std=gnu23
 C ObjC
-Conform to the ISO 202X C standard draft with GNU extensions (experimental and incomplete support).
+Conform to the ISO 2023 C standard draft (expected to be published in 2024) with GNU extensions (experimental and incomplete support).
+
+std=gnu2x
+C ObjC Alias(std=gnu23)
+Deprecated in favor of -std=gnu23.
 
 std=gnu89
 C ObjC Alias(std=gnu90)
@@ -2605,6 +2617,10 @@  std=iso9899:2018
 C ObjC Alias(std=c17)
 Conform to the ISO 2017 C standard (published in 2018).
 
+std=iso9899:2024
+C ObjC Alias(std=c23)
+Conform to the ISO 2023 C standard draft (expected to be published in 2024) (experimental and incomplete support).
+
 stdlib=
 Driver C++ ObjC++ Common Condition(ENABLE_STDLIB_OPTION) Var(flag_stdlib_kind) Joined Enum(stdlib_kind) RejectNegative Init(1)
 -stdlib=[libstdc++|libc++]	The standard library to be used for C++ headers
diff --git a/gcc/c/c-errors.cc b/gcc/c/c-errors.cc
index 01c521e5536..87bb13c6b25 100644
--- a/gcc/c/c-errors.cc
+++ b/gcc/c/c-errors.cc
@@ -47,7 +47,7 @@  pedwarn_c11 (location_t location, int opt, const char *gmsgid, ...)
       diagnostic_set_info (&diagnostic, gmsgid, &ap, &richloc,
 			   (pedantic && !flag_isoc2x)
 			   ? DK_PEDWARN : DK_WARNING);
-      diagnostic.option_index = OPT_Wc11_c2x_compat;
+      diagnostic.option_index = OPT_Wc11_c23_compat;
       warned = diagnostic_report_diagnostic (global_dc, &diagnostic);
     }
   /* -Wno-c11-c2x-compat suppresses even the pedwarns.  */
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index bdd57aae3ff..dd39cec9204 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -5545,7 +5545,7 @@  build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp,
 			    "pointer to array loses qualifier "
 			    "in conditional expression");
 	      else if (warn_c11_c2x_compat > 0)
-		warning_at (colon_loc, OPT_Wc11_c2x_compat,
+		warning_at (colon_loc, OPT_Wc11_c23_compat,
 			    "pointer to array loses qualifier "
 			    "in conditional expression in ISO C before C2X");
 	    }
@@ -7603,7 +7603,7 @@  convert_for_assignment (location_t location, location_t expr_loc, tree type,
 					   "pointer target type"),
 					TYPE_QUALS (ttr) & ~TYPE_QUALS (ttl));
 	      else if (warn_quals_ped)
-		pedwarn_c11 (location, OPT_Wc11_c2x_compat,
+		pedwarn_c11 (location, OPT_Wc11_c23_compat,
 			     "array with qualifier on the element is not qualified before C2X");
 
 	      /* If this is not a case of ignoring a mismatch in signedness,
diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi
index 3f492b33470..705e587ace6 100644
--- a/gcc/doc/cpp.texi
+++ b/gcc/doc/cpp.texi
@@ -1887,7 +1887,7 @@  signifies the 2011 revision of the C standard; the value
 @code{201710L} signifies the 2017 revision of the C standard (which is
 otherwise identical to the 2011 version apart from correction of
 defects).  An unspecified value larger than @code{201710L} is used for
-the experimental @option{-std=c2x} and @option{-std=gnu2x} modes.
+the experimental @option{-std=c23} and @option{-std=gnu23} modes.
 
 This macro is not defined if the @option{-traditional-cpp} option is
 used, nor when compiling C++ or Objective-C@.
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index fa7402813e7..6575c2be483 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -9443,8 +9443,8 @@  default language dialect for both C and C++.  More specifically, this
 syntax was first introduced in the C++11 language standard
 (@pxref{Standards}), and is supported by GCC in C++ code with
 @option{-std=c++11} or @option{-std=gnu++11} or later.  It is also
-part of the C2x language standard and is supported when compiling C
-code with @option{-std=c2x} or @option{-std=gnu17} or later.
+part of the C23 language standard and is supported when compiling C
+code with @option{-std=c23} or @option{-std=gnu17} or later.
 
 When using GNU-specific attributes in the standard syntax, you must
 prefix their names with @samp{gnu::}, such as @code{gnu::section}.
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index 6e776a0faa1..80bb1efac40 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -337,7 +337,7 @@  Objective-C and Objective-C++ Dialects}.
 -Wbool-compare  -Wbool-operation
 -Wno-builtin-declaration-mismatch
 -Wno-builtin-macro-redefined  -Wc90-c99-compat  -Wc99-c11-compat
--Wc11-c2x-compat
+-Wc11-c23-compat
 -Wc++-compat  -Wc++11-compat  -Wc++14-compat  -Wc++17-compat
 -Wc++20-compat
 -Wno-c++11-extensions  -Wno-c++14-extensions -Wno-c++17-extensions
@@ -2432,9 +2432,12 @@  same as C11 except for corrections of defects (all of which are also
 applied with @option{-std=c11}) and a new value of
 @code{__STDC_VERSION__}, and so is supported to the same extent as C11.
 
-@item c2x
-The next version of the ISO C standard, still under development.  The
-support for this version is experimental and incomplete.
+@item c23
+@itemx c2x
+@itemx iso9899:2024
+ISO C23, the 2023 revision of the ISO C standard (expected to be
+published in 2024).  The support for this version is experimental and
+incomplete.  The name @samp{c2x} is deprecated.
 
 @item gnu90
 @itemx gnu89
@@ -2453,10 +2456,11 @@  The name @samp{gnu1x} is deprecated.
 @itemx gnu18
 GNU dialect of ISO C17.  This is the default for C code.
 
-@item gnu2x
+@item gnu23
+@itemx gnu2x
 The next version of the ISO C standard, still under development, plus
 GNU extensions.  The support for this version is experimental and
-incomplete.
+incomplete.  The name @samp{gnu2x} is deprecated.
 
 @item c++98
 @itemx c++03
@@ -2566,10 +2570,10 @@  this switch.  You may want to use the @option{-fno-gnu-keywords} flag
 instead, which disables @code{typeof} but not @code{asm} and
 @code{inline}.  In C99 mode (@option{-std=c99} or @option{-std=gnu99}),
 this switch only affects the @code{asm} and @code{typeof} keywords,
-since @code{inline} is a standard keyword in ISO C99.  In C2X mode
-(@option{-std=c2x} or @option{-std=gnu2x}), this switch only affects
+since @code{inline} is a standard keyword in ISO C99.  In C23 mode
+(@option{-std=c23} or @option{-std=gnu23}), this switch only affects
 the @code{asm} keyword, since @code{typeof} is a standard keyword in
-ISO C2X.
+ISO C23.
 
 @opindex fno-builtin
 @opindex fbuiltin
@@ -8998,17 +9002,19 @@  For instance, warn about use of anonymous structures and unions,
 and so on.  This option is independent of the standards mode.  Warnings are
 disabled in the expression that follows @code{__extension__}.
 
-@opindex Wc11-c2x-compat
-@opindex Wno-c11-c2x-compat
-@item -Wc11-c2x-compat @r{(C and Objective-C only)}
-Warn about features not present in ISO C11, but present in ISO C2X.
+@opindex Wc11-c23-compat
+@opindex Wno-c11-c23-compat
+@item -Wc11-c23-compat @r{(C and Objective-C only)}
+@itemx -Wc11-c2x-compat @r{(C and Objective-C only)}
+Warn about features not present in ISO C11, but present in ISO C23.
 For instance, warn about omitting the string in @code{_Static_assert},
 use of @samp{[[]]} syntax for attributes, use of decimal
 floating-point types, and so on.  This option is independent of the
 standards mode.  Warnings are disabled in the expression that follows
-@code{__extension__}.
+@code{__extension__}.  The name @option{-Wc11-c2x-compat} is
+deprecated.
 
-When not compiling in C2X mode, these warnings are upgraded to errors
+When not compiling in C23 mode, these warnings are upgraded to errors
 by @option{-pedantic-errors}.
 
 @opindex Wc++-compat
diff --git a/gcc/doc/standards.texi b/gcc/doc/standards.texi
index 2bcb664eb6b..4eb43f14f90 100644
--- a/gcc/doc/standards.texi
+++ b/gcc/doc/standards.texi
@@ -38,6 +38,8 @@  with some exceptions, and possibly with some extensions.
 @cindex C1X
 @cindex ISO C17
 @cindex C17
+@cindex ISO C23
+@cindex C23
 @cindex ISO C2X
 @cindex C2X
 @cindex Technical Corrigenda
@@ -111,9 +113,11 @@  known as @dfn{C17} and is supported with @option{-std=c17} or
 @option{-std=c11}, and the only difference between the options is the
 value of @code{__STDC_VERSION__}.
 
-A further version of the C standard, known as @dfn{C2X}, is under
-development; experimental and incomplete support for this is enabled
-with @option{-std=c2x}.
+A further version of the C standard, known as @dfn{C23}, is under
+development and expected to be published in 2024 as ISO/IEC 9899:2024.
+(While in development, drafts of this standard version were referred
+to as @dfn{C2X}.)  Experimental and incomplete support for this is
+enabled with @option{-std=c23} or @option{-std=iso9899:2024}.
 
 By default, GCC provides some extensions to the C language that, on
 rare occasions conflict with the C standard.  @xref{C
diff --git a/gcc/testsuite/gcc.dg/c23-opts-1.c b/gcc/testsuite/gcc.dg/c23-opts-1.c
new file mode 100644
index 00000000000..a72c6c6e7af
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c23-opts-1.c
@@ -0,0 +1,5 @@ 
+/* Test -std=c23.  */
+/* { dg-do compile } */
+/* { dg-options "-std=c23" } */
+
+auto p = nullptr;
diff --git a/gcc/testsuite/gcc.dg/c23-opts-2.c b/gcc/testsuite/gcc.dg/c23-opts-2.c
new file mode 100644
index 00000000000..47081a84745
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c23-opts-2.c
@@ -0,0 +1,5 @@ 
+/* Test -std=iso9899:2024.  */
+/* { dg-do compile } */
+/* { dg-options "-std=iso9899:2024" } */
+
+auto p = nullptr;
diff --git a/gcc/testsuite/gcc.dg/c23-opts-3.c b/gcc/testsuite/gcc.dg/c23-opts-3.c
new file mode 100644
index 00000000000..37b8bce1a09
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c23-opts-3.c
@@ -0,0 +1,5 @@ 
+/* Test the deprecated option -std=c2x.  */
+/* { dg-do compile } */
+/* { dg-options "-std=c2x" } */
+
+auto p = nullptr;
diff --git a/gcc/testsuite/gcc.dg/c23-opts-4.c b/gcc/testsuite/gcc.dg/c23-opts-4.c
new file mode 100644
index 00000000000..a501bc838d7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c23-opts-4.c
@@ -0,0 +1,5 @@ 
+/* Test -Wc11-c23-compat.  */
+/* { dg-do compile } */
+/* { dg-options "-std=c23 -Wc11-c23-compat" } */
+
+void *p = nullptr; /* { dg-warning "nullptr" } */
diff --git a/gcc/testsuite/gcc.dg/c23-opts-5.c b/gcc/testsuite/gcc.dg/c23-opts-5.c
new file mode 100644
index 00000000000..39e486deb96
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/c23-opts-5.c
@@ -0,0 +1,5 @@ 
+/* Test the deprecated option -Wc11-c2x-compat.  */
+/* { dg-do compile } */
+/* { dg-options "-std=c23 -Wc11-c2x-compat" } */
+
+void *p = nullptr; /* { dg-warning "nullptr" } */
diff --git a/gcc/testsuite/gcc.dg/gnu23-opts-1.c b/gcc/testsuite/gcc.dg/gnu23-opts-1.c
new file mode 100644
index 00000000000..e5de935bf02
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gnu23-opts-1.c
@@ -0,0 +1,5 @@ 
+/* Test -std=gnu23.  */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu23" } */
+
+auto p = nullptr;
diff --git a/gcc/testsuite/gcc.dg/gnu23-opts-2.c b/gcc/testsuite/gcc.dg/gnu23-opts-2.c
new file mode 100644
index 00000000000..a3980d92581
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gnu23-opts-2.c
@@ -0,0 +1,5 @@ 
+/* Test the deprecated option -std=gnu2x.  */
+/* { dg-do compile } */
+/* { dg-options "-std=gnu2x" } */
+
+auto p = nullptr;