[PATCH] D53867: [libcxx] Implement http://wg21.link/p1006, constexpr in pointer_traits

Louis Dionne via Phabricator reviews at reviews.llvm.org
Tue Oct 30 14:56:53 PDT 2018


ldionne updated this revision to Diff 171809.
ldionne marked 4 inline comments as done.
ldionne added a comment.

Apply Marshall's comments


Repository:
  rCXX libc++

https://reviews.llvm.org/D53867

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


Index: libcxx/test/std/utilities/memory/pointer.traits/pointer_to.pass.cpp
===================================================================
--- libcxx/test/std/utilities/memory/pointer.traits/pointer_to.pass.cpp
+++ libcxx/test/std/utilities/memory/pointer.traits/pointer_to.pass.cpp
@@ -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 @@
     {
         (std::pointer_traits<void*>::element_type)0;
     }
+    return true;
+}
+
+int main() {
+    check();
+#if TEST_STD_VER > 17
+    static_assert(check(), "");
+#endif
 }
Index: libcxx/include/memory
===================================================================
--- libcxx/include/memory
+++ libcxx/include/memory
@@ -43,7 +43,7 @@
 
     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 @@
 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);}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53867.171809.patch
Type: text/x-patch
Size: 1756 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20181030/31a1f382/attachment-0001.bin>


More information about the libcxx-commits mailing list