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 202101L. diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 5541e694bb3..3a0d452b62b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2021-01-08 Paul Fee <paul.f....@gmail.com> + + 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. + 2021-01-06 Vladimir N. Makarov <vmaka...@redhat.com> PR rtl-optimization/97978 diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 654c2360085..9af4050fdc8 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,13 @@ +2021-01-08 Paul Fee <paul.f....@gmail.com> + + 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. + 2021-01-06 Martin Sebor <mse...@redhat.com> PR c++/95768 diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index a65c78f7240..cfa056a6e28 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? */ + 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..2612fac5a62 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++ 2020 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..3464d72591b 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -2214,6 +2214,11 @@ 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 +2297,11 @@ 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/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 856b05d5727..98b9b7ab848 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,17 @@ +2021-01-08 Paul Fee <paul.f....@gmail.com> + + 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. + 2021-01-06 Vladimir N. Makarov <vmaka...@redhat.com> PR rtl-optimization/97978 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/ChangeLog b/libcpp/ChangeLog index e78e9a6b26a..26bd505104f 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,10 @@ +2021-01-08 Paul Fee <paul.f....@gmail.com> + + 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 202101L for C++2b. + 2020-12-14 Nathan Sidwell <nat...@acm.org> * include/cpplib.h (struct cpp_macro): Add imported_p field. 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..dd8c66bf324 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 202101L"); + 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