From: Andrew Sutton Date: Fri, 15 Sep 2017 21:16:37 +0000 (+0000) Subject: Add support for -std=c++2a. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=r8-3237-g026a79f70cf33f836ea5275eda72d4870a3041e5;p=gcc.git Add support for -std=c++2a. * c-common.h (cxx_dialect): Add cxx2a as a dialect. * opt.c: Add options for -std=c++2a and -std=gnu++2a. * c-opts.c (set_std_cxx2a): New. (c_common_handle_option): Set options when -std=c++2a is enabled. (c_common_post_options): Adjust comments. (set_std_cxx14, set_std_cxx17): Likewise. * doc/cpp.texi (__cplusplus): Document value for -std=c++2a or -std=gnu+2a. * doc/invoke.texi: Document -std=c++2a and -std=gnu++2a. * lib/target-supports.exp (check_effective_target_c++17): Return 1 also if check_effective_target_c++2a. (check_effective_target_c++17_down): New. (check_effective_target_c++2a_only): New. (check_effective_target_c++2a): New. * g++.dg/cpp2a/cplusplus.C: New. * include/cpplib.h (c_lang): Add CXX2A and GNUCXX2A. * init.c (lang_defaults): Add rows for CXX2A and GNUCXX2A. (cpp_init_builtins): Set __cplusplus to 201709L for C++2a. Co-Authored-By: Jakub Jelinek From-SVN: r252850 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 653502268d1..1b5176a760d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2017-09-15 Andrew Sutton + Jakub Jelinek + + Add support for -std=c++2a. + * doc/cpp.texi (__cplusplus): Document value for -std=c++2a + or -std=gnu+2a. + * doc/invoke.texi: Document -std=c++2a and -std=gnu++2a. + 2017-09-15 Steve Ellcey PR target/82066 diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index a3f990d49fd..8003fb55fc7 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,14 @@ +2017-09-15 Andrew Sutton + Jakub Jelinek + + Add support for -std=c++2a. + * c-common.h (cxx_dialect): Add cxx2a as a dialect. + * opt.c: Add options for -std=c++2a and -std=gnu++2a. + * c-opts.c (set_std_cxx2a): New. + (c_common_handle_option): Set options when -std=c++2a is enabled. + (c_common_post_options): Adjust comments. + (set_std_cxx14, set_std_cxx17): Likewise. + 2017-09-15 Eric Botcazou * c-pragma.c (handle_pragma_scalar_storage_order): Expand on error diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index d57829bc89a..da6a0be9200 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -703,7 +703,9 @@ enum cxx_dialect { /* C++14 */ cxx14, /* C++17 */ - cxx17 + cxx17, + /* C++2a (C++20?) */ + cxx2a }; /* 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 cdbcd6cf874..3662aa37be6 100644 --- a/gcc/c-family/c-opts.c +++ b/gcc/c-family/c-opts.c @@ -111,6 +111,7 @@ static void set_std_cxx98 (int); static void set_std_cxx11 (int); static void set_std_cxx14 (int); static void set_std_cxx17 (int); +static void set_std_cxx2a (int); static void set_std_c89 (int, int); static void set_std_c99 (int); static void set_std_c11 (int); @@ -637,6 +638,12 @@ c_common_handle_option (size_t scode, const char *arg, int value, set_std_cxx17 (code == OPT_std_c__17 /* ISO */); break; + case OPT_std_c__2a: + case OPT_std_gnu__2a: + if (!preprocessing_asm_p) + set_std_cxx2a (code == OPT_std_c__2a /* ISO */); + break; + case OPT_std_c90: case OPT_std_iso9899_199409: if (!preprocessing_asm_p) @@ -938,7 +945,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} default to -fno-ext-numeric-literals. */ + for -std=c++{11,14,17,2a} default to -fno-ext-numeric-literals. */ if (flag_iso && !global_options_set.x_flag_ext_numeric_literals) cpp_opts->ext_numeric_literals = 0; } @@ -1589,7 +1596,7 @@ set_std_cxx14 (int iso) flag_no_gnu_keywords = iso; flag_no_nonansi_builtin = iso; flag_iso = iso; - /* C++11 includes the C99 standard library. */ + /* C++14 includes the C99 standard library. */ flag_isoc94 = 1; flag_isoc99 = 1; cxx_dialect = cxx14; @@ -1604,7 +1611,7 @@ set_std_cxx17 (int iso) flag_no_gnu_keywords = iso; flag_no_nonansi_builtin = iso; flag_iso = iso; - /* C++11 includes the C99 standard library. */ + /* C++17 includes the C11 standard library. */ flag_isoc94 = 1; flag_isoc99 = 1; flag_isoc11 = 1; @@ -1612,6 +1619,22 @@ set_std_cxx17 (int iso) lang_hooks.name = "GNU C++17"; } +/* Set the C++ 202a draft standard (without GNU extensions if ISO). */ +static void +set_std_cxx2a (int iso) +{ + cpp_set_lang (parse_in, iso ? CLK_CXX2A: CLK_GNUCXX2A); + flag_no_gnu_keywords = iso; + flag_no_nonansi_builtin = iso; + flag_iso = iso; + /* C++17 includes the C11 standard library. */ + flag_isoc94 = 1; + flag_isoc99 = 1; + flag_isoc11 = 1; + cxx_dialect = cxx2a; + lang_hooks.name = "GNU C++17"; /* Pretend C++17 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 ed5938f0ea4..3c2c107ba4b 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -1932,6 +1932,10 @@ std=c++17 C++ ObjC++ Conform to the ISO 2017 C++ standard. +std=c++2a +C++ ObjC++ +Conform to the ISO 2020(?) C++ draft standard (experimental and incomplete support). + std=c11 C ObjC Conform to the ISO 2011 C standard. @@ -1990,6 +1994,10 @@ std=gnu++17 C++ ObjC++ Conform to the ISO 2017 C++ standard with GNU extensions. +std=gnu++2a +C++ ObjC++ +Conform to the ISO 2020(?) 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 8e9cba378c3..52f2606eadc 100644 --- a/gcc/doc/cpp.texi +++ b/gcc/doc/cpp.texi @@ -1877,7 +1877,10 @@ selected, the value of the macro is @code{199711L} for the 1998 C++ standard, @code{201103L} for the 2011 C++ standard, @code{201402L} for the 2014 C++ standard, -@code{201703L} for the 2017 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}. @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 60650c83917..204c9b77b61 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -1880,6 +1880,16 @@ The name @samp{c++1z} is deprecated. @itemx gnu++1z GNU dialect of @option{-std=c++17}. The name @samp{gnu++1z} is deprecated. + +@item c++2a +The next revision of the ISO C++ standard, tentatively planned for +2020. Support is highly experimental, and will almost certainly +change in incompatible ways in future releases. + +@item gnu++2a +GNU dialect of @option{-std=c++2a}. 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 b9bb9c62a8e..1a94535b0ee 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,14 @@ +2017-09-15 Andrew Sutton + Jakub Jelinek + + Add support for -std=c++2a. + * lib/target-supports.exp (check_effective_target_c++17): Return + 1 also if check_effective_target_c++2a. + (check_effective_target_c++17_down): New. + (check_effective_target_c++2a_only): New. + (check_effective_target_c++2a): New. + * g++.dg/cpp2a/cplusplus.C: New. + 2017-09-15 Joseph Myers PR c/82071 diff --git a/gcc/testsuite/g++.dg/cpp2a/cplusplus.C b/gcc/testsuite/g++.dg/cpp2a/cplusplus.C new file mode 100644 index 00000000000..614fc52e391 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/cplusplus.C @@ -0,0 +1,4 @@ +// { dg-do compile } +// { dg-options "-std=c++2a" } + +static_assert(__cplusplus > 201703L); diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp index d22948543e2..6ea71222c6e 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -7863,8 +7863,35 @@ proc check_effective_target_c++17_only { } { } return 0 } + proc check_effective_target_c++17 { } { - return [check_effective_target_c++17_only] + if [check_effective_target_c++17_only] { + return 1 + } + return [check_effective_target_c++2a] +} +proc check_effective_target_c++17_down { } { + if ![check_effective_target_c++] { + return 0 + } + return [expr ![check_effective_target_c++2a] ] +} + +proc check_effective_target_c++2a_only { } { + global cxx_default + if ![check_effective_target_c++] { + return 0 + } + if [check-flags { { } { } { -std=c++2a -std=gnu++2a } }] { + return 1 + } + if { $cxx_default == "c++20" && [check-flags { { } { } { } { -std=* } }] } { + return 1 + } + return 0 +} +proc check_effective_target_c++2a { } { + return [check_effective_target_c++2a_only] } # Check for C++ Concepts TS support, i.e. -fconcepts flag. diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 3696c76768b..0621074b53b 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,11 @@ +2017-09-15 Andrew Sutton + Jakub Jelinek + + Add support for -std=c++2a. + * include/cpplib.h (c_lang): Add CXX2A and GNUCXX2A. + * init.c (lang_defaults): Add rows for CXX2A and GNUCXX2A. + (cpp_init_builtins): Set __cplusplus to 201709L for C++2a. + 2017-09-15 Jakub Jelinek * include/cpplib.h (enum c_lang): Rename CLK_GNUCXX1Z diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 8c81f9d03a0..804132a44da 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -171,7 +171,8 @@ enum cpp_ttype enum c_lang {CLK_GNUC89 = 0, CLK_GNUC99, CLK_GNUC11, CLK_STDC89, CLK_STDC94, CLK_STDC99, CLK_STDC11, CLK_GNUCXX, CLK_CXX98, CLK_GNUCXX11, CLK_CXX11, - CLK_GNUCXX14, CLK_CXX14, CLK_GNUCXX17, CLK_CXX17, CLK_ASM}; + CLK_GNUCXX14, CLK_CXX14, CLK_GNUCXX17, CLK_CXX17, + CLK_GNUCXX2A, CLK_CXX2A, 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 0148586a5cb..16ff202c8cf 100644 --- a/libcpp/init.c +++ b/libcpp/init.c @@ -110,6 +110,8 @@ static const struct lang_flags lang_defaults[] = /* CXX14 */ { 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 }, /* GNUCXX17 */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1 }, /* CXX17 */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 }, + /* GNUCXX2A */ { 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1 }, + /* CXX2A */ { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1 }, /* ASM */ { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }; @@ -497,7 +499,10 @@ cpp_init_builtins (cpp_reader *pfile, int hosted) if (CPP_OPTION (pfile, cplusplus)) { - if (CPP_OPTION (pfile, lang) == CLK_CXX17 + if (CPP_OPTION (pfile, lang) == CLK_CXX2A + || CPP_OPTION (pfile, lang) == CLK_GNUCXX2A) + _cpp_define_builtin (pfile, "__cplusplus 201709L"); + else if (CPP_OPTION (pfile, lang) == CLK_CXX17 || CPP_OPTION (pfile, lang) == CLK_GNUCXX17) _cpp_define_builtin (pfile, "__cplusplus 201703L"); else if (CPP_OPTION (pfile, lang) == CLK_CXX14