diff options
author | Paul Fee <paul.f.fee@gmail.com> | 2021-01-25 01:18:30 +0000 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2021-01-26 17:11:34 -0500 |
commit | 78739c2df788ee5c868d998a6333d453317d8711 (patch) | |
tree | 8b2912606a50618a4c05b01ed1712f18f2a6f1e1 /gcc | |
parent | 96253f069ead0736536de803b06a8053a85039a6 (diff) | |
download | gcc-78739c2df788ee5c868d998a6333d453317d8711.zip gcc-78739c2df788ee5c868d998a6333d453317d8711.tar.gz gcc-78739c2df788ee5c868d998a6333d453317d8711.tar.bz2 |
c++: Add support for -std=c++23
Derived from the changes that added C++2a support in 2017.
r8-3237-g026a79f70cf33f836ea5275eda72d4870a3041e5
No C++23 features are added here.
Use of -std=c++23 sets __cplusplus to 202100L.
$ g++ -std=c++23 -dM -E -x c++ - < /dev/null | grep cplusplus
#define __cplusplus 202100L
gcc/
* doc/cpp.texi (__cplusplus): Document value for -std=c++23
or -std=gnu++23.
* doc/invoke.texi: Document -std=c++23 and -std=gnu++23.
* dwarf2out.c (highest_c_language): Recognise C++20 and C++23.
(gen_compile_unit_die): Recognise C++23.
gcc/c-family/
* c-common.h (cxx_dialect): Add cxx23 as a dialect.
* c.opt: Add options for -std=c++23, std=c++2b, -std=gnu++23
and -std=gnu++2b
* c-opts.c (set_std_cxx23): New.
(c_common_handle_option): Set options when -std=c++23 is enabled.
(c_common_post_options): Adjust comments.
(set_std_cxx20): Likewise.
gcc/testsuite/
* lib/target-supports.exp (check_effective_target_c++2a):
Check for C++2a or C++23.
(check_effective_target_c++20_down): New.
(check_effective_target_c++23_only): New.
(check_effective_target_c++23): New.
* g++.dg/cpp23/cplusplus.C: New.
libcpp/
* include/cpplib.h (c_lang): Add CXX23 and GNUCXX23.
* init.c (lang_defaults): Add rows for CXX23 and GNUCXX23.
(cpp_init_builtins): Set __cplusplus to 202100L for C++23.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c-family/c-common.h | 4 | ||||
-rw-r--r-- | gcc/c-family/c-opts.c | 29 | ||||
-rw-r--r-- | gcc/c-family/c.opt | 18 | ||||
-rw-r--r-- | gcc/doc/cpp.texi | 7 | ||||
-rw-r--r-- | gcc/doc/invoke.texi | 12 | ||||
-rw-r--r-- | gcc/dwarf2out.c | 7 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp23/cplusplus.C | 4 | ||||
-rw-r--r-- | gcc/testsuite/lib/target-supports.exp | 28 |
8 files changed, 100 insertions, 9 deletions
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index a65c78f..f30b6c6 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -738,7 +738,9 @@ enum cxx_dialect { /* C++17 */ cxx17, /* C++20 */ - cxx20 + cxx20, + /* C++23 */ + cxx23 }; /* The C++ dialect being used. C++98 is the default. */ diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c index 3cdf41b..bd15b9c 100644 --- a/gcc/c-family/c-opts.c +++ b/gcc/c-family/c-opts.c @@ -113,6 +113,7 @@ static void set_std_cxx11 (int); 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_c89 (int, int); static void set_std_c99 (int); static void set_std_c11 (int); @@ -649,6 +650,12 @@ c_common_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value, set_std_cxx20 (code == OPT_std_c__20 /* ISO */); break; + case OPT_std_c__23: + case OPT_std_gnu__23: + if (!preprocessing_asm_p) + set_std_cxx23 (code == OPT_std_c__23 /* ISO */); + break; + case OPT_std_c90: case OPT_std_iso9899_199409: if (!preprocessing_asm_p) @@ -1019,7 +1026,7 @@ 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,2a} default to -fno-ext-numeric-literals. */ + for -std=c++{11,14,17,20,23} default to -fno-ext-numeric-literals. */ if (flag_iso && !global_options_set.x_flag_ext_numeric_literals) cpp_opts->ext_numeric_literals = 0; } @@ -1763,7 +1770,7 @@ set_std_cxx20 (int iso) flag_no_gnu_keywords = iso; flag_no_nonansi_builtin = iso; flag_iso = iso; - /* C++17 includes the C11 standard library. */ + /* C++20 includes the C11 standard library. */ flag_isoc94 = 1; flag_isoc99 = 1; flag_isoc11 = 1; @@ -1773,6 +1780,24 @@ set_std_cxx20 (int iso) lang_hooks.name = "GNU C++20"; } +/* Set the C++ 2023 standard (without GNU extensions if ISO). */ +static void +set_std_cxx23 (int iso) +{ + cpp_set_lang (parse_in, iso ? CLK_CXX23: CLK_GNUCXX23); + flag_no_gnu_keywords = iso; + flag_no_nonansi_builtin = iso; + flag_iso = iso; + /* C++23 includes the C11 standard library. */ + flag_isoc94 = 1; + flag_isoc99 = 1; + flag_isoc11 = 1; + /* C++23 includes coroutines. */ + flag_coroutines = true; + cxx_dialect = cxx23; + lang_hooks.name = "GNU C++23"; +} + /* Args to -d specify what to dump. Silently ignore unrecognized options; they may be aimed at toplev.c. */ static void diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 1766364..b729be7f 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -2214,6 +2214,14 @@ std=c++20 C++ ObjC++ Conform to the ISO 2020 C++ draft standard (experimental and incomplete support). +std=c++2b +C++ ObjC++ Alias(std=c++23) +Conform to the ISO 2020 C++ draft standard (experimental and incomplete support). + +std=c++23 +C++ ObjC++ Undocumented +Conform to the ISO 2023 C++ draft standard (experimental and incomplete support). + std=c11 C ObjC Conform to the ISO 2011 C standard. @@ -2285,13 +2293,21 @@ C++ ObjC++ Conform to the ISO 2017 C++ standard with GNU extensions. std=gnu++2a -C++ ObjC++ Alias(std=gnu++20) +C++ ObjC++ Alias(std=gnu++20) Undocumented Conform to the ISO 2020 C++ draft standard with GNU extensions (experimental and incomplete support). std=gnu++20 C++ ObjC++ Conform to the ISO 2020 C++ draft standard with GNU extensions (experimental and incomplete support). +std=gnu++2b +C++ ObjC++ Alias(std=gnu++23) +Conform to the ISO 2023 C++ draft standard with GNU extensions (experimental and incomplete support). + +std=gnu++23 +C++ ObjC++ Undocumented +Conform to the ISO 2023 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 25f2625..2c109bb 100644 --- a/gcc/doc/cpp.texi +++ b/gcc/doc/cpp.texi @@ -1907,9 +1907,10 @@ selected, the value of the macro is @code{201103L} for the 2011 C++ standard, @code{201402L} for the 2014 C++ standard, @code{201703L} for the 2017 C++ standard, -or an unspecified value strictly larger than @code{201703L} for the -experimental languages enabled by @option{-std=c++2a} and -@option{-std=gnu++2a}. +@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}. @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 34218a7..d9e49c4 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -2430,6 +2430,18 @@ GNU dialect of @option{-std=c++20}. Support is experimental, and could change in incompatible ways in future releases. The name @samp{gnu++2a} is deprecated. + +@item c++2b +@itemx c++23 +The next revision of the ISO C++ standard, planned for +2023. Support is highly experimental, and will almost certainly +change in incompatible ways in future releases. + +@item gnu++2b +@itemx gnu++23 +GNU dialect of @option{-std=c++2b}. Support is highly experimental, +and will almost certainly change in incompatible ways in future +releases. @end table @item -fgnu89-inline diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c index 2ec3449..0a61d14 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -24492,6 +24492,10 @@ static char *producer_string; static const char * highest_c_language (const char *lang1, const char *lang2) { + 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) + return "GNU C++20"; if (strcmp ("GNU C++17", lang1) == 0 || strcmp ("GNU C++17", lang2) == 0) return "GNU C++17"; if (strcmp ("GNU C++14", lang1) == 0 || strcmp ("GNU C++14", lang2) == 0) @@ -24597,7 +24601,8 @@ gen_compile_unit_die (const char *filename) else if (strcmp (language_string, "GNU C++14") == 0) 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++20") == 0 + || strcmp (language_string, "GNU C++23") == 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 new file mode 100644 index 0000000..29a941b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp23/cplusplus.C @@ -0,0 +1,4 @@ +// { dg-do compile } +// { dg-options "-std=c++23" } + +static_assert(__cplusplus > 202002L); diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index 0d351c8..af46c77 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -9503,7 +9503,10 @@ proc check_effective_target_c++2a_only { } { return 0 } proc check_effective_target_c++2a { } { - return [check_effective_target_c++2a_only] + if [check_effective_target_c++2a_only] { + return 1 + } + return [check_effective_target_c++23] } proc check_effective_target_c++20_only { } { @@ -9513,6 +9516,29 @@ proc check_effective_target_c++20_only { } { proc check_effective_target_c++20 { } { return [check_effective_target_c++2a] } +proc check_effective_target_c++20_down { } { + if ![check_effective_target_c++] { + return 0 + } + return [expr ![check_effective_target_c++23] ] +} + +proc check_effective_target_c++23_only { } { + global cxx_default + if ![check_effective_target_c++] { + return 0 + } + if [check-flags { { } { } { -std=c++23 -std=gnu++23 -std=c++2b -std=gnu++2b } }] { + return 1 + } + if { $cxx_default == "c++23" && [check-flags { { } { } { } { -std=* } }] } { + return 1 + } + return 0 +} +proc check_effective_target_c++23 { } { + return [check_effective_target_c++23_only] +} # Check for C++ Concepts support, i.e. -fconcepts flag. proc check_effective_target_concepts { } { |