diff options
author | Marek Polacek <polacek@redhat.com> | 2023-06-22 16:56:26 -0400 |
---|---|---|
committer | Marek Polacek <polacek@redhat.com> | 2023-06-23 16:46:29 -0400 |
commit | 5388a43f6a3f348929292998bd6d0c1da6f006de (patch) | |
tree | dcc504a25f4e8ac3aedc9274918abc05d37f6984 /gcc | |
parent | b7fc0a3be52f78100a270b63e7555fde078fd2e3 (diff) | |
download | gcc-5388a43f6a3f348929292998bd6d0c1da6f006de.zip gcc-5388a43f6a3f348929292998bd6d0c1da6f006de.tar.gz gcc-5388a43f6a3f348929292998bd6d0c1da6f006de.tar.bz2 |
c++: Add support for -std={c,gnu}++2{c,6}
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.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c-family/c-common.h | 4 | ||||
-rw-r--r-- | gcc/c-family/c-opts.cc | 28 | ||||
-rw-r--r-- | gcc/c-family/c.opt | 24 | ||||
-rw-r--r-- | gcc/doc/cpp.texi | 7 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 12 | ||||
-rw-r--r-- | gcc/dwarf2out.cc | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp23/cplusplus.C | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp26/cplusplus.C | 3 | ||||
-rw-r--r-- | gcc/testsuite/lib/target-supports.exp | 30 |
9 files changed, 103 insertions, 12 deletions
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 336a09f..b5ef5ff 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 c68a2a2..af19140 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 0930a3c04..c516091 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 b0a2ce3..3f492b3 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 fd4943b..efcf3bf 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 e70c47c..9112fc0 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 29a941b..ff331c2 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 0000000..08c502e --- /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 d79ad4b..c04db2b 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. |