[llvm-branch-commits] [libcxx] f632673 - [libc++] [LWG3374] Mark `to_address(const Ptr& p)` overload `constexpr`.
Marek Kurdej via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Dec 6 06:30:39 PST 2020
Author: Marek Kurdej
Date: 2020-12-06T15:26:26+01:00
New Revision: f6326736ba166f0a9bfa4e9be019f84fc3143651
URL: https://github.com/llvm/llvm-project/commit/f6326736ba166f0a9bfa4e9be019f84fc3143651
DIFF: https://github.com/llvm/llvm-project/commit/f6326736ba166f0a9bfa4e9be019f84fc3143651.diff
LOG: [libc++] [LWG3374] Mark `to_address(const Ptr& p)` overload `constexpr`.
Reviewed By: ldionne, #libc
Differential Revision: https://reviews.llvm.org/D92659
Added:
Modified:
libcxx/docs/Cxx2aStatusIssuesStatus.csv
libcxx/include/memory
libcxx/test/std/utilities/memory/pointer.conversion/to_address.pass.cpp
Removed:
################################################################################
diff --git a/libcxx/docs/Cxx2aStatusIssuesStatus.csv b/libcxx/docs/Cxx2aStatusIssuesStatus.csv
index 4c78b1655631..4ef24005a3c0 100644
--- a/libcxx/docs/Cxx2aStatusIssuesStatus.csv
+++ b/libcxx/docs/Cxx2aStatusIssuesStatus.csv
@@ -278,7 +278,7 @@
"`3371 <https://wg21.link/LWG3371>`__","``visit_format_arg``\ and ``make_format_args``\ are not hidden friends","Prague","",""
"`3372 <https://wg21.link/LWG3372>`__","``vformat_to``\ should not try to deduce ``Out``\ twice","Prague","",""
"`3373 <https://wg21.link/LWG3373>`__","``{to,from}_chars_result``\ and ``format_to_n_result``\ need the ""we really mean what we say"" wording","Prague","",""
-"`3374 <https://wg21.link/LWG3374>`__","P0653 + P1006 should have made the other ``std::to_address``\ overload ``constexpr``\ ","Prague","",""
+"`3374 <https://wg21.link/LWG3374>`__","P0653 + P1006 should have made the other ``std::to_address``\ overload ``constexpr``\ ","Prague","|Complete|","12.0"
"`3375 <https://wg21.link/LWG3375>`__","``decay``\ in ``viewable_range``\ should be ``remove_cvref``\ ","Prague","",""
"`3377 <https://wg21.link/LWG3377>`__","``elements_view::iterator``\ befriends a specialization of itself","Prague","",""
"`3379 <https://wg21.link/LWG3379>`__","""``safe``\ "" in several library names is misleading","Prague","",""
diff --git a/libcxx/include/memory b/libcxx/include/memory
index 402a735419c8..77d7b67112e3 100644
--- a/libcxx/include/memory
+++ b/libcxx/include/memory
@@ -46,7 +46,7 @@ struct pointer_traits<T*>
};
template <class T> constexpr T* to_address(T* p) noexcept; // C++20
-template <class Ptr> auto to_address(const Ptr& p) noexcept; // C++20
+template <class Ptr> constexpr auto to_address(const Ptr& p) noexcept; // C++20
template <class Alloc>
struct allocator_traits
@@ -1077,7 +1077,7 @@ to_address(_Tp* __p) _NOEXCEPT
}
template <class _Pointer>
-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
index 2b9928f4df7e..26eba0e06cff 100644
--- 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 <class T> constexpr T* to_address(T* p) noexcept;
-// template <class Ptr> auto to_address(const Ptr& p) noexcept;
+// template <class Ptr> constexpr auto to_address(const Ptr& p) noexcept;
#include <memory>
#include <cassert>
@@ -22,10 +22,10 @@ class P1
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 @@ class P2
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 P2
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 @@ namespace std
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 @@ struct pointer_traits<::P3>
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 @@ namespace std
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 @@ struct pointer_traits<::P4>
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;
}
More information about the llvm-branch-commits
mailing list