[libcxx-commits] [libcxx] r359162 - Update test to better check for the non-constexpr-ness of a move constructor. Fixes PR#41577.
Marshall Clow via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Apr 24 19:12:51 PDT 2019
Author: marshall
Date: Wed Apr 24 19:12:51 2019
New Revision: 359162
URL: http://llvm.org/viewvc/llvm-project?rev=359162&view=rev
Log:
Update test to better check for the non-constexpr-ness of a move constructor. Fixes PR#41577.
Modified:
libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/move.fail.cpp
Modified: libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/move.fail.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/move.fail.cpp?rev=359162&r1=359161&r2=359162&view=diff
==============================================================================
--- libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/move.fail.cpp (original)
+++ libcxx/trunk/test/std/utilities/optional/optional.object/optional.object.ctor/move.fail.cpp Wed Apr 24 19:12:51 2019
@@ -10,8 +10,17 @@
// <optional>
// constexpr optional(const optional<T>&& rhs);
+// C++17 said:
// If is_trivially_move_constructible_v<T> is true,
// this constructor shall be a constexpr constructor.
+//
+// P0602 changed this to:
+// If is_trivially_move_constructible_v<T> is true, this constructor is trivial.
+//
+// which means that it can't be constexpr if T is not trivially move-constructible,
+// because you have to do a placement new to get the value into place.
+// Except in the case where it is moving from an empty optional - that could be
+// made to be constexpr (and libstdc++ does so).
#include <optional>
#include <type_traits>
@@ -23,16 +32,22 @@ struct S {
constexpr S() : v_(0) {}
S(int v) : v_(v) {}
constexpr S(const S &rhs) : v_(rhs.v_) {} // not trivially moveable
- constexpr S(const S &&rhs) : v_(rhs.v_) {} // not trivially moveable
+ constexpr S( S &&rhs) : v_(rhs.v_) {} // not trivially moveable
int v_;
};
+constexpr bool test() // expected-error {{constexpr function never produces a constant expression}}
+{
+ std::optional<S> o1{3};
+ std::optional<S> o2 = std::move(o1);
+ return o2.has_value(); // return -something-
+}
+
+
int main(int, char**)
{
static_assert (!std::is_trivially_move_constructible_v<S>, "" );
- constexpr std::optional<S> o1;
- constexpr std::optional<S> o2 = std::move(o1); // not constexpr
-
- return 0;
+ static_assert (test(), ""); // expected-error {{static_assert expression is not an integral constant expression}}
+ return 0;
}
More information about the libcxx-commits
mailing list