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 /libcpp | |
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 'libcpp')
-rw-r--r-- | libcpp/include/cpplib.h | 2 | ||||
-rw-r--r-- | libcpp/init.cc | 13 |
2 files changed, 10 insertions, 5 deletions
diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index d326f5a..aef703f 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 c508f06..693feaa 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"); |