Message ID | CAJYtZHnLkNgm5opWXpnJOYtbLxQK5OrhDyvJ=9y5sE0e8ZQjKA@mail.gmail.com |
---|---|
State | New |
Headers | show |
Series | [v2] c++: Add support for -std=c++2b | expand |
On 1/10/21 7:28 PM, Paul Fee via Gcc-patches wrote: > [PATCH v2] c++: Add support for -std=c++2b Thanks! This patch was corrupted by word wrap, so it won't apply; if you can't suppress word wrap in your mail client, please send the patch as an attachment instead. Also remember to use git gcc-verify before sending the patch. > Derived from the changes that added C++2a support in 2017. > https://gcc.gnu.org/g:026a79f70cf33f836ea5275eda72d4870a3041e5 > > No C++2b features are added here. > Use of -std=c++2b sets __cplusplus to 202100L. > > $ g++ -std=c++2b -dM -E -x c++ - < /dev/null | grep cplusplus > #define __cplusplus 202100L > > Changes since v1 (8th Jan 2021): > * As suggested by Jonathan Wakely: > __cplusplus set to 202100L rather than 202101L. Use of a non-existent date > helps indicate this is not a true standard, yet is a value greater > than 202002L. > * As suggested by Jakub Jelinek: > Fixed typos and formatting. > Added C++23 support to dwarf2out.c, including missing C++20 support > in highest_c_language. > * Regarding suggestion by Marek Polacek to refer to C++23 rather than C++2b. > Left the option as -std=c++2b for now. It may be premature to assume the next > version of the standard will be named C++23. Use of c++2b also reinforces > the experimental nature of GCC's C++23 implementation. Hmm, I don't think it's that premature; the C++ committee has been very serious about time-based releases every three years. I think it makes sense for the advertised flag to be c++2b, but let's also go ahead and add the c++23 flags as hidden, and use cxx23 internally. > gcc/ > > Add support for -std=c++2b > * doc/cpp.texi (__cplusplus): Document value for -std=c++2b > or -std=gnu++2b. > * doc/invoke.texi: Document -std=c++2b and -std=gnu++2b. > > gcc/c-family > > Add support for -std=c++2b > * c-common.h (cxx_dialect): Add cxx2b as a dialect. > * c.opt: Add options for -std=c++2b and -std=gnu++2b. > * c-opts.c (set_std_cxx2b): New. > (c_common_handle_option): Set options when -std=c++2b is enabled. > (c_common_post_options): Adjust comments. > (set_std_cxx20): Likewise. > * dwarf2out.c (highest_c_language): Recognise C++20 and C++23. > (gen_compile_unit_die): Recognise C++23. dwarf2out.c isn't in c-family. > gcc/testsuite > > Add support for -std=c++2b > * lib/target-supports.exp (check_effective_target_c++2a_only): > rename to check_effective_target_c++20_only. > (check_effective_target_c++2a): rename to check_effective_target_c++20. > (check_effective_target_c++20): Return 1 > if check_effective_target_c++20_only or > if check_effective_target_c++2b. > (check_effective_target_c++20_down): New. > (check_effective_target_c++2a_only): New. > (check_effective_target_c++2a): New. > * g++.dg/cpp2b/cplusplus.C: New. > > libcpp > Add support for -std=c++2b > * include/cpplib.h (c_lang): Add CXX2B and GNUCXX2B. > * init.c (lang_defaults): Add rows for CXX2B and GNUCXX2B. > (cpp_init_builtins): Set __cplusplus to 202100L for C++2b. > --- > gcc/c-family/c-common.h | 4 ++- > gcc/c-family/c-opts.c | 29 ++++++++++++++++++++++-- > gcc/c-family/c.opt | 8 ++++++ > gcc/doc/cpp.texi | 7 +++-- > gcc/doc/invoke.texi | 10 ++++++++ > gcc/dwarf2out.c | 7 +++++ > gcc/testsuite/g++.dg/cpp2b/cplusplus.C | 4 +++ > gcc/testsuite/lib/target-supports.exp | 39 +++++++++++++++++++++++---------- > libcpp/include/cpplib.h | 3 +- > libcpp/init.c | 7 +++++ > 10 files changed, 98 insertions(+), 20 deletions(-) > > diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h > index a65c78f7240..f562cdebf4c 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++2b (C++23?) */ > + cxx2b > }; > > /* 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 3cdf41bc6e2..15f120d475d 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_cxx2b (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__2b: > + case OPT_std_gnu__2b: > + if (!preprocessing_asm_p) > + set_std_cxx2b (code == OPT_std_c__2b /* 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,2b} 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++ 202b standard (without GNU extensions if ISO). */ > +static void > +set_std_cxx2b (int iso) > +{ > + cpp_set_lang (parse_in, iso ? CLK_CXX2B: CLK_GNUCXX2B); > + flag_no_gnu_keywords = iso; > + flag_no_nonansi_builtin = iso; > + flag_iso = iso; > + /* C++2b includes the C11 standard library. */ > + flag_isoc94 = 1; > + flag_isoc99 = 1; > + flag_isoc11 = 1; > + /* C++2b includes coroutines. */ > + flag_coroutines = true; > + cxx_dialect = cxx2b; > + lang_hooks.name = "GNU C++20"; /* Pretend C++20 until standardization. */ > +} > + > /* 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 1766364806e..273772a0cd5 100644 > --- a/gcc/c-family/c.opt > +++ b/gcc/c-family/c.opt > @@ -2214,6 +2214,10 @@ std=c++20 > C++ ObjC++ > Conform to the ISO 2020 C++ draft standard (experimental and > incomplete support). > > +std=c++2b > +C++ ObjC++ > +Conform to the ISO 2023(?) C++ draft standard (experimental and > incomplete support). > + > std=c11 > C ObjC > Conform to the ISO 2011 C standard. > @@ -2292,6 +2296,10 @@ 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++ > +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 25f2625d8bd..f801024affd 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++2b} and > +@option{-std=gnu++2b}. > > @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 226b8ade430..11a6e9a23c3 100644 > --- a/gcc/doc/invoke.texi > +++ b/gcc/doc/invoke.texi > @@ -2430,6 +2430,16 @@ 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 > +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 > +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 8b6890a5097..97df6604373 100644 > --- a/gcc/dwarf2out.c > +++ b/gcc/dwarf2out.c > @@ -24445,6 +24445,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) > @@ -24550,7 +24554,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/cpp2b/cplusplus.C > b/gcc/testsuite/g++.dg/cpp2b/cplusplus.C > new file mode 100644 > index 00000000000..615d9f081de > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2b/cplusplus.C > @@ -0,0 +1,4 @@ > +// { dg-do compile } > +// { dg-options "-std=c++2b" } > + > +static_assert(__cplusplus > 202002L); > diff --git a/gcc/testsuite/lib/target-supports.exp > b/gcc/testsuite/lib/target-supports.exp > index 5cf0f4218a6..31be4de12a5 100644 > --- a/gcc/testsuite/lib/target-supports.exp > +++ b/gcc/testsuite/lib/target-supports.exp > @@ -9434,7 +9434,6 @@ proc check_effective_target_c++14_only { } { > } > return 0 > } > - > proc check_effective_target_c++14 { } { > if [check_effective_target_c++14_only] { > return 1 > @@ -9475,7 +9474,6 @@ proc check_effective_target_c++17_only { } { > } > return 0 > } > - > proc check_effective_target_c++17 { } { > if [check_effective_target_c++17_only] { > return 1 > @@ -9489,12 +9487,12 @@ proc check_effective_target_c++17_down { } { > return [expr ![check_effective_target_c++2a] ] > } > > -proc check_effective_target_c++2a_only { } { > +proc check_effective_target_c++20_only { } { > global cxx_default > if ![check_effective_target_c++] { > return 0 > } > - if [check-flags { { } { } { -std=c++2a -std=gnu++2a -std=c++20 > -std=gnu++20 } }] { > + if [check-flags { { } { } { -std=c++20 -std=gnu++20 -std=c++2a > -std=gnu++2a } }] { > return 1 > } > if { $cxx_default == "c++20" && [check-flags { { } { } { } { > -std=* } }] } { > @@ -9502,18 +9500,37 @@ proc check_effective_target_c++2a_only { } { > } > return 0 > } > -proc check_effective_target_c++2a { } { > - return [check_effective_target_c++2a_only] > +proc check_effective_target_c++20 { } { > + if [check_effective_target_c++20_only] { > + return 1 > + } > + return [check_effective_target_c++2b] > } > - > -proc check_effective_target_c++20_only { } { > - return [check_effective_target_c++2a_only] > +proc check_effective_target_c++20_down { } { > + if ![check_effective_target_c++] { > + return 0 > + } > + return [expr ![check_effective_target_c++20] ] This should be !c++2b. > } > > -proc check_effective_target_c++20 { } { > - return [check_effective_target_c++2a] > +proc check_effective_target_c++2b_only { } { > + global cxx_default > + if ![check_effective_target_c++] { > + return 0 > + } > + if [check-flags { { } { } { -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++2b { } { > + return [check_effective_target_c++2b_only] > } > > + > # Check for C++ Concepts support, i.e. -fconcepts flag. > proc check_effective_target_concepts { } { > if [check_effective_target_c++2a] { > diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h > index bcc50ba45f6..c213fbac0b1 100644 > --- a/libcpp/include/cpplib.h > +++ b/libcpp/include/cpplib.h > @@ -173,7 +173,8 @@ enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, > CLK_GNUC11, CLK_GNUC17, CLK_GNUC2X, > CLK_STDC2X, > CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX11, CLK_CXX11, > CLK_GNUCXX14, CLK_CXX14, CLK_GNUCXX17, CLK_CXX17, > - CLK_GNUCXX20, CLK_CXX20, CLK_ASM}; > + CLK_GNUCXX20, CLK_CXX20, CLK_GNUCXX2B, CLK_CXX2B, > + CLK_ASM}; > > /* Payload of a NUMBER, STRING, CHAR or COMMENT token. */ > struct GTY(()) cpp_string { > diff --git a/libcpp/init.c b/libcpp/init.c > index a5103c4d454..80543f90a51 100644 > --- a/libcpp/init.c > +++ b/libcpp/init.c > @@ -119,6 +119,8 @@ static const struct lang_flags lang_defaults[] = > /* CXX17 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, > 1, 0, 1, 0, 1, 0 }, > /* GNUCXX20 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, > 1, 0, 1, 1, 1, 0 }, > /* CXX20 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, > 1, 0, 1, 1, 1, 0 }, > + /* GNUCXX2B */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, > 1, 0, 1, 1, 1, 0 }, > + /* CXX2B */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, > 1, 0, 1, 1, 1, 0 }, > /* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, > 0, 0, 0, 0, 0, 0 } > }; > > @@ -540,7 +542,10 @@ cpp_init_builtins (cpp_reader *pfile, int hosted) > > if (CPP_OPTION (pfile, cplusplus)) > { > - if (CPP_OPTION (pfile, lang) == CLK_CXX20 > + if (CPP_OPTION (pfile, lang) == CLK_CXX2B > + || CPP_OPTION (pfile, lang) == CLK_GNUCXX2B) > + _cpp_define_builtin (pfile, "__cplusplus 202100L"); Let's add a comment here. > + else if (CPP_OPTION (pfile, lang) == CLK_CXX20 > || CPP_OPTION (pfile, lang) == CLK_GNUCXX20) > _cpp_define_builtin (pfile, "__cplusplus 202002L"); > else if (CPP_OPTION (pfile, lang) == CLK_CXX17 > Jason
On Tue, Jan 19, 2021 at 11:28 PM Jason Merrill <jason@redhat.com> wrote: > > On 1/10/21 7:28 PM, Paul Fee via Gcc-patches wrote: > > [PATCH v2] c++: Add support for -std=c++2b > > Thanks! > > This patch was corrupted by word wrap, so it won't apply; if you can't > suppress word wrap in your mail client, please send the patch as an > attachment instead. Seems that "Plain text mode" in gmail isn't plain enough. I'll use an attachment for patch v3. > > Also remember to use git gcc-verify before sending the patch. Thanks for the tip. It helps me learn the GCC patch posting process. > > > Derived from the changes that added C++2a support in 2017. > > https://gcc.gnu.org/g:026a79f70cf33f836ea5275eda72d4870a3041e5 > > > > No C++2b features are added here. > > Use of -std=c++2b sets __cplusplus to 202100L. > > > > $ g++ -std=c++2b -dM -E -x c++ - < /dev/null | grep cplusplus > > #define __cplusplus 202100L > > > > Changes since v1 (8th Jan 2021): > > * As suggested by Jonathan Wakely: > > __cplusplus set to 202100L rather than 202101L. Use of a non-existent date > > helps indicate this is not a true standard, yet is a value greater > > than 202002L. > > * As suggested by Jakub Jelinek: > > Fixed typos and formatting. > > Added C++23 support to dwarf2out.c, including missing C++20 support > > in highest_c_language. > > > * Regarding suggestion by Marek Polacek to refer to C++23 rather than C++2b. > > Left the option as -std=c++2b for now. It may be premature to assume the next > > version of the standard will be named C++23. Use of c++2b also reinforces > > the experimental nature of GCC's C++23 implementation. > > Hmm, I don't think it's that premature; the C++ committee has been very > serious about time-based releases every three years. I think it makes > sense for the advertised flag to be c++2b, but let's also go ahead and > add the c++23 flags as hidden, and use cxx23 internally. Ok, I'll change from only exposing -std=c++2b to the end goal of -std=c++23. You pointed out below a flaw in target-supports.exp. Checking "make check-c++", I found that I'd also broken many tests while adjusting c++2a to be c++20. I'll take the 2a->20 change out of this patch. It can be in a separate patch. Seeing the cost of changing from "2a" to "20", I'll post up patch v3 with support for -std=c++23 so that a "2b->23" change isn't needed in a few years. GCC's C++23 will still be experimental, despite the flag be -std=c++23. > > > gcc/ > > > > Add support for -std=c++2b > > * doc/cpp.texi (__cplusplus): Document value for -std=c++2b > > or -std=gnu++2b. > > * doc/invoke.texi: Document -std=c++2b and -std=gnu++2b. > > > > gcc/c-family > > > > Add support for -std=c++2b > > * c-common.h (cxx_dialect): Add cxx2b as a dialect. > > * c.opt: Add options for -std=c++2b and -std=gnu++2b. > > * c-opts.c (set_std_cxx2b): New. > > (c_common_handle_option): Set options when -std=c++2b is enabled. > > (c_common_post_options): Adjust comments. > > (set_std_cxx20): Likewise. > > * dwarf2out.c (highest_c_language): Recognise C++20 and C++23. > > (gen_compile_unit_die): Recognise C++23. > > dwarf2out.c isn't in c-family. > > > gcc/testsuite > > > > Add support for -std=c++2b > > * lib/target-supports.exp (check_effective_target_c++2a_only): > > rename to check_effective_target_c++20_only. > > (check_effective_target_c++2a): rename to check_effective_target_c++20. > > (check_effective_target_c++20): Return 1 > > if check_effective_target_c++20_only or > > if check_effective_target_c++2b. > > (check_effective_target_c++20_down): New. > > (check_effective_target_c++2a_only): New. > > (check_effective_target_c++2a): New. > > * g++.dg/cpp2b/cplusplus.C: New. > > > > libcpp > > Add support for -std=c++2b > > * include/cpplib.h (c_lang): Add CXX2B and GNUCXX2B. > > * init.c (lang_defaults): Add rows for CXX2B and GNUCXX2B. > > (cpp_init_builtins): Set __cplusplus to 202100L for C++2b. > > --- > > gcc/c-family/c-common.h | 4 ++- > > gcc/c-family/c-opts.c | 29 ++++++++++++++++++++++-- > > gcc/c-family/c.opt | 8 ++++++ > > gcc/doc/cpp.texi | 7 +++-- > > gcc/doc/invoke.texi | 10 ++++++++ > > gcc/dwarf2out.c | 7 +++++ > > gcc/testsuite/g++.dg/cpp2b/cplusplus.C | 4 +++ > > gcc/testsuite/lib/target-supports.exp | 39 +++++++++++++++++++++++---------- > > libcpp/include/cpplib.h | 3 +- > > libcpp/init.c | 7 +++++ > > 10 files changed, 98 insertions(+), 20 deletions(-) > > > > diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h > > index a65c78f7240..f562cdebf4c 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++2b (C++23?) */ > > + cxx2b > > }; > > > > /* 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 3cdf41bc6e2..15f120d475d 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_cxx2b (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__2b: > > + case OPT_std_gnu__2b: > > + if (!preprocessing_asm_p) > > + set_std_cxx2b (code == OPT_std_c__2b /* 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,2b} 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++ 202b standard (without GNU extensions if ISO). */ > > +static void > > +set_std_cxx2b (int iso) > > +{ > > + cpp_set_lang (parse_in, iso ? CLK_CXX2B: CLK_GNUCXX2B); > > + flag_no_gnu_keywords = iso; > > + flag_no_nonansi_builtin = iso; > > + flag_iso = iso; > > + /* C++2b includes the C11 standard library. */ > > + flag_isoc94 = 1; > > + flag_isoc99 = 1; > > + flag_isoc11 = 1; > > + /* C++2b includes coroutines. */ > > + flag_coroutines = true; > > + cxx_dialect = cxx2b; > > + lang_hooks.name = "GNU C++20"; /* Pretend C++20 until standardization. */ > > +} > > + > > /* 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 1766364806e..273772a0cd5 100644 > > --- a/gcc/c-family/c.opt > > +++ b/gcc/c-family/c.opt > > @@ -2214,6 +2214,10 @@ std=c++20 > > C++ ObjC++ > > Conform to the ISO 2020 C++ draft standard (experimental and > > incomplete support). > > > > +std=c++2b > > +C++ ObjC++ > > +Conform to the ISO 2023(?) C++ draft standard (experimental and > > incomplete support). > > + > > std=c11 > > C ObjC > > Conform to the ISO 2011 C standard. > > @@ -2292,6 +2296,10 @@ 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++ > > +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 25f2625d8bd..f801024affd 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++2b} and > > +@option{-std=gnu++2b}. > > > > @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 226b8ade430..11a6e9a23c3 100644 > > --- a/gcc/doc/invoke.texi > > +++ b/gcc/doc/invoke.texi > > @@ -2430,6 +2430,16 @@ 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 > > +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 > > +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 8b6890a5097..97df6604373 100644 > > --- a/gcc/dwarf2out.c > > +++ b/gcc/dwarf2out.c > > @@ -24445,6 +24445,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) > > @@ -24550,7 +24554,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/cpp2b/cplusplus.C > > b/gcc/testsuite/g++.dg/cpp2b/cplusplus.C > > new file mode 100644 > > index 00000000000..615d9f081de > > --- /dev/null > > +++ b/gcc/testsuite/g++.dg/cpp2b/cplusplus.C > > @@ -0,0 +1,4 @@ > > +// { dg-do compile } > > +// { dg-options "-std=c++2b" } > > + > > +static_assert(__cplusplus > 202002L); > > diff --git a/gcc/testsuite/lib/target-supports.exp > > b/gcc/testsuite/lib/target-supports.exp > > index 5cf0f4218a6..31be4de12a5 100644 > > --- a/gcc/testsuite/lib/target-supports.exp > > +++ b/gcc/testsuite/lib/target-supports.exp > > @@ -9434,7 +9434,6 @@ proc check_effective_target_c++14_only { } { > > } > > return 0 > > } > > - > > proc check_effective_target_c++14 { } { > > if [check_effective_target_c++14_only] { > > return 1 > > @@ -9475,7 +9474,6 @@ proc check_effective_target_c++17_only { } { > > } > > return 0 > > } > > - > > proc check_effective_target_c++17 { } { > > if [check_effective_target_c++17_only] { > > return 1 > > @@ -9489,12 +9487,12 @@ proc check_effective_target_c++17_down { } { > > return [expr ![check_effective_target_c++2a] ] > > } > > > > -proc check_effective_target_c++2a_only { } { > > +proc check_effective_target_c++20_only { } { > > global cxx_default > > if ![check_effective_target_c++] { > > return 0 > > } > > - if [check-flags { { } { } { -std=c++2a -std=gnu++2a -std=c++20 > > -std=gnu++20 } }] { > > + if [check-flags { { } { } { -std=c++20 -std=gnu++20 -std=c++2a > > -std=gnu++2a } }] { > > return 1 > > } > > if { $cxx_default == "c++20" && [check-flags { { } { } { } { > > -std=* } }] } { > > @@ -9502,18 +9500,37 @@ proc check_effective_target_c++2a_only { } { > > } > > return 0 > > } > > -proc check_effective_target_c++2a { } { > > - return [check_effective_target_c++2a_only] > > +proc check_effective_target_c++20 { } { > > + if [check_effective_target_c++20_only] { > > + return 1 > > + } > > + return [check_effective_target_c++2b] > > } > > - > > -proc check_effective_target_c++20_only { } { > > - return [check_effective_target_c++2a_only] > > +proc check_effective_target_c++20_down { } { > > + if ![check_effective_target_c++] { > > + return 0 > > + } > > + return [expr ![check_effective_target_c++20] ] > > This should be !c++2b. Indeed, thanks for highlighting my mistake. > > > } > > > > -proc check_effective_target_c++20 { } { > > - return [check_effective_target_c++2a] > > +proc check_effective_target_c++2b_only { } { > > + global cxx_default > > + if ![check_effective_target_c++] { > > + return 0 > > + } > > + if [check-flags { { } { } { -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++2b { } { > > + return [check_effective_target_c++2b_only] > > } > > > > + > > # Check for C++ Concepts support, i.e. -fconcepts flag. > > proc check_effective_target_concepts { } { > > if [check_effective_target_c++2a] { > > diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h > > index bcc50ba45f6..c213fbac0b1 100644 > > --- a/libcpp/include/cpplib.h > > +++ b/libcpp/include/cpplib.h > > @@ -173,7 +173,8 @@ enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, > > CLK_GNUC11, CLK_GNUC17, CLK_GNUC2X, > > CLK_STDC2X, > > CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX11, CLK_CXX11, > > CLK_GNUCXX14, CLK_CXX14, CLK_GNUCXX17, CLK_CXX17, > > - CLK_GNUCXX20, CLK_CXX20, CLK_ASM}; > > + CLK_GNUCXX20, CLK_CXX20, CLK_GNUCXX2B, CLK_CXX2B, > > + CLK_ASM}; > > > > /* Payload of a NUMBER, STRING, CHAR or COMMENT token. */ > > struct GTY(()) cpp_string { > > diff --git a/libcpp/init.c b/libcpp/init.c > > index a5103c4d454..80543f90a51 100644 > > --- a/libcpp/init.c > > +++ b/libcpp/init.c > > @@ -119,6 +119,8 @@ static const struct lang_flags lang_defaults[] = > > /* CXX17 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, > > 1, 0, 1, 0, 1, 0 }, > > /* GNUCXX20 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, > > 1, 0, 1, 1, 1, 0 }, > > /* CXX20 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, > > 1, 0, 1, 1, 1, 0 }, > > + /* GNUCXX2B */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, > > 1, 0, 1, 1, 1, 0 }, > > + /* CXX2B */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, > > 1, 0, 1, 1, 1, 0 }, > > /* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, > > 0, 0, 0, 0, 0, 0 } > > }; > > > > @@ -540,7 +542,10 @@ cpp_init_builtins (cpp_reader *pfile, int hosted) > > > > if (CPP_OPTION (pfile, cplusplus)) > > { > > - if (CPP_OPTION (pfile, lang) == CLK_CXX20 > > + if (CPP_OPTION (pfile, lang) == CLK_CXX2B > > + || CPP_OPTION (pfile, lang) == CLK_GNUCXX2B) > > + _cpp_define_builtin (pfile, "__cplusplus 202100L"); > > Let's add a comment here. > > > + else if (CPP_OPTION (pfile, lang) == CLK_CXX20 > > || CPP_OPTION (pfile, lang) == CLK_GNUCXX20) > > _cpp_define_builtin (pfile, "__cplusplus 202002L"); > > else if (CPP_OPTION (pfile, lang) == CLK_CXX17 > > > > Jason >
diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index a65c78f7240..f562cdebf4c 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++2b (C++23?) */ + cxx2b }; /* 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 3cdf41bc6e2..15f120d475d 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_cxx2b (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__2b: + case OPT_std_gnu__2b: + if (!preprocessing_asm_p) + set_std_cxx2b (code == OPT_std_c__2b /* 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,2b} 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++ 202b standard (without GNU extensions if ISO). */ +static void +set_std_cxx2b (int iso) +{ + cpp_set_lang (parse_in, iso ? CLK_CXX2B: CLK_GNUCXX2B); + flag_no_gnu_keywords = iso; + flag_no_nonansi_builtin = iso; + flag_iso = iso; + /* C++2b includes the C11 standard library. */ + flag_isoc94 = 1; + flag_isoc99 = 1; + flag_isoc11 = 1; + /* C++2b includes coroutines. */ + flag_coroutines = true; + cxx_dialect = cxx2b; + lang_hooks.name = "GNU C++20"; /* Pretend C++20 until standardization. */ +} + /* 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 1766364806e..273772a0cd5 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -2214,6 +2214,10 @@ std=c++20 C++ ObjC++ Conform to the ISO 2020 C++ draft standard (experimental and incomplete support). +std=c++2b +C++ ObjC++ +Conform to the ISO 2023(?) C++ draft standard (experimental and incomplete support). + std=c11 C ObjC Conform to the ISO 2011 C standard. @@ -2292,6 +2296,10 @@ 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++ +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 25f2625d8bd..f801024affd 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++2b} and +@option{-std=gnu++2b}. @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 226b8ade430..11a6e9a23c3 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -2430,6 +2430,16 @@ 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 +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 +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 8b6890a5097..97df6604373 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -24445,6 +24445,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) @@ -24550,7 +24554,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/cpp2b/cplusplus.C b/gcc/testsuite/g++.dg/cpp2b/cplusplus.C new file mode 100644 index 00000000000..615d9f081de --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2b/cplusplus.C @@ -0,0 +1,4 @@ +// { dg-do compile } +// { dg-options "-std=c++2b" } + +static_assert(__cplusplus > 202002L); diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index 5cf0f4218a6..31be4de12a5 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -9434,7 +9434,6 @@ proc check_effective_target_c++14_only { } { } return 0 } - proc check_effective_target_c++14 { } { if [check_effective_target_c++14_only] { return 1 @@ -9475,7 +9474,6 @@ proc check_effective_target_c++17_only { } { } return 0 } - proc check_effective_target_c++17 { } { if [check_effective_target_c++17_only] { return 1 @@ -9489,12 +9487,12 @@ proc check_effective_target_c++17_down { } { return [expr ![check_effective_target_c++2a] ] } -proc check_effective_target_c++2a_only { } { +proc check_effective_target_c++20_only { } { global cxx_default if ![check_effective_target_c++] { return 0 } - if [check-flags { { } { } { -std=c++2a -std=gnu++2a -std=c++20 -std=gnu++20 } }] { + if [check-flags { { } { } { -std=c++20 -std=gnu++20 -std=c++2a -std=gnu++2a } }] { return 1 } if { $cxx_default == "c++20" && [check-flags { { } { } { } { -std=* } }] } { @@ -9502,18 +9500,37 @@ proc check_effective_target_c++2a_only { } { } return 0 } -proc check_effective_target_c++2a { } { - return [check_effective_target_c++2a_only] +proc check_effective_target_c++20 { } { + if [check_effective_target_c++20_only] { + return 1 + } + return [check_effective_target_c++2b] } - -proc check_effective_target_c++20_only { } { - return [check_effective_target_c++2a_only] +proc check_effective_target_c++20_down { } { + if ![check_effective_target_c++] { + return 0 + } + return [expr ![check_effective_target_c++20] ] } -proc check_effective_target_c++20 { } { - return [check_effective_target_c++2a] +proc check_effective_target_c++2b_only { } { + global cxx_default + if ![check_effective_target_c++] { + return 0 + } + if [check-flags { { } { } { -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++2b { } { + return [check_effective_target_c++2b_only] } + # Check for C++ Concepts support, i.e. -fconcepts flag. proc check_effective_target_concepts { } { if [check_effective_target_c++2a] { diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index bcc50ba45f6..c213fbac0b1 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -173,7 +173,8 @@ enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_GNUC11, CLK_GNUC17, CLK_GNUC2X, CLK_STDC2X, CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX11, CLK_CXX11, CLK_GNUCXX14, CLK_CXX14, CLK_GNUCXX17, CLK_CXX17, - CLK_GNUCXX20, CLK_CXX20, CLK_ASM}; + CLK_GNUCXX20, CLK_CXX20, CLK_GNUCXX2B, CLK_CXX2B, + CLK_ASM}; /* Payload of a NUMBER, STRING, CHAR or COMMENT token. */ struct GTY(()) cpp_string { diff --git a/libcpp/init.c b/libcpp/init.c index a5103c4d454..80543f90a51 100644 --- a/libcpp/init.c +++ b/libcpp/init.c @@ -119,6 +119,8 @@ static const struct lang_flags lang_defaults[] = /* CXX17 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0 }, /* GNUCXX20 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0 }, /* CXX20 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0 }, + /* GNUCXX2B */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0 },