From patchwork Mon Jan 11 00:28:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Fee X-Patchwork-Id: 1424376 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=qzDHZWh+; dkim-atps=neutral Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DDZLz1br0z9sWL for ; Mon, 11 Jan 2021 11:28:41 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B047D3851C21; Mon, 11 Jan 2021 00:28:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B047D3851C21 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1610324917; bh=ru2LjXcNqAWOouGMW+ayKxFxm0c+eLUOUUi/+OG6WR4=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=qzDHZWh+GBNZ8VfZBQ9S6q+UJtUWCaGfwwbn3QuemKZiM6OuvfAW7pj3+D3l70S5/ nYoF5e+oMqqwnlpfONqGrGq+KCNDr9zCCYwCItC6f9Hb9t8hF0ryKRutlHn9uTvVGg /upnJ3dW/Msmvw2Yw49riDg9oKj9sMSVr2LDb/UI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by sourceware.org (Postfix) with ESMTPS id 7F892385DC14; Mon, 11 Jan 2021 00:28:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7F892385DC14 Received: by mail-lf1-x136.google.com with SMTP id o13so35450818lfr.3; Sun, 10 Jan 2021 16:28:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=ru2LjXcNqAWOouGMW+ayKxFxm0c+eLUOUUi/+OG6WR4=; b=UwkDtGAMmz68J7IoaeES6v9fzFt6QnoxdBvhOudqWndJ0RLF1xuEXkwIu8BQ7+y1Tg FDolrKh6zYXSh9SsdElE1ZKyKG/oY9X31YNXtCHMryQ7aSdfDw1j1F0MgWdCXNUpr2u+ Gp0a6+lBUYiORVw0dniiVvefA3KkNW8RcoUIbjoJW/uOli0eP/VuY6hdIj2dv98zMr0p zF7DrmWxLH3YTvva03e4w2LPo923R+XbR+M7cJAnFdIJV/kOiCvk7x+dM/bfAFgkA6c3 gF/gH2sQZsGOI/gtzbkkQUSF/mQjwG4azmJrEiNKjxYdV2Tmk/iT5iwo/T1vOyjQSynN dkEA== X-Gm-Message-State: AOAM531AfMeZg8zPWTBnXGWC1eAA6Y1ugyEyy5xiOieEjBfT8J4PRUwt NLmGkX6fIkWZMF5G4aEew5IwPxDLWet7j8+i9ziD41VPGjUIFw== X-Google-Smtp-Source: ABdhPJxa1LwRgHHwzbfCEWIzJSoiebwZye3eP6qFbDQiqHWNjGxub4ZgL3yc6X19aweaSkvYa1JKJuV7BKnzZh9y6Ds= X-Received: by 2002:ac2:454b:: with SMTP id j11mr4995558lfm.45.1610324910624; Sun, 10 Jan 2021 16:28:30 -0800 (PST) MIME-Version: 1.0 Date: Mon, 11 Jan 2021 00:28:19 +0000 Message-ID: Subject: [PATCH v2] c++: Add support for -std=c++2b To: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Paul Fee via Gcc-patches From: Paul Fee Reply-To: Paul Fee Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" [PATCH v2] c++: Add support for -std=c++2b 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 202100L. $ g++ -std=c++2b -dM -E -x c++ - < /dev/null | grep cplusplus #define __cplusplus 202100L Changes since v1 (8th Jan 2021): * As suggested by Jonathan Wakely: __cplusplus set to 202100L rather than 202101L. Use of a non-existent date helps indicate this is not a true standard, yet is a value greater than 202002L. * As suggested by Jakub Jelinek: Fixed typos and formatting. Added C++23 support to dwarf2out.c, including missing C++20 support in highest_c_language. * Regarding suggestion by Marek Polacek to refer to C++23 rather than C++2b. Left the option as -std=c++2b for now. It may be premature to assume the next version of the standard will be named C++23. Use of c++2b also reinforces the experimental nature of GCC's C++23 implementation. gcc/ 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. gcc/c-family 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. * dwarf2out.c (highest_c_language): Recognise C++20 and C++23. (gen_compile_unit_die): Recognise C++23. gcc/testsuite 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. libcpp 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 202100L for C++2b. --- gcc/c-family/c-common.h | 4 ++- gcc/c-family/c-opts.c | 29 ++++++++++++++++++++++-- gcc/c-family/c.opt | 8 ++++++ gcc/doc/cpp.texi | 7 +++-- gcc/doc/invoke.texi | 10 ++++++++ gcc/dwarf2out.c | 7 +++++ gcc/testsuite/g++.dg/cpp2b/cplusplus.C | 4 +++ gcc/testsuite/lib/target-supports.exp | 39 +++++++++++++++++++++++---------- libcpp/include/cpplib.h | 3 +- libcpp/init.c | 7 +++++ 10 files changed, 98 insertions(+), 20 deletions(-) + /* 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 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 diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index a65c78f7240..f562cdebf4c 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++2b (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..15f120d475d 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++ 202b 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..273772a0cd5 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -2214,6 +2214,10 @@ 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 +2296,10 @@ 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/dwarf2out.c b/gcc/dwarf2out.c index 8b6890a5097..97df6604373 100644 --- a/gcc/dwarf2out.c +++ b/gcc/dwarf2out.c @@ -24445,6 +24445,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) @@ -24550,7 +24554,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; } 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/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..80543f90a51 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 },