[libcxx] r346764 - [libcxx] Implement http://wg21.link/p1006, constexpr in pointer_traits

Louis Dionne ldionne at apple.com
Tue Nov 13 09:04:05 PST 2018


Author: ldionne
Date: Tue Nov 13 09:04:05 2018
New Revision: 346764

URL: http://llvm.org/viewvc/llvm-project?rev=346764&view=rev
Log:
[libcxx] Implement http://wg21.link/p1006, constexpr in pointer_traits

Summary:
P1006 adds support for constexpr in the specialization of pointer_traits
for raw pointers. This is necessary in order to use pointer_traits in
the upcoming constexpr containers. We expect P1006 to be voted into the
working draft for C++20 at the San Diego meeting.

Reviewers: mclow.lists, EricWF

Subscribers: christof, dexonsmith, libcxx-commits

Differential Revision: https://reviews.llvm.org/D53867

Modified:
    libcxx/trunk/include/memory
    libcxx/trunk/test/std/utilities/memory/pointer.traits/pointer_to.pass.cpp

Modified: libcxx/trunk/include/memory
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/memory?rev=346764&r1=346763&r2=346764&view=diff
==============================================================================
--- libcxx/trunk/include/memory (original)
+++ libcxx/trunk/include/memory Tue Nov 13 09:04:05 2018
@@ -43,7 +43,7 @@ struct pointer_traits<T*>
 
     template <class U> using rebind = U*;
 
-    static pointer pointer_to(<details>) noexcept;
+    static pointer pointer_to(<details>) noexcept; // constexpr in C++20
 };
 
 template <class T> constexpr T* to_address(T* p) noexcept; // C++20
@@ -984,7 +984,7 @@ struct _LIBCPP_TEMPLATE_VIS pointer_trai
 private:
     struct __nat {};
 public:
-    _LIBCPP_INLINE_VISIBILITY
+    _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX17
     static pointer pointer_to(typename conditional<is_void<element_type>::value,
                                       __nat, element_type>::type& __r) _NOEXCEPT
         {return _VSTD::addressof(__r);}

Modified: libcxx/trunk/test/std/utilities/memory/pointer.traits/pointer_to.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/memory/pointer.traits/pointer_to.pass.cpp?rev=346764&r1=346763&r2=346764&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/memory/pointer.traits/pointer_to.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/memory/pointer.traits/pointer_to.pass.cpp Tue Nov 13 09:04:05 2018
@@ -12,15 +12,18 @@
 // template <class T>
 // struct pointer_traits<T*>
 // {
-//     static pointer pointer_to(<details>);
+//     static pointer pointer_to(<details>); // constexpr in C++20
 //     ...
 // };
 
 #include <memory>
 #include <cassert>
+#include "test_macros.h"
 
-int main()
-{
+#if TEST_STD_VER > 17
+constexpr
+#endif
+bool check() {
     {
         int i = 0;
         static_assert((std::is_same<int *, decltype(std::pointer_traits<int*>::pointer_to(i))>::value), "");
@@ -30,4 +33,12 @@ int main()
     {
         (std::pointer_traits<void*>::element_type)0;
     }
+    return true;
+}
+
+int main() {
+    check();
+#if TEST_STD_VER > 17
+    static_assert(check(), "");
+#endif
 }




More information about the libcxx-commits mailing list