[libcxx] r304813 - add missing constexpr to optional::value_or
Casey Carter via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 6 11:47:27 PDT 2017
Author: caseycarter
Date: Tue Jun 6 13:47:26 2017
New Revision: 304813
URL: http://llvm.org/viewvc/llvm-project?rev=304813&view=rev
Log:
add missing constexpr to optional::value_or
[Credit to cpplearner]
Differential Revision: https://reviews.llvm.org/D27850
Modified:
libcxx/trunk/include/optional
libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.observe/value_or.pass.cpp
Modified: libcxx/trunk/include/optional
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/optional?rev=304813&r1=304812&r2=304813&view=diff
==============================================================================
--- libcxx/trunk/include/optional (original)
+++ libcxx/trunk/include/optional Tue Jun 6 13:47:26 2017
@@ -897,7 +897,7 @@ public:
template <class _Up>
_LIBCPP_INLINE_VISIBILITY
- value_type value_or(_Up&& __v) &&
+ constexpr value_type value_or(_Up&& __v) &&
{
static_assert(is_move_constructible_v<value_type>,
"optional<T>::value_or: T must be move constructible");
Modified: libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.observe/value_or.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.observe/value_or.pass.cpp?rev=304813&r1=304812&r2=304813&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.observe/value_or.pass.cpp (original)
+++ libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.observe/value_or.pass.cpp Tue Jun 6 13:47:26 2017
@@ -10,7 +10,7 @@
// UNSUPPORTED: c++98, c++03, c++11, c++14
// <optional>
-// template <class U> T optional<T>::value_or(U&& v) &&;
+// template <class U> constexpr T optional<T>::value_or(U&& v) &&;
#include <optional>
#include <type_traits>
@@ -26,22 +26,22 @@ struct Y
{
int i_;
- Y(int i) : i_(i) {}
+ constexpr Y(int i) : i_(i) {}
};
struct X
{
int i_;
- X(int i) : i_(i) {}
- X(X&& x) : i_(x.i_) {x.i_ = 0;}
- X(const Y& y) : i_(y.i_) {}
- X(Y&& y) : i_(y.i_+1) {}
+ constexpr X(int i) : i_(i) {}
+ constexpr X(X&& x) : i_(x.i_) {x.i_ = 0;}
+ constexpr X(const Y& y) : i_(y.i_) {}
+ constexpr X(Y&& y) : i_(y.i_+1) {}
friend constexpr bool operator==(const X& x, const X& y)
{return x.i_ == y.i_;}
};
-int main()
+constexpr int test()
{
{
optional<X> opt(in_place, 2);
@@ -65,4 +65,10 @@ int main()
assert(std::move(opt).value_or(Y(3)) == 4);
assert(!opt);
}
+ return 0;
+}
+
+int main()
+{
+ static_assert(test() == 0);
}
More information about the cfe-commits
mailing list