Почему следующий код не компилируется? Статическое утверждение проверяет, что Foo не подлежит копированию, поэтому я ожидаю, что компилятор отбросит код в блоке constexpr-if, но это не так.
Код: Выделить всё
#include
struct Foo {
Foo() = default;
Foo const& operator=(Foo const&) = delete;
};
int main()
{
static_assert(!std::is_copy_assignable_v);
Foo x;
Foo other;
if constexpr (std::is_copy_assignable_v) {
other = x;
}
return 0;
}
Код: Выделить всё
: In function 'int main()':
:16:17: error: use of deleted function 'const Foo& Foo::operator=(const Foo&)'
16 | other = x;
| ^
:5:16: note: declared here
5 | Foo const& operator=(Foo const&) = delete;
| ^~~~~~~~
Compiler returned: 1
Источник: https://stackoverflow.com/questions/781 ... assignable