From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 1540F3AA9427; Thu, 29 Apr 2021 11:13:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1540F3AA9427 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r10-9779] libstdc++: Define __cpp_lib_constexpr_string macro X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: d0ae39ce2c3b4d635de6102ec3750cf6109cdc8d X-Git-Newrev: 8cfa99066ffe9f4d748634d294758dc27ef149ce Message-Id: <20210429111339.1540F3AA9427@sourceware.org> Date: Thu, 29 Apr 2021 11:13:39 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Apr 2021 11:13:39 -0000 https://gcc.gnu.org/g:8cfa99066ffe9f4d748634d294758dc27ef149ce commit r10-9779-g8cfa99066ffe9f4d748634d294758dc27ef149ce Author: Jonathan Wakely Date: Wed Apr 28 15:56:04 2021 +0100 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. (cherry picked from commit 3da80ed7efd582575e7850a403ce693ec882d087) Diff: --- libstdc++-v3/include/bits/basic_string.h | 9 ++++++++- libstdc++-v3/include/std/version | 2 ++ .../requirements/constexpr_functions_c++17.cc | 11 ++++++++--- .../requirements/constexpr_functions_c++20.cc | 7 +++++++ .../21_strings/char_traits/requirements/version.cc | 16 ++++++++++++++++ 5 files changed, 41 insertions(+), 4 deletions(-) diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h index f36bd6a4fe6..f51ec6b60cf 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 1cb2e4edb75..a5bfc72a001 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 @@ -207,6 +208,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 55dcba48db6..ebde98be20e 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 63c7c9cbb57..2c1cf3d2432 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