Make std::addressof constexpr in C++17 (Clang only).

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@263688 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier 2016-03-17 03:30:56 +00:00
parent 8b15aee1a1
commit 735026e3ee
4 changed files with 63 additions and 1 deletions

View File

@ -779,6 +779,12 @@ template <unsigned> struct __static_assert_check {};
#define _LIBCPP_CONSTEXPR_AFTER_CXX11
#endif
#if _LIBCPP_STD_VER > 14 && !defined(_LIBCPP_HAS_NO_CXX14_CONSTEXPR)
#define _LIBCPP_CONSTEXPR_AFTER_CXX14 constexpr
#else
#define _LIBCPP_CONSTEXPR_AFTER_CXX14
#endif
#ifdef _LIBCPP_HAS_NO_RVALUE_REFERENCES
# define _LIBCPP_EXPLICIT_MOVE(x) _VSTD::move(x)
#else

View File

@ -397,6 +397,18 @@ template <bool _Bp, class _Tp = void> using enable_if_t = typename enable_if<_Bp
#endif
// addressof
#if __has_builtin(__builtin_addressof)
template <class _Tp>
inline _LIBCPP_CONSTEXPR_AFTER_CXX14
_LIBCPP_NO_CFI _LIBCPP_INLINE_VISIBILITY
_Tp*
addressof(_Tp& __x) _NOEXCEPT
{
return __builtin_addressof(__x);
}
#else
template <class _Tp>
inline _LIBCPP_NO_CFI _LIBCPP_INLINE_VISIBILITY
@ -406,6 +418,8 @@ addressof(_Tp& __x) _NOEXCEPT
return (_Tp*)&reinterpret_cast<const volatile char&>(__x);
}
#endif // __has_builtin(__builtin_addressof)
#if defined(_LIBCPP_HAS_OBJC_ARC) && !defined(_LIBCPP_PREDEFINED_OBJC_ARC_ADDRESSOF)
// Objective-C++ Automatic Reference Counting uses qualified pointers
// that require special addressof() signatures. When

View File

@ -0,0 +1,42 @@
//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++98, c++03, c++11, c++14
// XFAIL: gcc
// <memory>
// template <ObjectType T> constexpr T* addressof(T& r);
#include <memory>
#include <cassert>
struct Pointer {
constexpr Pointer(void* v) : value(v) {}
void* value;
};
struct A
{
constexpr A() : n(42) {}
void operator&() const { }
int n;
};
constexpr int i = 0;
constexpr double d = 0.0;
constexpr A a{};
int main()
{
static_assert(std::addressof(i) == &i, "");
static_assert(std::addressof(d) == &d, "");
constexpr const A* ap = std::addressof(a);
static_assert(&ap->n == &a.n, "");
}

View File

@ -204,7 +204,7 @@
<tr><td></td><td></td><td></td><td></td></tr>
<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2192">2192</a></td><td>Validity and return type of <tt>std::abs(0u)</tt> is unclear</td><td>Jacksonville</td><td></td></tr>
<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2276">2276</a></td><td>Missing requirement on <tt>std::promise::set_exception</tt></td><td>Jacksonville</td><td></td></tr>
<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2296">2296</a></td><td><tt>std::addressof</tt> should be <tt>constexpr</td><td>Jacksonville</td><td></td></tr>
<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2296">2296</a></td><td><tt>std::addressof</tt> should be <tt>constexpr</td><td>Jacksonville</td><td>Complete (Clang Only)</td></tr>
<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2450">2450</a></td><td><tt>(greater|less|greater_equal|less_equal)&lt;void&gt;</tt> do not yield a total order for pointers</td><td>Jacksonville</td><td></td></tr>
<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2520">2520</a></td><td>N4089 broke initializing <tt>unique_ptr&lt;T[]&gt;</tt> from a <tt>nullptr</tt></td><td>Jacksonville</td><td></td></tr>
<tr><td><a href="http://cplusplus.github.io/LWG/lwg-defects.html#2522">2522</a></td><td>[fund.ts.v2] Contradiction in <tt>set_default_resource</tt> specification</td><td>Jacksonville</td><td></td></tr>