From patchwork Wed Apr 28 15:14:10 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1471253 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; 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=AVVm4kw1; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [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 4FVhxn1FTBz9sWD for ; Thu, 29 Apr 2021 01:14:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E9CEB3AA8C17; Wed, 28 Apr 2021 15:14:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E9CEB3AA8C17 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1619622862; bh=PdAHfZLXM6cHLUeC5W4TFZRlUfth9ocuD37WdUNoXU4=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=AVVm4kw1sFI4OOQR1B5rHGuau3/kPrh4kezsetlDCFn8XmZTivjl9VS93yyRoNBH5 ccmoKBTkHcU9mZplMv9+1h01ud2jwqzhzEVHXWomLjR7b6qrf3LaPvMY2CySOQvC70 hyxSjFIIk4lQDoYuGM1TT1sqQUF40lchct7uooyA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 27A5A3970806 for ; Wed, 28 Apr 2021 15:14:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 27A5A3970806 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-233-kanZGXNBNtGfpAxM-rK2Tg-1; Wed, 28 Apr 2021 11:14:13 -0400 X-MC-Unique: kanZGXNBNtGfpAxM-rK2Tg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 097D78049CD; Wed, 28 Apr 2021 15:14:12 +0000 (UTC) Received: from localhost (unknown [10.33.36.164]) by smtp.corp.redhat.com (Postfix) with ESMTP id A89916A965; Wed, 28 Apr 2021 15:14:11 +0000 (UTC) Date: Wed, 28 Apr 2021 16:14:10 +0100 To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Define __cpp_lib_constexpr_string macro Message-ID: MIME-Version: 1.0 X-Clacks-Overhead: GNU Terry Pratchett X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-14.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=unavailable 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: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" As noted in r11-1339-gb6ab9ecd550227684643b41e9e33a4d3466724d8 we define a non-standard __cpp_lib_constexpr_char_traits feature test macro to indicate support for P0426R1 and P1032R1. At some point last year the __cpp_lib_constexpr_string macro was retconned to indicate support for those papers. This adds the new macro (which we didn't previously define, because it referred to P0980R1 "Making std::string constexpr" which we don't support). libstdc++-v3/ChangeLog: * include/bits/basic_string.h (__cpp_lib_constexpr_string): Define. * include/std/version (__cpp_lib_constexpr_string): Define. * testsuite/21_strings/char_traits/requirements/constexpr_functions_c++17.cc: Check for __cpp_lib_constexpr_string. * testsuite/21_strings/char_traits/requirements/constexpr_functions_c++20.cc: Likewise. * testsuite/21_strings/char_traits/requirements/version.cc: New test. Tested powerpc64le-linux. Committed to trunk. I'll backport this to the relevant branches too. commit 3da80ed7efd582575e7850a403ce693ec882d087 Author: Jonathan Wakely Date: Wed Apr 28 15:56:04 2021 libstdc++: Define __cpp_lib_constexpr_string macro As noted in r11-1339-gb6ab9ecd550227684643b41e9e33a4d3466724d8 we define a non-standard __cpp_lib_constexpr_char_traits feature test macro to indicate support for P0426R1 and P1032R1. At some point last year the __cpp_lib_constexpr_string macro was retconned to indicate support for those papers. This adds the new macro (which we didn't previously define, because it referred to P0980R1 "Making std::string constexpr" which we don't support). libstdc++-v3/ChangeLog: * include/bits/basic_string.h (__cpp_lib_constexpr_string): Define. * include/std/version (__cpp_lib_constexpr_string): Define. * testsuite/21_strings/char_traits/requirements/constexpr_functions_c++17.cc: Check for __cpp_lib_constexpr_string. * testsuite/21_strings/char_traits/requirements/constexpr_functions_c++20.cc: Likewise. * testsuite/21_strings/char_traits/requirements/version.cc: New test. diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index 3c5309d16e6..41d781c698e 100644 --- a/libstdc++-v3/include/bits/basic_string.h +++ b/libstdc++-v3/include/bits/basic_string.h @@ -48,11 +48,18 @@ # include #endif - namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION +#if __cplusplus == 201703L +// Support P0426R1 changes to char_traits in C++17. +# define __cpp_lib_constexpr_string 201611L +#else +// Also support P1032R1 in C++20 (but not P0980R1 yet). +# define __cpp_lib_constexpr_string 201811L +#endif + #if _GLIBCXX_USE_CXX11_ABI _GLIBCXX_BEGIN_NAMESPACE_CXX11 /** diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version index d9f6a3c3dfd..09e67a40d0c 100644 --- a/libstdc++-v3/include/std/version +++ b/libstdc++-v3/include/std/version @@ -131,6 +131,7 @@ #define __cpp_lib_clamp 201603 #if __cplusplus == 201703L // N.B. updated value in C++20 # define __cpp_lib_constexpr_char_traits 201611L +# define __cpp_lib_constexpr_string 201611L #endif #define __cpp_lib_enable_shared_from_this 201603 #define __cpp_lib_execution 201902L // FIXME: should be 201603L @@ -219,6 +220,7 @@ #define __cpp_lib_constexpr_iterator 201811L #define __cpp_lib_constexpr_memory 201811L #define __cpp_lib_constexpr_numeric 201911L +#define __cpp_lib_constexpr_string 201811L #define __cpp_lib_constexpr_string_view 201811L #define __cpp_lib_constexpr_tuple 201811L #define __cpp_lib_constexpr_utility 201811L diff --git a/libstdc++-v3/testsuite/21_strings/char_traits/requirements/constexpr_functions_c++17.cc b/libstdc++-v3/testsuite/21_strings/char_traits/requirements/constexpr_functions_c++17.cc index 803fb68df09..32e31e13abb 100644 --- a/libstdc++-v3/testsuite/21_strings/char_traits/requirements/constexpr_functions_c++17.cc +++ b/libstdc++-v3/testsuite/21_strings/char_traits/requirements/constexpr_functions_c++17.cc @@ -73,12 +73,17 @@ template return true; } +#ifndef __cpp_lib_constexpr_string +# error Feature-test macro for constexpr char_traits is missing +#elif __cpp_lib_constexpr_string < (__cplusplus == 201703 ? 201611 : 201811) +# error Feature-test macro for constexpr char_traits has the wrong value +#endif + +// We also provide this non-standard macro for P0426R1 (and P1032R1 in C++20). #ifndef __cpp_lib_constexpr_char_traits # error Feature-test macro for constexpr char_traits is missing -#elif __cpp_lib_constexpr_char_traits < 201611 +#elif __cpp_lib_constexpr_char_traits != (__cplusplus == 201703 ? 201611 : 201811) # error Feature-test macro for constexpr char_traits has the wrong value -#elif __cpp_lib_constexpr_char_traits > 201611 && __cplusplus == 201703 -# error Feature-test macro for constexpr char_traits has wrong value for C++17 #endif static_assert( test_assign>() ); diff --git a/libstdc++-v3/testsuite/21_strings/char_traits/requirements/constexpr_functions_c++20.cc b/libstdc++-v3/testsuite/21_strings/char_traits/requirements/constexpr_functions_c++20.cc index 0c1329f903d..0d1595fe030 100644 --- a/libstdc++-v3/testsuite/21_strings/char_traits/requirements/constexpr_functions_c++20.cc +++ b/libstdc++-v3/testsuite/21_strings/char_traits/requirements/constexpr_functions_c++20.cc @@ -30,6 +30,13 @@ template return s1[0]==char_type{1} && s1[1]==char_type{1} && s1[2]==char_type{2}; } +#ifndef __cpp_lib_constexpr_string +# error Feature-test macro for constexpr char_traits is missing +#elif __cpp_lib_constexpr_string < 201811 +# error Feature-test macro for constexpr char_traits has the wrong value +#endif + +// We also provide this non-standard macro for P0426R1 and P1032R1. #ifndef __cpp_lib_constexpr_char_traits # error Feature-test macro for constexpr char_traits is missing #elif __cpp_lib_constexpr_char_traits != 201811 diff --git a/libstdc++-v3/testsuite/21_strings/char_traits/requirements/version.cc b/libstdc++-v3/testsuite/21_strings/char_traits/requirements/version.cc new file mode 100644 index 00000000000..6f571f48010 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/char_traits/requirements/version.cc @@ -0,0 +1,16 @@ +// { dg-do compile { target c++17 } } + +#include + +#ifndef __cpp_lib_constexpr_string +# error Feature-test macro for constexpr char_traits is missing in +#elif __cpp_lib_constexpr_string < (__cplusplus == 201703 ? 201611 : 201811) +# error Feature-test macro for constexpr char_traits has the wrong value in +#endif + +// We also provide this non-standard macro for P0426R1 and P1032R1. +#ifndef __cpp_lib_constexpr_char_traits +# error Feature-test macro for constexpr char_traits is missing in +#elif __cpp_lib_constexpr_char_traits != (__cplusplus == 201703 ? 201611 : 201811) +# error Feature-test macro for constexpr char_traits has the wrong value in +#endif