mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-03-25 23:41:28 +08:00
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.
This commit is contained in:
parent
96253f069e
commit
78739c2df7
@ -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. */
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
4
gcc/testsuite/g++.dg/cpp23/cplusplus.C
Normal file
4
gcc/testsuite/g++.dg/cpp23/cplusplus.C
Normal file
@ -0,0 +1,4 @@
|
||||
// { dg-do compile }
|
||||
// { dg-options "-std=c++23" }
|
||||
|
||||
static_assert(__cplusplus > 202002L);
|
@ -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 { } {
|
||||
|
@ -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_GNUCXX23, CLK_CXX23,
|
||||
CLK_ASM};
|
||||
|
||||
/* Payload of a NUMBER, STRING, CHAR or COMMENT token. */
|
||||
struct GTY(()) cpp_string {
|
||||
|
@ -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 },
|
||||
/* GNUCXX23 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0 },
|
||||
/* CXX23 */ { 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,12 @@ cpp_init_builtins (cpp_reader *pfile, int hosted)
|
||||
|
||||
if (CPP_OPTION (pfile, cplusplus))
|
||||
{
|
||||
if (CPP_OPTION (pfile, lang) == CLK_CXX20
|
||||
/* 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
|
||||
|| CPP_OPTION (pfile, lang) == CLK_GNUCXX23)
|
||||
_cpp_define_builtin (pfile, "__cplusplus 202100L");
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user