diff --git a/libcxx/docs/Cxx2aStatusIssuesStatus.csv b/libcxx/docs/Cxx2aStatusIssuesStatus.csv --- a/libcxx/docs/Cxx2aStatusIssuesStatus.csv +++ b/libcxx/docs/Cxx2aStatusIssuesStatus.csv @@ -278,7 +278,7 @@ "`3371 `__","``visit_format_arg``\ and ``make_format_args``\ are not hidden friends","Prague","" "`3372 `__","``vformat_to``\ should not try to deduce ``Out``\ twice","Prague","" "`3373 `__","``{to,from}_chars_result``\ and ``format_to_n_result``\ need the ""we really mean what we say"" wording","Prague","" -"`3374 `__","P0653 + P1006 should have made the other ``std::to_address``\ overload ``constexpr``\ ","Prague","" +"`3374 `__","P0653 + P1006 should have made the other ``std::to_address``\ overload ``constexpr``\ ","Prague","|Complete|" "`3375 `__","``decay``\ in ``viewable_range``\ should be ``remove_cvref``\ ","Prague","" "`3377 `__","``elements_view::iterator``\ befriends a specialization of itself","Prague","" "`3379 `__","""``safe``\ "" in several library names is misleading","Prague","" diff --git a/libcxx/include/memory b/libcxx/include/memory --- a/libcxx/include/memory +++ b/libcxx/include/memory @@ -46,7 +46,7 @@ }; template constexpr T* to_address(T* p) noexcept; // C++20 -template auto to_address(const Ptr& p) noexcept; // C++20 +template constexpr auto to_address(const Ptr& p) noexcept; // C++20 template struct allocator_traits @@ -1077,7 +1077,7 @@ } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY constexpr auto to_address(const _Pointer& __p) _NOEXCEPT { diff --git a/libcxx/test/std/utilities/memory/pointer.conversion/to_address.pass.cpp b/libcxx/test/std/utilities/memory/pointer.conversion/to_address.pass.cpp --- a/libcxx/test/std/utilities/memory/pointer.conversion/to_address.pass.cpp +++ b/libcxx/test/std/utilities/memory/pointer.conversion/to_address.pass.cpp @@ -11,7 +11,7 @@ // UNSUPPORTED: c++03, c++11, c++14, c++17 // template constexpr T* to_address(T* p) noexcept; -// template auto to_address(const Ptr& p) noexcept; +// template constexpr auto to_address(const Ptr& p) noexcept; #include #include @@ -22,10 +22,10 @@ public: using element_type = int; - explicit P1(int* p) + constexpr explicit P1(int* p) : p_(p) { } - int* operator->() const noexcept + constexpr int* operator->() const noexcept { return p_; } private: @@ -37,10 +37,10 @@ public: using element_type = int; - explicit P2(int* p) + constexpr explicit P2(int* p) : p_(p) { } - P1 operator->() const noexcept + constexpr P1 operator->() const noexcept { return p_; } private: @@ -50,10 +50,10 @@ class P3 { public: - explicit P3(int* p) + constexpr explicit P3(int* p) : p_(p) { } - int* get() const noexcept + constexpr int* get() const noexcept { return p_; } private: @@ -65,7 +65,7 @@ template<> struct pointer_traits<::P3> { - static int* to_address(const ::P3& p) noexcept + static constexpr int* to_address(const ::P3& p) noexcept { return p.get(); } }; } @@ -73,13 +73,13 @@ class P4 { public: - explicit P4(int* p) + constexpr explicit P4(int* p) : p_(p) { } - int* operator->() const noexcept + constexpr int* operator->() const noexcept { return nullptr; } - int* get() const noexcept + constexpr int* get() const noexcept { return p_; } private: @@ -91,7 +91,7 @@ template<> struct pointer_traits<::P4> { - static int* to_address(const ::P4& p) noexcept + constexpr static int* to_address(const ::P4& p) noexcept { return p.get(); } }; } @@ -99,23 +99,28 @@ int n = 0; static_assert(std::to_address(&n) == &n); -int main(int, char**) -{ - int i = 0; - ASSERT_NOEXCEPT(std::to_address(&i)); - assert(std::to_address(&i) == &i); - P1 p1(&i); - ASSERT_NOEXCEPT(std::to_address(p1)); - assert(std::to_address(p1) == &i); - P2 p2(&i); - ASSERT_NOEXCEPT(std::to_address(p2)); - assert(std::to_address(p2) == &i); - P3 p3(&i); - ASSERT_NOEXCEPT(std::to_address(p3)); - assert(std::to_address(p3) == &i); - P4 p4(&i); - ASSERT_NOEXCEPT(std::to_address(p4)); - assert(std::to_address(p4) == &i); +constexpr bool test() { + int i = 0; + ASSERT_NOEXCEPT(std::to_address(&i)); + assert(std::to_address(&i) == &i); + P1 p1(&i); + ASSERT_NOEXCEPT(std::to_address(p1)); + assert(std::to_address(p1) == &i); + P2 p2(&i); + ASSERT_NOEXCEPT(std::to_address(p2)); + assert(std::to_address(p2) == &i); + P3 p3(&i); + ASSERT_NOEXCEPT(std::to_address(p3)); + assert(std::to_address(p3) == &i); + P4 p4(&i); + ASSERT_NOEXCEPT(std::to_address(p4)); + assert(std::to_address(p4) == &i); + + return true; +} +int main(int, char**) { + test(); + static_assert(test()); return 0; }