public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed] libstdc++: Define __cpp_lib_constexpr_string macro
@ 2021-04-28 15:14 Jonathan Wakely
  2021-04-30 21:27 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Wakely @ 2021-04-28 15:14 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 978 bytes --]

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.



[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 6115 bytes --]

commit 3da80ed7efd582575e7850a403ce693ec882d087
Author: Jonathan Wakely <jwakely@redhat.com>
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 <string_view>
 #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<typename CT>
     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<std::char_traits<char>>() );
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<typename CT>
     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 <version>
+
+#ifndef __cpp_lib_constexpr_string
+# error Feature-test macro for constexpr char_traits is missing in <version>
+#elif __cpp_lib_constexpr_string < (__cplusplus == 201703 ? 201611 : 201811)
+# error Feature-test macro for constexpr char_traits has the wrong value in <version>
+#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 <version>
+#elif __cpp_lib_constexpr_char_traits != (__cplusplus == 201703 ? 201611 : 201811)
+# error Feature-test macro for constexpr char_traits has the wrong value in <version>
+#endif

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [committed] libstdc++: Define __cpp_lib_constexpr_string macro
  2021-04-28 15:14 [committed] libstdc++: Define __cpp_lib_constexpr_string macro Jonathan Wakely
@ 2021-04-30 21:27 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2021-04-30 21:27 UTC (permalink / raw)
  To: libstdc++, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 1468 bytes --]

On 28/04/21 16:14 +0100, Jonathan Wakely wrote:
>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.

I messed up the __cpp_lib_constexpr_string macro by copy&pasting from
the __cpp_lib_constexpr_char_traits one, which is defined inside a
#ifdef __cplusplus >= 201702 block. But for __cpp_lib_constexpr_string
it isn't so the #else means that we define it to 201811L for
everything newer *or* older than C++17.

I also noticed that __cpp_lib_semaphore wasn't defined consistently,
as it's failing on AIX.

Fixed on trunk by this patch. Tested x86_64-linux and powerpc-aix.

I'll backport this to the relevant branches too.



[-- Attachment #2: patch.txt --]
[-- Type: text/x-patch, Size: 1628 bytes --]

commit 3215d4f5b3d08e0087a88df9e155c779927ace1a
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Apr 30 20:32:05 2021

    libstdc++: Fix inconsistent feature test macros
    
    The __cpp_lib_constexpr_string and __cpp_lib_semaphore feature test
    macros are not defined consistently in <version> and the relevant header
    for the feature.
    
    libstdc++-v3/ChangeLog:
    
            * include/bits/basic_string.h (__cpp_lib_constexpr_string):
            Only define for C++17 and later.
            * include/std/version (__cpp_lib_semaphore): Fix condition
            to match the one in <semaphore>.

diff --git a/libstdc++-v3/include/bits/basic_string.h b/libstdc++-v3/include/bits/basic_string.h
index 41d781c698e..fba7c6f3354 100644
--- a/libstdc++-v3/include/bits/basic_string.h
+++ b/libstdc++-v3/include/bits/basic_string.h
@@ -55,7 +55,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #if __cplusplus == 201703L
 // Support P0426R1 changes to char_traits in C++17.
 # define __cpp_lib_constexpr_string 201611L
-#else
+#elif __cplusplus > 201703L
 // Also support P1032R1 in C++20 (but not P0980R1 yet).
 # define __cpp_lib_constexpr_string 201811L
 #endif
diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version
index 09e67a40d0c..ea0e18a3f9d 100644
--- a/libstdc++-v3/include/std/version
+++ b/libstdc++-v3/include/std/version
@@ -241,7 +241,7 @@
 #if __cpp_lib_concepts
 # define __cpp_lib_ranges 201911L
 #endif
-#if __cpp_lib_atomic_wait
+#if __cpp_lib_atomic_wait || _GLIBCXX_HAVE_POSIX_SEMAPHORE
 # define __cpp_lib_semaphore 201907L
 #endif
 #define __cpp_lib_shift 201806L

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-04-30 21:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-28 15:14 [committed] libstdc++: Define __cpp_lib_constexpr_string macro Jonathan Wakely
2021-04-30 21:27 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).