详题:为什么std:variant的operator=(T&& t)的noexcept规范不依赖于内部类型的析构函数的noexcept规范?
我可以在cppreference上看到
template <class T> variant& operator=(T&& t) noexcept(/* see below */);
Run Code Online (Sandbox Code Playgroud)
是
noexcept(std::is_nothrow_assignable_v<T_j&, T> &&
std::is_nothrow_constructible_v<T_j, T>)
Run Code Online (Sandbox Code Playgroud)
所以这个编译:
struct FooThrow {
~FooThrow() noexcept(false) {throw;}
};
static_assert(std::is_nothrow_assignable_v<std::variant<FooThrow, int>, int>);
Run Code Online (Sandbox Code Playgroud)
但它调用FooThrow的析构函数是noexcept(false):
std::variant<FooThrow, int> x;
x = 3; // throws
Run Code Online (Sandbox Code Playgroud)
这似乎不对.我错过了什么吗?