From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1734) id 93C443858C2F; Fri, 23 Jun 2023 20:46:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 93C443858C2F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687553215; bh=pcMZezJO9Eq3/bEs6AGE1WTgeiRRS9mmt4QPiGBB5o4=; h=From:To:Subject:Date:From; b=cym9vweYqu+yYRuXb1WXkozvVFgTf/MrKP4Q7W+33leRYjqwE/sQ3axNxOpt7ODyK 20DYcuxdwlKeHirswPsS93zsjhGMv4ZZ7PPTzoBCE6c56+g6hQ+561TWQ+LZP736Aq nzMJIvW+xOiHVSY4ea27DaFeBTxA6dPOtnYtJj3A= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marek Polacek To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-2054] c++: Add support for -std={c,gnu}++2{c,6} X-Act-Checkin: gcc X-Git-Author: Marek Polacek X-Git-Refname: refs/heads/trunk X-Git-Oldrev: b7fc0a3be52f78100a270b63e7555fde078fd2e3 X-Git-Newrev: 5388a43f6a3f348929292998bd6d0c1da6f006de Message-Id: <20230623204655.93C443858C2F@sourceware.org> Date: Fri, 23 Jun 2023 20:46:55 +0000 (GMT) List-Id: https://gcc.gnu.org/g:5388a43f6a3f348929292998bd6d0c1da6f006de commit r14-2054-g5388a43f6a3f348929292998bd6d0c1da6f006de Author: Marek Polacek Date: Thu Jun 22 16:56:26 2023 -0400 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. Diff: --- 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(-) 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");