From: Marshall Clow Date: Thu, 25 Apr 2019 02:12:51 +0000 (+0000) Subject: Update test to better check for the non-constexpr-ness of a move constructor. Fixes... X-Git-Tag: llvmorg-10-init~7061 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=07161d6de353c2363cc721ba8940163146da82a5;p=platform%2Fupstream%2Fllvm.git Update test to better check for the non-constexpr-ness of a move constructor. Fixes PR#41577. llvm-svn: 359162 --- diff --git a/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/move.fail.cpp b/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/move.fail.cpp index a8634b9..8aae557 100644 --- a/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/move.fail.cpp +++ b/libcxx/test/std/utilities/optional/optional.object/optional.object.ctor/move.fail.cpp @@ -10,8 +10,17 @@ // // constexpr optional(const optional&& rhs); +// C++17 said: // If is_trivially_move_constructible_v is true, // this constructor shall be a constexpr constructor. +// +// P0602 changed this to: +// If is_trivially_move_constructible_v 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 #include @@ -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 o1{3}; + std::optional o2 = std::move(o1); + return o2.has_value(); // return -something- +} + + int main(int, char**) { static_assert (!std::is_trivially_move_constructible_v, "" ); - constexpr std::optional o1; - constexpr std::optional o2 = std::move(o1); // not constexpr - - return 0; + static_assert (test(), ""); // expected-error {{static_assert expression is not an integral constant expression}} + return 0; }