You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"If is_trivially_move_constructible_v is true, this constructor is trivial."
That means the constructor might still be constexpr even if it's non-trivial.
It's not clear to me whether the constructor is required to be constexpr, but I think the test is wrong to assume the move construction can't be constexpr (the test compiles using the std::optional from libstdc++, but 'lit' expects it to be ill-formed).
The text was updated successfully, but these errors were encountered:
int main(int, char**)
{
static_assert(test(), "");
return 0;
}
fails to compile thus:
$ totclang2a junk.cpp
junk.cpp:14:16: error: constexpr function never produces a constant expression
[-Winvalid-constexpr]
constexpr bool test()
^
junk.cpp:17:27: note: non-constexpr constructor 'optional' cannot be used in a
constant expression
std::optional o2 = std::move(o1); // not constexpr
^
/Sources/LLVM/llvm-project/libcxx/include/optional:689:41: note: declared here
_LIBCPP_INLINE_VISIBILITY constexpr optional(optional&&) = default;
^
junk.cpp:24:19: error: static_assert expression is not an integral constant
expression
static_assert(test(), "");
^~~~~~
junk.cpp:17:27: note: non-constexpr constructor 'optional' cannot be used in a
constant expression
std::optional o2 = std::move(o1); // not constexpr
^
junk.cpp:24:19: note: in call to 'test()'
static_assert(test(), "");
^
/Sources/LLVM/llvm-project/libcxx/include/optional:689:41: note: declared here
_LIBCPP_INLINE_VISIBILITY constexpr optional(optional&&) = default;
^
2 errors generated.
Eric pointed out that you can't have a constexpr move-assignment operator for the non-trivial case, because it has to do a placement new (unless the optional that you are constructing from is empty)
That's why my second test fails.
Apparently libstdc++ is happy with this:
Extended Description
std/utilities/optional/optional.object/optional.object.ctor/move.fail.cpp
This test assumes that move construction is not constexpr, based on this old wording quoted in the test:
// constexpr optional(const optional&& rhs);
// If is_trivially_move_constructible_v is true,
// this constructor shall be a constexpr constructor.
That was replaced by https://wg21.link/p0602r4 and now it says:
"If is_trivially_move_constructible_v is true, this constructor is trivial."
That means the constructor might still be constexpr even if it's non-trivial.
It's not clear to me whether the constructor is required to be constexpr, but I think the test is wrong to assume the move construction can't be constexpr (the test compiles using the std::optional from libstdc++, but 'lit' expects it to be ill-formed).
The text was updated successfully, but these errors were encountered: