* [PATCH] c++: Add support for -std={c,gnu}++2{c,6}
@ 2023-06-23 0:25 Marek Polacek
2023-06-23 14:58 ` Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2023-06-23 0:25 UTC (permalink / raw)
To: GCC Patches, Jason Merrill
It seems prudent to add C++26 now that the first C++26 papers have been
approved. I followed commit r11-6920 as well as r8-3237.
I was puzzled to see that -std=c++23 was marked Undocumented but
-std=c++2b wasn't. I think it should be the other way round, like
the earlier modes.
As for __cplusplus, I've arbitrarily chosen 202600L:
$ xg++ -std=c++26 -dM -E -x c++ - < /dev/null | grep cplusplus
#define __cplusplus 202600L
I've verified the patch with a simple test, exercising the new
directives. Don't forget to update your GXX_TESTSUITE_STDS!
This patch does not add -Wc++26-extensions.
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
gcc/c-family/ChangeLog:
* c-common.h (cxx_dialect): Add cxx26 as a dialect.
* c-opts.cc (set_std_cxx26): New.
(c_common_handle_option): Set options when -std={c,gnu}++2{c,6} is
enabled.
(c_common_post_options): Adjust comments.
* c.opt: Add options for -std=c++26, std=c++2c, -std=gnu++26,
and -std=gnu++2c.
(std=c++2b): Mark as Undocumented.
(std=c++23): No longer Undocumented.
gcc/ChangeLog:
* doc/cpp.texi (__cplusplus): Document value for -std=c++26 and
-std=gnu++26.
* doc/invoke.texi: Document -std=c++26 and -std=gnu++26.
* dwarf2out.cc (highest_c_language): Handle GNU C++26.
(gen_compile_unit_die): Likewise.
libcpp/ChangeLog:
* include/cpplib.h (c_lang): Add CXX26 and GNUCXX26.
* init.cc (lang_defaults): Add rows for CXX26 and GNUCXX26.
(cpp_init_builtins): Set __cplusplus to 202600L for C++26.
gcc/testsuite/ChangeLog:
* lib/target-supports.exp (check_effective_target_c++23): Return
1 also if check_effective_target_c++26.
(check_effective_target_c++23_down): New.
(check_effective_target_c++26_only): New.
(check_effective_target_c++26): New.
* g++.dg/cpp26/cplusplus.C: New test.
---
gcc/c-family/c-common.h | 4 +++-
gcc/c-family/c-opts.cc | 28 +++++++++++++++++++++++-
gcc/c-family/c.opt | 24 +++++++++++++++++----
gcc/doc/cpp.texi | 5 +++++
gcc/doc/invoke.texi | 12 +++++++++++
gcc/dwarf2out.cc | 5 ++++-
gcc/testsuite/g++.dg/cpp26/cplusplus.C | 5 +++++
gcc/testsuite/lib/target-supports.exp | 30 +++++++++++++++++++++++++-
libcpp/include/cpplib.h | 2 +-
libcpp/init.cc | 13 ++++++++---
10 files changed, 116 insertions(+), 12 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/cpp26/cplusplus.C
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 336a09f4a40..b5ef5ff6b2c 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -740,7 +740,9 @@ enum cxx_dialect {
/* C++20 */
cxx20,
/* C++23 */
- cxx23
+ cxx23,
+ /* C++26 */
+ cxx26
};
/* The C++ dialect being used. C++98 is the default. */
diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
index c68a2a27469..af19140e382 100644
--- a/gcc/c-family/c-opts.cc
+++ b/gcc/c-family/c-opts.cc
@@ -111,6 +111,7 @@ static void set_std_cxx14 (int);
static void set_std_cxx17 (int);
static void set_std_cxx20 (int);
static void set_std_cxx23 (int);
+static void set_std_cxx26 (int);
static void set_std_c89 (int, int);
static void set_std_c99 (int);
static void set_std_c11 (int);
@@ -663,6 +664,12 @@ c_common_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
set_std_cxx23 (code == OPT_std_c__23 /* ISO */);
break;
+ case OPT_std_c__26:
+ case OPT_std_gnu__26:
+ if (!preprocessing_asm_p)
+ set_std_cxx26 (code == OPT_std_c__26 /* ISO */);
+ break;
+
case OPT_std_c90:
case OPT_std_iso9899_199409:
if (!preprocessing_asm_p)
@@ -1032,7 +1039,8 @@ c_common_post_options (const char **pfilename)
warn_narrowing = 1;
/* Unless -f{,no-}ext-numeric-literals has been used explicitly,
- for -std=c++{11,14,17,20,23} default to -fno-ext-numeric-literals. */
+ for -std=c++{11,14,17,20,23,26} default to
+ -fno-ext-numeric-literals. */
if (flag_iso && !OPTION_SET_P (flag_ext_numeric_literals))
cpp_opts->ext_numeric_literals = 0;
}
@@ -1820,6 +1828,24 @@ set_std_cxx23 (int iso)
lang_hooks.name = "GNU C++23";
}
+/* Set the C++ 2026 standard (without GNU extensions if ISO). */
+static void
+set_std_cxx26 (int iso)
+{
+ cpp_set_lang (parse_in, iso ? CLK_CXX26: CLK_GNUCXX26);
+ flag_no_gnu_keywords = iso;
+ flag_no_nonansi_builtin = iso;
+ flag_iso = iso;
+ /* C++26 includes the C11 standard library. */
+ flag_isoc94 = 1;
+ flag_isoc99 = 1;
+ flag_isoc11 = 1;
+ /* C++26 includes coroutines. */
+ flag_coroutines = true;
+ cxx_dialect = cxx26;
+ lang_hooks.name = "GNU C++26";
+}
+
/* Args to -d specify what to dump. Silently ignore
unrecognized options; they may be aimed at toplev.cc. */
static void
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 0930a3c0422..bc03ebdad97 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -2403,13 +2403,21 @@ C++ ObjC++
Conform to the ISO 2020 C++ standard (experimental and incomplete support).
std=c++2b
-C++ ObjC++ Alias(std=c++23)
+C++ ObjC++ Alias(std=c++23) Undocumented
Conform to the ISO 2023 C++ draft standard (experimental and incomplete support).
std=c++23
-C++ ObjC++ Undocumented
+C++ ObjC++
Conform to the ISO 2023 C++ draft standard (experimental and incomplete support).
+std=c++2c
+C++ ObjC++ Alias(std=c++26) Undocumented
+Conform to the ISO 2026 C++ draft standard (experimental and incomplete support).
+
+std=c++26
+C++ ObjC++
+Conform to the ISO 2026 C++ draft standard (experimental and incomplete support).
+
std=c11
C ObjC
Conform to the ISO 2011 C standard.
@@ -2489,13 +2497,21 @@ C++ ObjC++
Conform to the ISO 2020 C++ standard with GNU extensions (experimental and incomplete support).
std=gnu++2b
-C++ ObjC++ Alias(std=gnu++23)
+C++ ObjC++ Alias(std=gnu++23) Undocumented
Conform to the ISO 2023 C++ draft standard with GNU extensions (experimental and incomplete support).
std=gnu++23
-C++ ObjC++ Undocumented
+C++ ObjC++
Conform to the ISO 2023 C++ draft standard with GNU extensions (experimental and incomplete support).
+std=gnu++2c
+C++ ObjC++ Alias(std=gnu++26) Undocumented
+Conform to the ISO 2026 C++ draft standard with GNU extensions (experimental and incomplete support).
+
+std=gnu++26
+C++ ObjC++
+Conform to the ISO 2026 C++ draft standard with GNU extensions (experimental and incomplete support).
+
std=gnu11
C ObjC
Conform to the ISO 2011 C standard with GNU extensions.
diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi
index b0a2ce3ac6b..e3e5d2af042 100644
--- a/gcc/doc/cpp.texi
+++ b/gcc/doc/cpp.texi
@@ -1911,6 +1911,11 @@ selected, the value of the macro is
or an unspecified value strictly larger than @code{202002L} for the
experimental languages enabled by @option{-std=c++23} and
@option{-std=gnu++23}.
+Similarly, the value of the macro is an unspecified value strictly
+larger than @code{202002L} (and at the same time strictly larger than
+the unspecified value defined for @option{-std=c++23} above) for the
+experimental languages enabled by @option{-std=c++26} and
+@option{-std=gnu++26}.
@item __OBJC__
This macro is defined, with value 1, when the Objective-C compiler is in
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index fd4943bf317..efcf3bfb3d6 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -2507,6 +2507,18 @@ change in incompatible ways in future releases.
GNU dialect of @option{-std=c++2b}. Support is highly experimental,
and will almost certainly change in incompatible ways in future
releases.
+
+@item c++2c
+@itemx c++26
+The next revision of the ISO C++ standard, planned for
+2026. Support is highly experimental, and will almost certainly
+change in incompatible ways in future releases.
+
+@item gnu++2c
+@itemx gnu++26
+GNU dialect of @option{-std=c++2c}. Support is highly experimental,
+and will almost certainly change in incompatible ways in future
+releases.
@end table
@opindex aux-info
diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index e70c47cec8d..9112fc0c64b 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -25105,6 +25105,8 @@ static char *producer_string;
static const char *
highest_c_language (const char *lang1, const char *lang2)
{
+ if (strcmp ("GNU C++26", lang1) == 0 || strcmp ("GNU C++26", lang2) == 0)
+ return "GNU C++26";
if (strcmp ("GNU C++23", lang1) == 0 || strcmp ("GNU C++23", lang2) == 0)
return "GNU C++23";
if (strcmp ("GNU C++20", lang1) == 0 || strcmp ("GNU C++20", lang2) == 0)
@@ -25215,7 +25217,8 @@ gen_compile_unit_die (const char *filename)
language = DW_LANG_C_plus_plus_14;
else if (strcmp (language_string, "GNU C++17") == 0
|| strcmp (language_string, "GNU C++20") == 0
- || strcmp (language_string, "GNU C++23") == 0)
+ || strcmp (language_string, "GNU C++23") == 0
+ || strcmp (language_string, "GNU C++26") == 0)
/* For now. */
language = DW_LANG_C_plus_plus_14;
}
diff --git a/gcc/testsuite/g++.dg/cpp26/cplusplus.C b/gcc/testsuite/g++.dg/cpp26/cplusplus.C
new file mode 100644
index 00000000000..3027f9e711a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp26/cplusplus.C
@@ -0,0 +1,5 @@
+// { dg-do compile }
+// { dg-options "-std=c++26" }
+
+// TODO: Update once __cplusplus is defined for C++23.
+static_assert(__cplusplus > 202002L);
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index d79ad4be105..c04db2be7f9 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -10785,7 +10785,35 @@ proc check_effective_target_c++23_only { } {
return 0
}
proc check_effective_target_c++23 { } {
- return [check_effective_target_c++23_only]
+ if [check_effective_target_c++23_only] {
+ return 1
+ }
+ return [check_effective_target_c++26]
+}
+
+proc check_effective_target_c++23_down { } {
+ if ![check_effective_target_c++] {
+ return 0
+ }
+ return [expr ![check_effective_target_c++26] ]
+}
+
+proc check_effective_target_c++26_only { } {
+ global cxx_default
+ if ![check_effective_target_c++] {
+ return 0
+ }
+ if [check-flags { { } { } { -std=c++26 -std=gnu++26 -std=c++2c -std=gnu++2c } }] {
+ return 1
+ }
+ if { $cxx_default == "c++26" && [check-flags { { } { } { } { -std=* } }] } {
+ return 1
+ }
+ return 0
+}
+
+proc check_effective_target_c++26 { } {
+ return [check_effective_target_c++26_only]
}
# Check for C++ Concepts support, i.e. -fconcepts flag.
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index d326f5aa316..aef703f8111 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -174,7 +174,7 @@ enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_GNUC11, CLK_GNUC17, CLK_GNUC2X,
CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX11, CLK_CXX11,
CLK_GNUCXX14, CLK_CXX14, CLK_GNUCXX17, CLK_CXX17,
CLK_GNUCXX20, CLK_CXX20, CLK_GNUCXX23, CLK_CXX23,
- CLK_ASM};
+ CLK_GNUCXX26, CLK_CXX26, CLK_ASM};
/* Payload of a NUMBER, STRING, CHAR or COMMENT token. */
struct GTY(()) cpp_string {
diff --git a/libcpp/init.cc b/libcpp/init.cc
index c508f06112a..8ef8833e508 100644
--- a/libcpp/init.cc
+++ b/libcpp/init.cc
@@ -127,6 +127,8 @@ static const struct lang_flags lang_defaults[] =
/* CXX20 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1 },
/* GNUCXX23 */ { 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
/* CXX23 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
+ /* GNUCXX26 */ { 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
+ /* CXX26 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
/* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
@@ -561,9 +563,14 @@ cpp_init_builtins (cpp_reader *pfile, int hosted)
if (CPP_OPTION (pfile, cplusplus))
{
- /* C++23 is not yet a standard. For now, use an invalid
- * year/month, 202100L, which is larger than 202002L. */
- if (CPP_OPTION (pfile, lang) == CLK_CXX23
+ /* C++26 is not yet a standard. For now, use an invalid
+ year/month, 202600L, which is larger than 202100L. */
+ if (CPP_OPTION (pfile, lang) == CLK_CXX26
+ || CPP_OPTION (pfile, lang) == CLK_GNUCXX26)
+ _cpp_define_builtin (pfile, "__cplusplus 202600L");
+ /* C++23 is not yet a standard, either. For now, use an invalid
+ year/month, 202100L, which is larger than 202002L. */
+ else if (CPP_OPTION (pfile, lang) == CLK_CXX23
|| CPP_OPTION (pfile, lang) == CLK_GNUCXX23)
_cpp_define_builtin (pfile, "__cplusplus 202100L");
else if (CPP_OPTION (pfile, lang) == CLK_CXX20
base-commit: 33ebb0dff9bb022f1e0709e0e73faabfc3df7931
--
2.41.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] c++: Add support for -std={c,gnu}++2{c,6}
2023-06-23 0:25 [PATCH] c++: Add support for -std={c,gnu}++2{c,6} Marek Polacek
@ 2023-06-23 14:58 ` Jason Merrill
2023-06-23 17:22 ` [PATCH v2] " Marek Polacek
0 siblings, 1 reply; 4+ messages in thread
From: Jason Merrill @ 2023-06-23 14:58 UTC (permalink / raw)
To: Marek Polacek, GCC Patches
On 6/22/23 20:25, Marek Polacek wrote:
> It seems prudent to add C++26 now that the first C++26 papers have been
> approved. I followed commit r11-6920 as well as r8-3237.
>
> I was puzzled to see that -std=c++23 was marked Undocumented but
> -std=c++2b wasn't. I think it should be the other way round, like
> the earlier modes.
I was leaving -std=c++23 undocumented until C++23 was finalized, which
it now effectively is, so this change is good. Speaking of which, it
looks like the final value for __cplusplus for C++23 is 202302L.
But similarly, I'd like to leave -std=c++26 undocumented for now.
> As for __cplusplus, I've arbitrarily chosen 202600L:
Our previous convention has been the year after the previous standard,
so let's use 202400L.
> $ xg++ -std=c++26 -dM -E -x c++ - < /dev/null | grep cplusplus
> #define __cplusplus 202600L
>
> I've verified the patch with a simple test, exercising the new
> directives. Don't forget to update your GXX_TESTSUITE_STDS!
>
> This patch does not add -Wc++26-extensions.
>
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
>
> gcc/c-family/ChangeLog:
>
> * c-common.h (cxx_dialect): Add cxx26 as a dialect.
> * c-opts.cc (set_std_cxx26): New.
> (c_common_handle_option): Set options when -std={c,gnu}++2{c,6} is
> enabled.
> (c_common_post_options): Adjust comments.
> * c.opt: Add options for -std=c++26, std=c++2c, -std=gnu++26,
> and -std=gnu++2c.
> (std=c++2b): Mark as Undocumented.
> (std=c++23): No longer Undocumented.
>
> gcc/ChangeLog:
>
> * doc/cpp.texi (__cplusplus): Document value for -std=c++26 and
> -std=gnu++26.
> * doc/invoke.texi: Document -std=c++26 and -std=gnu++26.
> * dwarf2out.cc (highest_c_language): Handle GNU C++26.
> (gen_compile_unit_die): Likewise.
>
> libcpp/ChangeLog:
>
> * include/cpplib.h (c_lang): Add CXX26 and GNUCXX26.
> * init.cc (lang_defaults): Add rows for CXX26 and GNUCXX26.
> (cpp_init_builtins): Set __cplusplus to 202600L for C++26.
>
> gcc/testsuite/ChangeLog:
>
> * lib/target-supports.exp (check_effective_target_c++23): Return
> 1 also if check_effective_target_c++26.
> (check_effective_target_c++23_down): New.
> (check_effective_target_c++26_only): New.
> (check_effective_target_c++26): New.
> * g++.dg/cpp26/cplusplus.C: New test.
> ---
> gcc/c-family/c-common.h | 4 +++-
> gcc/c-family/c-opts.cc | 28 +++++++++++++++++++++++-
> gcc/c-family/c.opt | 24 +++++++++++++++++----
> gcc/doc/cpp.texi | 5 +++++
> gcc/doc/invoke.texi | 12 +++++++++++
> gcc/dwarf2out.cc | 5 ++++-
> gcc/testsuite/g++.dg/cpp26/cplusplus.C | 5 +++++
> gcc/testsuite/lib/target-supports.exp | 30 +++++++++++++++++++++++++-
> libcpp/include/cpplib.h | 2 +-
> libcpp/init.cc | 13 ++++++++---
> 10 files changed, 116 insertions(+), 12 deletions(-)
> create mode 100644 gcc/testsuite/g++.dg/cpp26/cplusplus.C
>
> diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
> index 336a09f4a40..b5ef5ff6b2c 100644
> --- a/gcc/c-family/c-common.h
> +++ b/gcc/c-family/c-common.h
> @@ -740,7 +740,9 @@ enum cxx_dialect {
> /* C++20 */
> cxx20,
> /* C++23 */
> - cxx23
> + cxx23,
> + /* C++26 */
> + cxx26
> };
>
> /* The C++ dialect being used. C++98 is the default. */
> diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
> index c68a2a27469..af19140e382 100644
> --- a/gcc/c-family/c-opts.cc
> +++ b/gcc/c-family/c-opts.cc
> @@ -111,6 +111,7 @@ static void set_std_cxx14 (int);
> static void set_std_cxx17 (int);
> static void set_std_cxx20 (int);
> static void set_std_cxx23 (int);
> +static void set_std_cxx26 (int);
> static void set_std_c89 (int, int);
> static void set_std_c99 (int);
> static void set_std_c11 (int);
> @@ -663,6 +664,12 @@ c_common_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
> set_std_cxx23 (code == OPT_std_c__23 /* ISO */);
> break;
>
> + case OPT_std_c__26:
> + case OPT_std_gnu__26:
> + if (!preprocessing_asm_p)
> + set_std_cxx26 (code == OPT_std_c__26 /* ISO */);
> + break;
> +
> case OPT_std_c90:
> case OPT_std_iso9899_199409:
> if (!preprocessing_asm_p)
> @@ -1032,7 +1039,8 @@ c_common_post_options (const char **pfilename)
> warn_narrowing = 1;
>
> /* Unless -f{,no-}ext-numeric-literals has been used explicitly,
> - for -std=c++{11,14,17,20,23} default to -fno-ext-numeric-literals. */
> + for -std=c++{11,14,17,20,23,26} default to
> + -fno-ext-numeric-literals. */
> if (flag_iso && !OPTION_SET_P (flag_ext_numeric_literals))
> cpp_opts->ext_numeric_literals = 0;
> }
> @@ -1820,6 +1828,24 @@ set_std_cxx23 (int iso)
> lang_hooks.name = "GNU C++23";
> }
>
> +/* Set the C++ 2026 standard (without GNU extensions if ISO). */
> +static void
> +set_std_cxx26 (int iso)
> +{
> + cpp_set_lang (parse_in, iso ? CLK_CXX26: CLK_GNUCXX26);
> + flag_no_gnu_keywords = iso;
> + flag_no_nonansi_builtin = iso;
> + flag_iso = iso;
> + /* C++26 includes the C11 standard library. */
> + flag_isoc94 = 1;
> + flag_isoc99 = 1;
> + flag_isoc11 = 1;
> + /* C++26 includes coroutines. */
> + flag_coroutines = true;
> + cxx_dialect = cxx26;
> + lang_hooks.name = "GNU C++26";
> +}
> +
> /* Args to -d specify what to dump. Silently ignore
> unrecognized options; they may be aimed at toplev.cc. */
> static void
> diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
> index 0930a3c0422..bc03ebdad97 100644
> --- a/gcc/c-family/c.opt
> +++ b/gcc/c-family/c.opt
> @@ -2403,13 +2403,21 @@ C++ ObjC++
> Conform to the ISO 2020 C++ standard (experimental and incomplete support).
>
> std=c++2b
> -C++ ObjC++ Alias(std=c++23)
> +C++ ObjC++ Alias(std=c++23) Undocumented
> Conform to the ISO 2023 C++ draft standard (experimental and incomplete support).
>
> std=c++23
> -C++ ObjC++ Undocumented
> +C++ ObjC++
> Conform to the ISO 2023 C++ draft standard (experimental and incomplete support).
>
> +std=c++2c
> +C++ ObjC++ Alias(std=c++26) Undocumented
> +Conform to the ISO 2026 C++ draft standard (experimental and incomplete support).
> +
> +std=c++26
> +C++ ObjC++
> +Conform to the ISO 2026 C++ draft standard (experimental and incomplete support).
> +
> std=c11
> C ObjC
> Conform to the ISO 2011 C standard.
> @@ -2489,13 +2497,21 @@ C++ ObjC++
> Conform to the ISO 2020 C++ standard with GNU extensions (experimental and incomplete support).
>
> std=gnu++2b
> -C++ ObjC++ Alias(std=gnu++23)
> +C++ ObjC++ Alias(std=gnu++23) Undocumented
> Conform to the ISO 2023 C++ draft standard with GNU extensions (experimental and incomplete support).
>
> std=gnu++23
> -C++ ObjC++ Undocumented
> +C++ ObjC++
> Conform to the ISO 2023 C++ draft standard with GNU extensions (experimental and incomplete support).
>
> +std=gnu++2c
> +C++ ObjC++ Alias(std=gnu++26) Undocumented
> +Conform to the ISO 2026 C++ draft standard with GNU extensions (experimental and incomplete support).
> +
> +std=gnu++26
> +C++ ObjC++
> +Conform to the ISO 2026 C++ draft standard with GNU extensions (experimental and incomplete support).
> +
> std=gnu11
> C ObjC
> Conform to the ISO 2011 C standard with GNU extensions.
> diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi
> index b0a2ce3ac6b..e3e5d2af042 100644
> --- a/gcc/doc/cpp.texi
> +++ b/gcc/doc/cpp.texi
> @@ -1911,6 +1911,11 @@ selected, the value of the macro is
> or an unspecified value strictly larger than @code{202002L} for the
> experimental languages enabled by @option{-std=c++23} and
> @option{-std=gnu++23}.
> +Similarly, the value of the macro is an unspecified value strictly
> +larger than @code{202002L} (and at the same time strictly larger than
> +the unspecified value defined for @option{-std=c++23} above) for the
> +experimental languages enabled by @option{-std=c++26} and
> +@option{-std=gnu++26}.
>
> @item __OBJC__
> This macro is defined, with value 1, when the Objective-C compiler is in
> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> index fd4943bf317..efcf3bfb3d6 100644
> --- a/gcc/doc/invoke.texi
> +++ b/gcc/doc/invoke.texi
> @@ -2507,6 +2507,18 @@ change in incompatible ways in future releases.
> GNU dialect of @option{-std=c++2b}. Support is highly experimental,
> and will almost certainly change in incompatible ways in future
> releases.
> +
> +@item c++2c
> +@itemx c++26
> +The next revision of the ISO C++ standard, planned for
> +2026. Support is highly experimental, and will almost certainly
> +change in incompatible ways in future releases.
> +
> +@item gnu++2c
> +@itemx gnu++26
> +GNU dialect of @option{-std=c++2c}. Support is highly experimental,
> +and will almost certainly change in incompatible ways in future
> +releases.
> @end table
>
> @opindex aux-info
> diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
> index e70c47cec8d..9112fc0c64b 100644
> --- a/gcc/dwarf2out.cc
> +++ b/gcc/dwarf2out.cc
> @@ -25105,6 +25105,8 @@ static char *producer_string;
> static const char *
> highest_c_language (const char *lang1, const char *lang2)
> {
> + if (strcmp ("GNU C++26", lang1) == 0 || strcmp ("GNU C++26", lang2) == 0)
> + return "GNU C++26";
> if (strcmp ("GNU C++23", lang1) == 0 || strcmp ("GNU C++23", lang2) == 0)
> return "GNU C++23";
> if (strcmp ("GNU C++20", lang1) == 0 || strcmp ("GNU C++20", lang2) == 0)
> @@ -25215,7 +25217,8 @@ gen_compile_unit_die (const char *filename)
> language = DW_LANG_C_plus_plus_14;
> else if (strcmp (language_string, "GNU C++17") == 0
> || strcmp (language_string, "GNU C++20") == 0
> - || strcmp (language_string, "GNU C++23") == 0)
> + || strcmp (language_string, "GNU C++23") == 0
> + || strcmp (language_string, "GNU C++26") == 0)
> /* For now. */
> language = DW_LANG_C_plus_plus_14;
> }
> diff --git a/gcc/testsuite/g++.dg/cpp26/cplusplus.C b/gcc/testsuite/g++.dg/cpp26/cplusplus.C
> new file mode 100644
> index 00000000000..3027f9e711a
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp26/cplusplus.C
> @@ -0,0 +1,5 @@
> +// { dg-do compile }
> +// { dg-options "-std=c++26" }
> +
> +// TODO: Update once __cplusplus is defined for C++23.
> +static_assert(__cplusplus > 202002L);
> diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
> index d79ad4be105..c04db2be7f9 100644
> --- a/gcc/testsuite/lib/target-supports.exp
> +++ b/gcc/testsuite/lib/target-supports.exp
> @@ -10785,7 +10785,35 @@ proc check_effective_target_c++23_only { } {
> return 0
> }
> proc check_effective_target_c++23 { } {
> - return [check_effective_target_c++23_only]
> + if [check_effective_target_c++23_only] {
> + return 1
> + }
> + return [check_effective_target_c++26]
> +}
> +
> +proc check_effective_target_c++23_down { } {
> + if ![check_effective_target_c++] {
> + return 0
> + }
> + return [expr ![check_effective_target_c++26] ]
> +}
> +
> +proc check_effective_target_c++26_only { } {
> + global cxx_default
> + if ![check_effective_target_c++] {
> + return 0
> + }
> + if [check-flags { { } { } { -std=c++26 -std=gnu++26 -std=c++2c -std=gnu++2c } }] {
> + return 1
> + }
> + if { $cxx_default == "c++26" && [check-flags { { } { } { } { -std=* } }] } {
> + return 1
> + }
> + return 0
> +}
> +
> +proc check_effective_target_c++26 { } {
> + return [check_effective_target_c++26_only]
> }
>
> # Check for C++ Concepts support, i.e. -fconcepts flag.
> diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
> index d326f5aa316..aef703f8111 100644
> --- a/libcpp/include/cpplib.h
> +++ b/libcpp/include/cpplib.h
> @@ -174,7 +174,7 @@ enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_GNUC11, CLK_GNUC17, CLK_GNUC2X,
> CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX11, CLK_CXX11,
> CLK_GNUCXX14, CLK_CXX14, CLK_GNUCXX17, CLK_CXX17,
> CLK_GNUCXX20, CLK_CXX20, CLK_GNUCXX23, CLK_CXX23,
> - CLK_ASM};
> + CLK_GNUCXX26, CLK_CXX26, CLK_ASM};
>
> /* Payload of a NUMBER, STRING, CHAR or COMMENT token. */
> struct GTY(()) cpp_string {
> diff --git a/libcpp/init.cc b/libcpp/init.cc
> index c508f06112a..8ef8833e508 100644
> --- a/libcpp/init.cc
> +++ b/libcpp/init.cc
> @@ -127,6 +127,8 @@ static const struct lang_flags lang_defaults[] =
> /* CXX20 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1 },
> /* GNUCXX23 */ { 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
> /* CXX23 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
> + /* GNUCXX26 */ { 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
> + /* CXX26 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
> /* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
> };
>
> @@ -561,9 +563,14 @@ cpp_init_builtins (cpp_reader *pfile, int hosted)
>
> if (CPP_OPTION (pfile, cplusplus))
> {
> - /* C++23 is not yet a standard. For now, use an invalid
> - * year/month, 202100L, which is larger than 202002L. */
> - if (CPP_OPTION (pfile, lang) == CLK_CXX23
> + /* C++26 is not yet a standard. For now, use an invalid
> + year/month, 202600L, which is larger than 202100L. */
> + if (CPP_OPTION (pfile, lang) == CLK_CXX26
> + || CPP_OPTION (pfile, lang) == CLK_GNUCXX26)
> + _cpp_define_builtin (pfile, "__cplusplus 202600L");
> + /* C++23 is not yet a standard, either. For now, use an invalid
> + year/month, 202100L, which is larger than 202002L. */
> + else if (CPP_OPTION (pfile, lang) == CLK_CXX23
> || CPP_OPTION (pfile, lang) == CLK_GNUCXX23)
> _cpp_define_builtin (pfile, "__cplusplus 202100L");
> else if (CPP_OPTION (pfile, lang) == CLK_CXX20
>
> base-commit: 33ebb0dff9bb022f1e0709e0e73faabfc3df7931
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] c++: Add support for -std={c,gnu}++2{c,6}
2023-06-23 14:58 ` Jason Merrill
@ 2023-06-23 17:22 ` Marek Polacek
2023-06-23 19:47 ` Jason Merrill
0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2023-06-23 17:22 UTC (permalink / raw)
To: Jason Merrill; +Cc: GCC Patches
On Fri, Jun 23, 2023 at 10:58:54AM -0400, Jason Merrill wrote:
> On 6/22/23 20:25, Marek Polacek wrote:
> > It seems prudent to add C++26 now that the first C++26 papers have been
> > approved. I followed commit r11-6920 as well as r8-3237.
> >
> > I was puzzled to see that -std=c++23 was marked Undocumented but
> > -std=c++2b wasn't. I think it should be the other way round, like
> > the earlier modes.
>
> I was leaving -std=c++23 undocumented until C++23 was finalized, which it
> now effectively is, so this change is good. Speaking of which, it looks
> like the final value for __cplusplus for C++23 is 202302L.
Ok. I've updated the code to reflect that.
> But similarly, I'd like to leave -std=c++26 undocumented for now.
Done.
> > As for __cplusplus, I've arbitrarily chosen 202600L:
>
> Our previous convention has been the year after the previous standard, so
> let's use 202400L.
Done.
Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
-- >8 --
It seems prudent to add C++26 now that the first C++26 papers have been
approved. I followed commit r11-6920 as well as r8-3237.
Since C++23 is essentially finished and its __cplusplus value has
settled to 202302L, I've updated cpp_init_builtins and marked
-std=c++2b Undocumented and made -std=c++23 no longer Undocumented.
As for __cplusplus, I've chosen 202400L:
$ xg++ -std=c++26 -dM -E -x c++ - < /dev/null | grep cplusplus
#define __cplusplus 202400L
I've verified the patch with a simple test, exercising the new
directives. Don't forget to update your GXX_TESTSUITE_STDS!
This patch does not add -Wc++26-extensions.
gcc/c-family/ChangeLog:
* c-common.h (cxx_dialect): Add cxx26 as a dialect.
* c-opts.cc (set_std_cxx26): New.
(c_common_handle_option): Set options when -std={c,gnu}++2{c,6} is
enabled.
(c_common_post_options): Adjust comments.
* c.opt: Add options for -std=c++26, std=c++2c, -std=gnu++26,
and -std=gnu++2c.
(std=c++2b): Mark as Undocumented.
(std=c++23): No longer Undocumented.
gcc/ChangeLog:
* doc/cpp.texi (__cplusplus): Document value for -std=c++26 and
-std=gnu++26. Document that for C++23, its value is 202302L.
* doc/invoke.texi: Document -std=c++26 and -std=gnu++26.
* dwarf2out.cc (highest_c_language): Handle GNU C++26.
(gen_compile_unit_die): Likewise.
libcpp/ChangeLog:
* include/cpplib.h (c_lang): Add CXX26 and GNUCXX26.
* init.cc (lang_defaults): Add rows for CXX26 and GNUCXX26.
(cpp_init_builtins): Set __cplusplus to 202400L for C++26.
Set __cplusplus to 202302L for C++23.
gcc/testsuite/ChangeLog:
* lib/target-supports.exp (check_effective_target_c++23): Return
1 also if check_effective_target_c++26.
(check_effective_target_c++23_down): New.
(check_effective_target_c++26_only): New.
(check_effective_target_c++26): New.
* g++.dg/cpp23/cplusplus.C: Adjust expected value.
* g++.dg/cpp26/cplusplus.C: New test.
---
gcc/c-family/c-common.h | 4 +++-
gcc/c-family/c-opts.cc | 28 +++++++++++++++++++++++-
gcc/c-family/c.opt | 24 +++++++++++++++++----
gcc/doc/cpp.texi | 7 +++---
gcc/doc/invoke.texi | 12 +++++++++++
gcc/dwarf2out.cc | 5 ++++-
gcc/testsuite/g++.dg/cpp23/cplusplus.C | 2 +-
gcc/testsuite/g++.dg/cpp26/cplusplus.C | 3 +++
gcc/testsuite/lib/target-supports.exp | 30 +++++++++++++++++++++++++-
libcpp/include/cpplib.h | 2 +-
libcpp/init.cc | 13 +++++++----
11 files changed, 113 insertions(+), 17 deletions(-)
create mode 100644 gcc/testsuite/g++.dg/cpp26/cplusplus.C
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
index 336a09f4a40..b5ef5ff6b2c 100644
--- a/gcc/c-family/c-common.h
+++ b/gcc/c-family/c-common.h
@@ -740,7 +740,9 @@ enum cxx_dialect {
/* C++20 */
cxx20,
/* C++23 */
- cxx23
+ cxx23,
+ /* C++26 */
+ cxx26
};
/* The C++ dialect being used. C++98 is the default. */
diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
index c68a2a27469..af19140e382 100644
--- a/gcc/c-family/c-opts.cc
+++ b/gcc/c-family/c-opts.cc
@@ -111,6 +111,7 @@ static void set_std_cxx14 (int);
static void set_std_cxx17 (int);
static void set_std_cxx20 (int);
static void set_std_cxx23 (int);
+static void set_std_cxx26 (int);
static void set_std_c89 (int, int);
static void set_std_c99 (int);
static void set_std_c11 (int);
@@ -663,6 +664,12 @@ c_common_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
set_std_cxx23 (code == OPT_std_c__23 /* ISO */);
break;
+ case OPT_std_c__26:
+ case OPT_std_gnu__26:
+ if (!preprocessing_asm_p)
+ set_std_cxx26 (code == OPT_std_c__26 /* ISO */);
+ break;
+
case OPT_std_c90:
case OPT_std_iso9899_199409:
if (!preprocessing_asm_p)
@@ -1032,7 +1039,8 @@ c_common_post_options (const char **pfilename)
warn_narrowing = 1;
/* Unless -f{,no-}ext-numeric-literals has been used explicitly,
- for -std=c++{11,14,17,20,23} default to -fno-ext-numeric-literals. */
+ for -std=c++{11,14,17,20,23,26} default to
+ -fno-ext-numeric-literals. */
if (flag_iso && !OPTION_SET_P (flag_ext_numeric_literals))
cpp_opts->ext_numeric_literals = 0;
}
@@ -1820,6 +1828,24 @@ set_std_cxx23 (int iso)
lang_hooks.name = "GNU C++23";
}
+/* Set the C++ 2026 standard (without GNU extensions if ISO). */
+static void
+set_std_cxx26 (int iso)
+{
+ cpp_set_lang (parse_in, iso ? CLK_CXX26: CLK_GNUCXX26);
+ flag_no_gnu_keywords = iso;
+ flag_no_nonansi_builtin = iso;
+ flag_iso = iso;
+ /* C++26 includes the C11 standard library. */
+ flag_isoc94 = 1;
+ flag_isoc99 = 1;
+ flag_isoc11 = 1;
+ /* C++26 includes coroutines. */
+ flag_coroutines = true;
+ cxx_dialect = cxx26;
+ lang_hooks.name = "GNU C++26";
+}
+
/* Args to -d specify what to dump. Silently ignore
unrecognized options; they may be aimed at toplev.cc. */
static void
diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
index 0930a3c0422..c5160918d9a 100644
--- a/gcc/c-family/c.opt
+++ b/gcc/c-family/c.opt
@@ -2403,13 +2403,21 @@ C++ ObjC++
Conform to the ISO 2020 C++ standard (experimental and incomplete support).
std=c++2b
-C++ ObjC++ Alias(std=c++23)
+C++ ObjC++ Alias(std=c++23) Undocumented
Conform to the ISO 2023 C++ draft standard (experimental and incomplete support).
std=c++23
-C++ ObjC++ Undocumented
+C++ ObjC++
Conform to the ISO 2023 C++ draft standard (experimental and incomplete support).
+std=c++2c
+C++ ObjC++ Alias(std=c++26)
+Conform to the ISO 2026 C++ draft standard (experimental and incomplete support).
+
+std=c++26
+C++ ObjC++ Undocumented
+Conform to the ISO 2026 C++ draft standard (experimental and incomplete support).
+
std=c11
C ObjC
Conform to the ISO 2011 C standard.
@@ -2489,13 +2497,21 @@ C++ ObjC++
Conform to the ISO 2020 C++ standard with GNU extensions (experimental and incomplete support).
std=gnu++2b
-C++ ObjC++ Alias(std=gnu++23)
+C++ ObjC++ Alias(std=gnu++23) Undocumented
Conform to the ISO 2023 C++ draft standard with GNU extensions (experimental and incomplete support).
std=gnu++23
-C++ ObjC++ Undocumented
+C++ ObjC++
Conform to the ISO 2023 C++ draft standard with GNU extensions (experimental and incomplete support).
+std=gnu++2c
+C++ ObjC++ Alias(std=gnu++26)
+Conform to the ISO 2026 C++ draft standard with GNU extensions (experimental and incomplete support).
+
+std=gnu++26
+C++ ObjC++ Undocumented
+Conform to the ISO 2026 C++ draft standard with GNU extensions (experimental and incomplete support).
+
std=gnu11
C ObjC
Conform to the ISO 2011 C standard with GNU extensions.
diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi
index b0a2ce3ac6b..3f492b33470 100644
--- a/gcc/doc/cpp.texi
+++ b/gcc/doc/cpp.texi
@@ -1908,9 +1908,10 @@ selected, the value of the macro is
@code{201402L} for the 2014 C++ standard,
@code{201703L} for the 2017 C++ standard,
@code{202002L} for the 2020 C++ standard,
-or an unspecified value strictly larger than @code{202002L} for the
-experimental languages enabled by @option{-std=c++23} and
-@option{-std=gnu++23}.
+@code{202302L} for the 2023 C++ standard,
+or an unspecified value strictly larger than @code{202302L} for the
+experimental languages enabled by @option{-std=c++26} and
+@option{-std=gnu++26}.
@item __OBJC__
This macro is defined, with value 1, when the Objective-C compiler is in
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index fd4943bf317..efcf3bfb3d6 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -2507,6 +2507,18 @@ change in incompatible ways in future releases.
GNU dialect of @option{-std=c++2b}. Support is highly experimental,
and will almost certainly change in incompatible ways in future
releases.
+
+@item c++2c
+@itemx c++26
+The next revision of the ISO C++ standard, planned for
+2026. Support is highly experimental, and will almost certainly
+change in incompatible ways in future releases.
+
+@item gnu++2c
+@itemx gnu++26
+GNU dialect of @option{-std=c++2c}. Support is highly experimental,
+and will almost certainly change in incompatible ways in future
+releases.
@end table
@opindex aux-info
diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index e70c47cec8d..9112fc0c64b 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -25105,6 +25105,8 @@ static char *producer_string;
static const char *
highest_c_language (const char *lang1, const char *lang2)
{
+ if (strcmp ("GNU C++26", lang1) == 0 || strcmp ("GNU C++26", lang2) == 0)
+ return "GNU C++26";
if (strcmp ("GNU C++23", lang1) == 0 || strcmp ("GNU C++23", lang2) == 0)
return "GNU C++23";
if (strcmp ("GNU C++20", lang1) == 0 || strcmp ("GNU C++20", lang2) == 0)
@@ -25215,7 +25217,8 @@ gen_compile_unit_die (const char *filename)
language = DW_LANG_C_plus_plus_14;
else if (strcmp (language_string, "GNU C++17") == 0
|| strcmp (language_string, "GNU C++20") == 0
- || strcmp (language_string, "GNU C++23") == 0)
+ || strcmp (language_string, "GNU C++23") == 0
+ || strcmp (language_string, "GNU C++26") == 0)
/* For now. */
language = DW_LANG_C_plus_plus_14;
}
diff --git a/gcc/testsuite/g++.dg/cpp23/cplusplus.C b/gcc/testsuite/g++.dg/cpp23/cplusplus.C
index 29a941bc758..ff331c2783d 100644
--- a/gcc/testsuite/g++.dg/cpp23/cplusplus.C
+++ b/gcc/testsuite/g++.dg/cpp23/cplusplus.C
@@ -1,4 +1,4 @@
// { dg-do compile }
// { dg-options "-std=c++23" }
-static_assert(__cplusplus > 202002L);
+static_assert(__cplusplus == 202302L);
diff --git a/gcc/testsuite/g++.dg/cpp26/cplusplus.C b/gcc/testsuite/g++.dg/cpp26/cplusplus.C
new file mode 100644
index 00000000000..08c502eb34a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp26/cplusplus.C
@@ -0,0 +1,3 @@
+// { dg-do compile { target c++26_only } }
+
+static_assert(__cplusplus > 202302L);
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index d79ad4be105..c04db2be7f9 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -10785,7 +10785,35 @@ proc check_effective_target_c++23_only { } {
return 0
}
proc check_effective_target_c++23 { } {
- return [check_effective_target_c++23_only]
+ if [check_effective_target_c++23_only] {
+ return 1
+ }
+ return [check_effective_target_c++26]
+}
+
+proc check_effective_target_c++23_down { } {
+ if ![check_effective_target_c++] {
+ return 0
+ }
+ return [expr ![check_effective_target_c++26] ]
+}
+
+proc check_effective_target_c++26_only { } {
+ global cxx_default
+ if ![check_effective_target_c++] {
+ return 0
+ }
+ if [check-flags { { } { } { -std=c++26 -std=gnu++26 -std=c++2c -std=gnu++2c } }] {
+ return 1
+ }
+ if { $cxx_default == "c++26" && [check-flags { { } { } { } { -std=* } }] } {
+ return 1
+ }
+ return 0
+}
+
+proc check_effective_target_c++26 { } {
+ return [check_effective_target_c++26_only]
}
# Check for C++ Concepts support, i.e. -fconcepts flag.
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
index d326f5aa316..aef703f8111 100644
--- a/libcpp/include/cpplib.h
+++ b/libcpp/include/cpplib.h
@@ -174,7 +174,7 @@ enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_GNUC11, CLK_GNUC17, CLK_GNUC2X,
CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX11, CLK_CXX11,
CLK_GNUCXX14, CLK_CXX14, CLK_GNUCXX17, CLK_CXX17,
CLK_GNUCXX20, CLK_CXX20, CLK_GNUCXX23, CLK_CXX23,
- CLK_ASM};
+ CLK_GNUCXX26, CLK_CXX26, CLK_ASM};
/* Payload of a NUMBER, STRING, CHAR or COMMENT token. */
struct GTY(()) cpp_string {
diff --git a/libcpp/init.cc b/libcpp/init.cc
index c508f06112a..693feaa31ed 100644
--- a/libcpp/init.cc
+++ b/libcpp/init.cc
@@ -127,6 +127,8 @@ static const struct lang_flags lang_defaults[] =
/* CXX20 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1 },
/* GNUCXX23 */ { 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
/* CXX23 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
+ /* GNUCXX26 */ { 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
+ /* CXX26 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
/* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
@@ -561,11 +563,14 @@ cpp_init_builtins (cpp_reader *pfile, int hosted)
if (CPP_OPTION (pfile, cplusplus))
{
- /* C++23 is not yet a standard. For now, use an invalid
- * year/month, 202100L, which is larger than 202002L. */
- if (CPP_OPTION (pfile, lang) == CLK_CXX23
+ /* C++26 is not yet a standard. For now, use an invalid
+ year/month, 202400L, which is larger than 202302L. */
+ if (CPP_OPTION (pfile, lang) == CLK_CXX26
+ || CPP_OPTION (pfile, lang) == CLK_GNUCXX26)
+ _cpp_define_builtin (pfile, "__cplusplus 202400L");
+ else if (CPP_OPTION (pfile, lang) == CLK_CXX23
|| CPP_OPTION (pfile, lang) == CLK_GNUCXX23)
- _cpp_define_builtin (pfile, "__cplusplus 202100L");
+ _cpp_define_builtin (pfile, "__cplusplus 202302L");
else if (CPP_OPTION (pfile, lang) == CLK_CXX20
|| CPP_OPTION (pfile, lang) == CLK_GNUCXX20)
_cpp_define_builtin (pfile, "__cplusplus 202002L");
base-commit: 370de1488a9a49956c47e5ec8c8f1489b4314a34
--
2.41.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] c++: Add support for -std={c,gnu}++2{c,6}
2023-06-23 17:22 ` [PATCH v2] " Marek Polacek
@ 2023-06-23 19:47 ` Jason Merrill
0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2023-06-23 19:47 UTC (permalink / raw)
To: Marek Polacek; +Cc: GCC Patches
On 6/23/23 13:22, Marek Polacek wrote:
> On Fri, Jun 23, 2023 at 10:58:54AM -0400, Jason Merrill wrote:
>> On 6/22/23 20:25, Marek Polacek wrote:
>>> It seems prudent to add C++26 now that the first C++26 papers have been
>>> approved. I followed commit r11-6920 as well as r8-3237.
>>>
>>> I was puzzled to see that -std=c++23 was marked Undocumented but
>>> -std=c++2b wasn't. I think it should be the other way round, like
>>> the earlier modes.
>>
>> I was leaving -std=c++23 undocumented until C++23 was finalized, which it
>> now effectively is, so this change is good. Speaking of which, it looks
>> like the final value for __cplusplus for C++23 is 202302L.
>
> Ok. I've updated the code to reflect that.
>
>> But similarly, I'd like to leave -std=c++26 undocumented for now.
>
> Done.
>
>>> As for __cplusplus, I've arbitrarily chosen 202600L:
>>
>> Our previous convention has been the year after the previous standard, so
>> let's use 202400L.
>
> Done.
>
> Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?
OK, thanks.
> -- >8 --
> It seems prudent to add C++26 now that the first C++26 papers have been
> approved. I followed commit r11-6920 as well as r8-3237.
>
> Since C++23 is essentially finished and its __cplusplus value has
> settled to 202302L, I've updated cpp_init_builtins and marked
> -std=c++2b Undocumented and made -std=c++23 no longer Undocumented.
>
> As for __cplusplus, I've chosen 202400L:
>
> $ xg++ -std=c++26 -dM -E -x c++ - < /dev/null | grep cplusplus
> #define __cplusplus 202400L
>
> I've verified the patch with a simple test, exercising the new
> directives. Don't forget to update your GXX_TESTSUITE_STDS!
>
> This patch does not add -Wc++26-extensions.
>
> gcc/c-family/ChangeLog:
>
> * c-common.h (cxx_dialect): Add cxx26 as a dialect.
> * c-opts.cc (set_std_cxx26): New.
> (c_common_handle_option): Set options when -std={c,gnu}++2{c,6} is
> enabled.
> (c_common_post_options): Adjust comments.
> * c.opt: Add options for -std=c++26, std=c++2c, -std=gnu++26,
> and -std=gnu++2c.
> (std=c++2b): Mark as Undocumented.
> (std=c++23): No longer Undocumented.
>
> gcc/ChangeLog:
>
> * doc/cpp.texi (__cplusplus): Document value for -std=c++26 and
> -std=gnu++26. Document that for C++23, its value is 202302L.
> * doc/invoke.texi: Document -std=c++26 and -std=gnu++26.
> * dwarf2out.cc (highest_c_language): Handle GNU C++26.
> (gen_compile_unit_die): Likewise.
>
> libcpp/ChangeLog:
>
> * include/cpplib.h (c_lang): Add CXX26 and GNUCXX26.
> * init.cc (lang_defaults): Add rows for CXX26 and GNUCXX26.
> (cpp_init_builtins): Set __cplusplus to 202400L for C++26.
> Set __cplusplus to 202302L for C++23.
>
> gcc/testsuite/ChangeLog:
>
> * lib/target-supports.exp (check_effective_target_c++23): Return
> 1 also if check_effective_target_c++26.
> (check_effective_target_c++23_down): New.
> (check_effective_target_c++26_only): New.
> (check_effective_target_c++26): New.
> * g++.dg/cpp23/cplusplus.C: Adjust expected value.
> * g++.dg/cpp26/cplusplus.C: New test.
> ---
> gcc/c-family/c-common.h | 4 +++-
> gcc/c-family/c-opts.cc | 28 +++++++++++++++++++++++-
> gcc/c-family/c.opt | 24 +++++++++++++++++----
> gcc/doc/cpp.texi | 7 +++---
> gcc/doc/invoke.texi | 12 +++++++++++
> gcc/dwarf2out.cc | 5 ++++-
> gcc/testsuite/g++.dg/cpp23/cplusplus.C | 2 +-
> gcc/testsuite/g++.dg/cpp26/cplusplus.C | 3 +++
> gcc/testsuite/lib/target-supports.exp | 30 +++++++++++++++++++++++++-
> libcpp/include/cpplib.h | 2 +-
> libcpp/init.cc | 13 +++++++----
> 11 files changed, 113 insertions(+), 17 deletions(-)
> create mode 100644 gcc/testsuite/g++.dg/cpp26/cplusplus.C
>
> diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h
> index 336a09f4a40..b5ef5ff6b2c 100644
> --- a/gcc/c-family/c-common.h
> +++ b/gcc/c-family/c-common.h
> @@ -740,7 +740,9 @@ enum cxx_dialect {
> /* C++20 */
> cxx20,
> /* C++23 */
> - cxx23
> + cxx23,
> + /* C++26 */
> + cxx26
> };
>
> /* The C++ dialect being used. C++98 is the default. */
> diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc
> index c68a2a27469..af19140e382 100644
> --- a/gcc/c-family/c-opts.cc
> +++ b/gcc/c-family/c-opts.cc
> @@ -111,6 +111,7 @@ static void set_std_cxx14 (int);
> static void set_std_cxx17 (int);
> static void set_std_cxx20 (int);
> static void set_std_cxx23 (int);
> +static void set_std_cxx26 (int);
> static void set_std_c89 (int, int);
> static void set_std_c99 (int);
> static void set_std_c11 (int);
> @@ -663,6 +664,12 @@ c_common_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
> set_std_cxx23 (code == OPT_std_c__23 /* ISO */);
> break;
>
> + case OPT_std_c__26:
> + case OPT_std_gnu__26:
> + if (!preprocessing_asm_p)
> + set_std_cxx26 (code == OPT_std_c__26 /* ISO */);
> + break;
> +
> case OPT_std_c90:
> case OPT_std_iso9899_199409:
> if (!preprocessing_asm_p)
> @@ -1032,7 +1039,8 @@ c_common_post_options (const char **pfilename)
> warn_narrowing = 1;
>
> /* Unless -f{,no-}ext-numeric-literals has been used explicitly,
> - for -std=c++{11,14,17,20,23} default to -fno-ext-numeric-literals. */
> + for -std=c++{11,14,17,20,23,26} default to
> + -fno-ext-numeric-literals. */
> if (flag_iso && !OPTION_SET_P (flag_ext_numeric_literals))
> cpp_opts->ext_numeric_literals = 0;
> }
> @@ -1820,6 +1828,24 @@ set_std_cxx23 (int iso)
> lang_hooks.name = "GNU C++23";
> }
>
> +/* Set the C++ 2026 standard (without GNU extensions if ISO). */
> +static void
> +set_std_cxx26 (int iso)
> +{
> + cpp_set_lang (parse_in, iso ? CLK_CXX26: CLK_GNUCXX26);
> + flag_no_gnu_keywords = iso;
> + flag_no_nonansi_builtin = iso;
> + flag_iso = iso;
> + /* C++26 includes the C11 standard library. */
> + flag_isoc94 = 1;
> + flag_isoc99 = 1;
> + flag_isoc11 = 1;
> + /* C++26 includes coroutines. */
> + flag_coroutines = true;
> + cxx_dialect = cxx26;
> + lang_hooks.name = "GNU C++26";
> +}
> +
> /* Args to -d specify what to dump. Silently ignore
> unrecognized options; they may be aimed at toplev.cc. */
> static void
> diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
> index 0930a3c0422..c5160918d9a 100644
> --- a/gcc/c-family/c.opt
> +++ b/gcc/c-family/c.opt
> @@ -2403,13 +2403,21 @@ C++ ObjC++
> Conform to the ISO 2020 C++ standard (experimental and incomplete support).
>
> std=c++2b
> -C++ ObjC++ Alias(std=c++23)
> +C++ ObjC++ Alias(std=c++23) Undocumented
> Conform to the ISO 2023 C++ draft standard (experimental and incomplete support).
>
> std=c++23
> -C++ ObjC++ Undocumented
> +C++ ObjC++
> Conform to the ISO 2023 C++ draft standard (experimental and incomplete support).
>
> +std=c++2c
> +C++ ObjC++ Alias(std=c++26)
> +Conform to the ISO 2026 C++ draft standard (experimental and incomplete support).
> +
> +std=c++26
> +C++ ObjC++ Undocumented
> +Conform to the ISO 2026 C++ draft standard (experimental and incomplete support).
> +
> std=c11
> C ObjC
> Conform to the ISO 2011 C standard.
> @@ -2489,13 +2497,21 @@ C++ ObjC++
> Conform to the ISO 2020 C++ standard with GNU extensions (experimental and incomplete support).
>
> std=gnu++2b
> -C++ ObjC++ Alias(std=gnu++23)
> +C++ ObjC++ Alias(std=gnu++23) Undocumented
> Conform to the ISO 2023 C++ draft standard with GNU extensions (experimental and incomplete support).
>
> std=gnu++23
> -C++ ObjC++ Undocumented
> +C++ ObjC++
> Conform to the ISO 2023 C++ draft standard with GNU extensions (experimental and incomplete support).
>
> +std=gnu++2c
> +C++ ObjC++ Alias(std=gnu++26)
> +Conform to the ISO 2026 C++ draft standard with GNU extensions (experimental and incomplete support).
> +
> +std=gnu++26
> +C++ ObjC++ Undocumented
> +Conform to the ISO 2026 C++ draft standard with GNU extensions (experimental and incomplete support).
> +
> std=gnu11
> C ObjC
> Conform to the ISO 2011 C standard with GNU extensions.
> diff --git a/gcc/doc/cpp.texi b/gcc/doc/cpp.texi
> index b0a2ce3ac6b..3f492b33470 100644
> --- a/gcc/doc/cpp.texi
> +++ b/gcc/doc/cpp.texi
> @@ -1908,9 +1908,10 @@ selected, the value of the macro is
> @code{201402L} for the 2014 C++ standard,
> @code{201703L} for the 2017 C++ standard,
> @code{202002L} for the 2020 C++ standard,
> -or an unspecified value strictly larger than @code{202002L} for the
> -experimental languages enabled by @option{-std=c++23} and
> -@option{-std=gnu++23}.
> +@code{202302L} for the 2023 C++ standard,
> +or an unspecified value strictly larger than @code{202302L} for the
> +experimental languages enabled by @option{-std=c++26} and
> +@option{-std=gnu++26}.
>
> @item __OBJC__
> This macro is defined, with value 1, when the Objective-C compiler is in
> diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
> index fd4943bf317..efcf3bfb3d6 100644
> --- a/gcc/doc/invoke.texi
> +++ b/gcc/doc/invoke.texi
> @@ -2507,6 +2507,18 @@ change in incompatible ways in future releases.
> GNU dialect of @option{-std=c++2b}. Support is highly experimental,
> and will almost certainly change in incompatible ways in future
> releases.
> +
> +@item c++2c
> +@itemx c++26
> +The next revision of the ISO C++ standard, planned for
> +2026. Support is highly experimental, and will almost certainly
> +change in incompatible ways in future releases.
> +
> +@item gnu++2c
> +@itemx gnu++26
> +GNU dialect of @option{-std=c++2c}. Support is highly experimental,
> +and will almost certainly change in incompatible ways in future
> +releases.
> @end table
>
> @opindex aux-info
> diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
> index e70c47cec8d..9112fc0c64b 100644
> --- a/gcc/dwarf2out.cc
> +++ b/gcc/dwarf2out.cc
> @@ -25105,6 +25105,8 @@ static char *producer_string;
> static const char *
> highest_c_language (const char *lang1, const char *lang2)
> {
> + if (strcmp ("GNU C++26", lang1) == 0 || strcmp ("GNU C++26", lang2) == 0)
> + return "GNU C++26";
> if (strcmp ("GNU C++23", lang1) == 0 || strcmp ("GNU C++23", lang2) == 0)
> return "GNU C++23";
> if (strcmp ("GNU C++20", lang1) == 0 || strcmp ("GNU C++20", lang2) == 0)
> @@ -25215,7 +25217,8 @@ gen_compile_unit_die (const char *filename)
> language = DW_LANG_C_plus_plus_14;
> else if (strcmp (language_string, "GNU C++17") == 0
> || strcmp (language_string, "GNU C++20") == 0
> - || strcmp (language_string, "GNU C++23") == 0)
> + || strcmp (language_string, "GNU C++23") == 0
> + || strcmp (language_string, "GNU C++26") == 0)
> /* For now. */
> language = DW_LANG_C_plus_plus_14;
> }
> diff --git a/gcc/testsuite/g++.dg/cpp23/cplusplus.C b/gcc/testsuite/g++.dg/cpp23/cplusplus.C
> index 29a941bc758..ff331c2783d 100644
> --- a/gcc/testsuite/g++.dg/cpp23/cplusplus.C
> +++ b/gcc/testsuite/g++.dg/cpp23/cplusplus.C
> @@ -1,4 +1,4 @@
> // { dg-do compile }
> // { dg-options "-std=c++23" }
>
> -static_assert(__cplusplus > 202002L);
> +static_assert(__cplusplus == 202302L);
> diff --git a/gcc/testsuite/g++.dg/cpp26/cplusplus.C b/gcc/testsuite/g++.dg/cpp26/cplusplus.C
> new file mode 100644
> index 00000000000..08c502eb34a
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cpp26/cplusplus.C
> @@ -0,0 +1,3 @@
> +// { dg-do compile { target c++26_only } }
> +
> +static_assert(__cplusplus > 202302L);
> diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
> index d79ad4be105..c04db2be7f9 100644
> --- a/gcc/testsuite/lib/target-supports.exp
> +++ b/gcc/testsuite/lib/target-supports.exp
> @@ -10785,7 +10785,35 @@ proc check_effective_target_c++23_only { } {
> return 0
> }
> proc check_effective_target_c++23 { } {
> - return [check_effective_target_c++23_only]
> + if [check_effective_target_c++23_only] {
> + return 1
> + }
> + return [check_effective_target_c++26]
> +}
> +
> +proc check_effective_target_c++23_down { } {
> + if ![check_effective_target_c++] {
> + return 0
> + }
> + return [expr ![check_effective_target_c++26] ]
> +}
> +
> +proc check_effective_target_c++26_only { } {
> + global cxx_default
> + if ![check_effective_target_c++] {
> + return 0
> + }
> + if [check-flags { { } { } { -std=c++26 -std=gnu++26 -std=c++2c -std=gnu++2c } }] {
> + return 1
> + }
> + if { $cxx_default == "c++26" && [check-flags { { } { } { } { -std=* } }] } {
> + return 1
> + }
> + return 0
> +}
> +
> +proc check_effective_target_c++26 { } {
> + return [check_effective_target_c++26_only]
> }
>
> # Check for C++ Concepts support, i.e. -fconcepts flag.
> diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h
> index d326f5aa316..aef703f8111 100644
> --- a/libcpp/include/cpplib.h
> +++ b/libcpp/include/cpplib.h
> @@ -174,7 +174,7 @@ enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_GNUC11, CLK_GNUC17, CLK_GNUC2X,
> CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX11, CLK_CXX11,
> CLK_GNUCXX14, CLK_CXX14, CLK_GNUCXX17, CLK_CXX17,
> CLK_GNUCXX20, CLK_CXX20, CLK_GNUCXX23, CLK_CXX23,
> - CLK_ASM};
> + CLK_GNUCXX26, CLK_CXX26, CLK_ASM};
>
> /* Payload of a NUMBER, STRING, CHAR or COMMENT token. */
> struct GTY(()) cpp_string {
> diff --git a/libcpp/init.cc b/libcpp/init.cc
> index c508f06112a..693feaa31ed 100644
> --- a/libcpp/init.cc
> +++ b/libcpp/init.cc
> @@ -127,6 +127,8 @@ static const struct lang_flags lang_defaults[] =
> /* CXX20 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1 },
> /* GNUCXX23 */ { 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
> /* CXX23 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
> + /* GNUCXX26 */ { 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
> + /* CXX26 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 1 },
> /* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
> };
>
> @@ -561,11 +563,14 @@ cpp_init_builtins (cpp_reader *pfile, int hosted)
>
> if (CPP_OPTION (pfile, cplusplus))
> {
> - /* C++23 is not yet a standard. For now, use an invalid
> - * year/month, 202100L, which is larger than 202002L. */
> - if (CPP_OPTION (pfile, lang) == CLK_CXX23
> + /* C++26 is not yet a standard. For now, use an invalid
> + year/month, 202400L, which is larger than 202302L. */
> + if (CPP_OPTION (pfile, lang) == CLK_CXX26
> + || CPP_OPTION (pfile, lang) == CLK_GNUCXX26)
> + _cpp_define_builtin (pfile, "__cplusplus 202400L");
> + else if (CPP_OPTION (pfile, lang) == CLK_CXX23
> || CPP_OPTION (pfile, lang) == CLK_GNUCXX23)
> - _cpp_define_builtin (pfile, "__cplusplus 202100L");
> + _cpp_define_builtin (pfile, "__cplusplus 202302L");
> else if (CPP_OPTION (pfile, lang) == CLK_CXX20
> || CPP_OPTION (pfile, lang) == CLK_GNUCXX20)
> _cpp_define_builtin (pfile, "__cplusplus 202002L");
>
> base-commit: 370de1488a9a49956c47e5ec8c8f1489b4314a34
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-06-23 19:47 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-23 0:25 [PATCH] c++: Add support for -std={c,gnu}++2{c,6} Marek Polacek
2023-06-23 14:58 ` Jason Merrill
2023-06-23 17:22 ` [PATCH v2] " Marek Polacek
2023-06-23 19:47 ` Jason Merrill
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).