This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] PR c++/91369 Implement P0784R7 changes to allocation and construction


On 29/10/19 09:37 +0000, Jonathan Wakely wrote:
On 29/10/19 10:23 +0100, Stephan Bergmann wrote:
On 23/10/2019 21:27, Jonathan Wakely wrote:
This patch is the first part of library support for constexpr
std::vector and std::string. This only includes the changes to
std::allocator, std::allocator_traits, std::construct_at,
std::destroy_at, std::destroy and std::destroy_n.
[...]
Tested x86_64-linux and powerpc64le-linux, for every -std=gnu++NN
mode.

Clang (trunk, at least) with -std=c++11 now complains about some of the constexpr (because they return void, or don't have a return statement) when including <memory>.

Ah, thanks for letting me know. I did test with Clang, but not with
-std=c++11. I'll add that to my set of checks.

What fixed it for me locally:

diff --git a/libstdc++-v3/include/bits/alloc_traits.h b/libstdc++-v3/include/bits/alloc_traits.h
index 26d6d26ae48..61d3c1b794b 100644
--- a/libstdc++-v3/include/bits/alloc_traits.h
+++ b/libstdc++-v3/include/bits/alloc_traits.h
@@ -241,13 +241,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
	  = typename __construct_helper<_Tp, _Args...>::type;
     template<typename _Tp, typename... _Args>
-	static constexpr _Require<__has_construct<_Tp, _Args...>>
+	static
+#if __cplusplus >= 201402L
+	       constexpr
+#endif

That's what the _GLIBCXX14_CONSTEXPR macro is for.

I'll fix this today, thanks.

Fixed with this, tested on powerpc64le-linux, and smoke tested on
x86_64-linux using Clang 7.0.1.

Committed to trunk.


commit 94674310b112c55010cfe4f49f0236fecb2dccb8
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Oct 29 19:33:51 2019 +0000

    Fix compilation errors with Clang
    
            * include/bits/alloc_traits.h (__cpp_lib_constexpr_dynamic_alloc):
            Define.
            (allocator_traits::_S_construct, allocator_traits::_S_destroy)
            (__alloc_on_copy, __alloc_on_move, __alloc_on_swap): Use
            _GLIBCXX14_CONSTEXPR instead of constexpr.
            * include/bits/stl_construct.h (_Destroy): Likewise.

diff --git a/libstdc++-v3/include/bits/alloc_traits.h b/libstdc++-v3/include/bits/alloc_traits.h
index 26d6d26ae48..55211ac1d72 100644
--- a/libstdc++-v3/include/bits/alloc_traits.h
+++ b/libstdc++-v3/include/bits/alloc_traits.h
@@ -241,13 +241,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	  = typename __construct_helper<_Tp, _Args...>::type;
 
       template<typename _Tp, typename... _Args>
-	static constexpr _Require<__has_construct<_Tp, _Args...>>
+	static _GLIBCXX14_CONSTEXPR _Require<__has_construct<_Tp, _Args...>>
 	_S_construct(_Alloc& __a, _Tp* __p, _Args&&... __args)
 	noexcept(noexcept(__a.construct(__p, std::forward<_Args>(__args)...)))
 	{ __a.construct(__p, std::forward<_Args>(__args)...); }
 
       template<typename _Tp, typename... _Args>
-	static constexpr
+	static _GLIBCXX14_CONSTEXPR
 	_Require<__and_<__not_<__has_construct<_Tp, _Args...>>,
 			       is_constructible<_Tp, _Args...>>>
 	_S_construct(_Alloc&, _Tp* __p, _Args&&... __args)
@@ -256,14 +256,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	{ std::_Construct(__p, std::forward<_Args>(__args)...); }
 
       template<typename _Alloc2, typename _Tp>
-	static constexpr auto
+	static _GLIBCXX14_CONSTEXPR auto
 	_S_destroy(_Alloc2& __a, _Tp* __p, int)
 	noexcept(noexcept(__a.destroy(__p)))
 	-> decltype(__a.destroy(__p))
 	{ __a.destroy(__p); }
 
       template<typename _Alloc2, typename _Tp>
-	static constexpr void
+	static _GLIBCXX14_CONSTEXPR void
 	_S_destroy(_Alloc2&, _Tp* __p, ...)
 	noexcept(noexcept(__p->~_Tp()))
 	{ std::_Destroy(__p); }
@@ -393,6 +393,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       { return _S_select(__rhs, 0); }
     };
 
+#if __cplusplus > 201703L
+# define __cpp_lib_constexpr_dynamic_alloc 201907L
+#endif
+
   /// Partial specialization for std::allocator.
   template<typename _Tp>
     struct allocator_traits<allocator<_Tp>>
@@ -562,7 +566,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
 
   template<typename _Alloc>
-    constexpr void
+    _GLIBCXX14_CONSTEXPR void
     __alloc_on_copy(_Alloc& __one, const _Alloc& __two)
     {
       typedef allocator_traits<_Alloc> __traits;
@@ -594,7 +598,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
 
   template<typename _Alloc>
-    constexpr void
+    _GLIBCXX14_CONSTEXPR void
     __alloc_on_move(_Alloc& __one, _Alloc& __two)
     {
       typedef allocator_traits<_Alloc> __traits;
@@ -621,7 +625,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
 
   template<typename _Alloc>
-    constexpr void
+    _GLIBCXX14_CONSTEXPR void
     __alloc_on_swap(_Alloc& __one, _Alloc& __two)
     {
       typedef allocator_traits<_Alloc> __traits;
diff --git a/libstdc++-v3/include/bits/stl_construct.h b/libstdc++-v3/include/bits/stl_construct.h
index a16196ffe74..c714148e037 100644
--- a/libstdc++-v3/include/bits/stl_construct.h
+++ b/libstdc++-v3/include/bits/stl_construct.h
@@ -137,7 +137,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
    * Destroy the object pointed to by a pointer type.
    */
   template<typename _Tp>
-    _GLIBCXX_CONSTEXPR inline void
+    _GLIBCXX14_CONSTEXPR inline void
     _Destroy(_Tp* __pointer)
     {
 #if __cplusplus > 201703L
diff --git a/libstdc++-v3/include/ext/alloc_traits.h b/libstdc++-v3/include/ext/alloc_traits.h
index 052d811ec01..c7b8e5d4ba3 100644
--- a/libstdc++-v3/include/ext/alloc_traits.h
+++ b/libstdc++-v3/include/ext/alloc_traits.h
@@ -76,7 +76,8 @@ template<typename _Alloc, typename = typename _Alloc::value_type>
   public:
     // overload construct for non-standard pointer types
     template<typename _Ptr, typename... _Args>
-      static constexpr std::__enable_if_t<__is_custom_pointer<_Ptr>::value>
+      static _GLIBCXX14_CONSTEXPR
+      std::__enable_if_t<__is_custom_pointer<_Ptr>::value>
       construct(_Alloc& __a, _Ptr __p, _Args&&... __args)
       noexcept(noexcept(_Base_type::construct(__a, std::__to_address(__p),
 					      std::forward<_Args>(__args)...)))
@@ -87,7 +88,8 @@ template<typename _Alloc, typename = typename _Alloc::value_type>
 
     // overload destroy for non-standard pointer types
     template<typename _Ptr>
-      static constexpr std::__enable_if_t<__is_custom_pointer<_Ptr>::value>
+      static _GLIBCXX14_CONSTEXPR
+      std::__enable_if_t<__is_custom_pointer<_Ptr>::value>
       destroy(_Alloc& __a, _Ptr __p)
       noexcept(noexcept(_Base_type::destroy(__a, std::__to_address(__p))))
       { _Base_type::destroy(__a, std::__to_address(__p)); }
@@ -95,7 +97,7 @@ template<typename _Alloc, typename = typename _Alloc::value_type>
     static constexpr _Alloc _S_select_on_copy(const _Alloc& __a)
     { return _Base_type::select_on_container_copy_construction(__a); }
 
-    static constexpr void _S_on_swap(_Alloc& __a, _Alloc& __b)
+    static _GLIBCXX14_CONSTEXPR void _S_on_swap(_Alloc& __a, _Alloc& __b)
     { std::__alloc_on_swap(__a, __b); }
 
     static constexpr bool _S_propagate_on_copy_assign()

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]