[libc++] [LWG3374] Mark `to_address(const Ptr& p)` overload `constexpr`.

Reviewed By: ldionne, #libc

Differential Revision: https://reviews.llvm.org/D92659
This commit is contained in:
Marek Kurdej 2020-12-06 15:23:46 +01:00
parent db900995ed
commit f6326736ba
3 changed files with 37 additions and 32 deletions

View File

@ -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","",""

1 Issue # Issue Name Meeting Status First released version
278 `3371 <https://wg21.link/LWG3371>`__ ``visit_format_arg``\ and ``make_format_args``\ are not hidden friends Prague
279 `3372 <https://wg21.link/LWG3372>`__ ``vformat_to``\ should not try to deduce ``Out``\ twice Prague
280 `3373 <https://wg21.link/LWG3373>`__ ``{to,from}_chars_result``\ and ``format_to_n_result``\ need the "we really mean what we say" wording Prague
281 `3374 <https://wg21.link/LWG3374>`__ P0653 + P1006 should have made the other ``std::to_address``\ overload ``constexpr``\ Prague |Complete| 12.0
282 `3375 <https://wg21.link/LWG3375>`__ ``decay``\ in ``viewable_range``\ should be ``remove_cvref``\ Prague
283 `3377 <https://wg21.link/LWG3377>`__ ``elements_view::iterator``\ befriends a specialization of itself Prague
284 `3379 <https://wg21.link/LWG3379>`__ "``safe``\ " in several library names is misleading Prague

View File

@ -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
{

View File

@ -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 @@ private:
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;
}