From 01a0e90783b3ead5eb0854b71017fd2470e65188 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Mon, 15 Jul 2013 20:46:11 +0000 Subject: [PATCH] Make std::forward and std::move (and std::move_if_noexcept) constexpr in C++14 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@186344 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/tuple | 2 +- include/type_traits | 6 +++--- include/utility | 10 +++++----- test/utilities/utility/forward/forward.pass.cpp | 7 +++++++ .../utility/forward/move_if_noexcept.pass.cpp | 6 ++++++ 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/include/tuple b/include/tuple index d8a36e6e..c7a1c143 100644 --- a/include/tuple +++ b/include/tuple @@ -843,7 +843,7 @@ template inline _LIBCPP_INLINE_VISIBILITY constexpr _T1&& get(tuple<_Args...>&& __tup) noexcept { - return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move>(__tup)); + return _VSTD::get<__find_exactly_one_t<_T1, _Args...>::value>(_VSTD::move(__tup)); } #endif diff --git a/include/type_traits b/include/type_traits index dd84abf2..3d3ae5ea 100644 --- a/include/type_traits +++ b/include/type_traits @@ -1466,7 +1466,7 @@ struct is_destructible #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 typename remove_reference<_Tp>::type&& move(_Tp&& __t) _NOEXCEPT { @@ -1475,7 +1475,7 @@ move(_Tp&& __t) _NOEXCEPT } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp&& forward(typename std::remove_reference<_Tp>::type& __t) _NOEXCEPT { @@ -1483,7 +1483,7 @@ forward(typename std::remove_reference<_Tp>::type& __t) _NOEXCEPT } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 _Tp&& forward(typename std::remove_reference<_Tp>::type&& __t) _NOEXCEPT { diff --git a/include/utility b/include/utility index 3e4b401f..46a8803a 100644 --- a/include/utility +++ b/include/utility @@ -38,10 +38,10 @@ template void swap(T (&a)[N], T (&b)[N]) noexcept(noexcept(swap(*a, *b))); -template T&& forward(typename remove_reference::type& t) noexcept; -template T&& forward(typename remove_reference::type&& t) noexcept; +template T&& forward(typename remove_reference::type& t) noexcept; // constexpr in C++14 +template T&& forward(typename remove_reference::type&& t) noexcept; // constexpr in C++14 -template typename remove_reference::type&& move(T&&) noexcept; +template typename remove_reference::type&& move(T&&) noexcept; // constexpr in C++14 template typename conditional @@ -50,7 +50,7 @@ template const T&, T&& >::type - move_if_noexcept(T& x) noexcept; + move_if_noexcept(T& x) noexcept; // constexpr in C++14 template typename add_rvalue_reference::type declval() noexcept; @@ -221,7 +221,7 @@ swap(_Tp (&__a)[_Np], _Tp (&__b)[_Np]) _NOEXCEPT_(__is_nothrow_swappable<_Tp>::v } template -inline _LIBCPP_INLINE_VISIBILITY +inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR_AFTER_CXX11 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES typename conditional < diff --git a/test/utilities/utility/forward/forward.pass.cpp b/test/utilities/utility/forward/forward.pass.cpp index b62eed5d..aed396ee 100644 --- a/test/utilities/utility/forward/forward.pass.cpp +++ b/test/utilities/utility/forward/forward.pass.cpp @@ -70,4 +70,11 @@ int main() static_assert(sizeof(test(std::forward(ca))) == 2, ""); static_assert(sizeof(test(std::forward(csource()))) == 2, ""); #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES + +#if _LIBCPP_STD_VER > 11 + constexpr int i1 = std::move(23); + static_assert(i1 == 23, "" ); + constexpr int i2 = std::forward(42); + static_assert(i2 == 42, "" ); +#endif } diff --git a/test/utilities/utility/forward/move_if_noexcept.pass.cpp b/test/utilities/utility/forward/move_if_noexcept.pass.cpp index 8a0eba01..4a07467b 100644 --- a/test/utilities/utility/forward/move_if_noexcept.pass.cpp +++ b/test/utilities/utility/forward/move_if_noexcept.pass.cpp @@ -60,4 +60,10 @@ int main() #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES static_assert((std::is_same::value), ""); +#if _LIBCPP_STD_VER > 11 + constexpr int i1 = 23; + constexpr int i2 = std::move_if_noexcept(i1); + static_assert(i2 == 23, "" ); +#endif + }