Этот код не скомпилирован с gcc 4.8.2 (-std = С++ 11), но компилируется с clang 3.4 (trunk) (-std = С++ 11):
#include <type_traits>
#include <vector>
struct X {
X& operator=(X&&) noexcept = default;
// adding noexcept this leads to an error in gcc, but works in clang:
// function ‘X& X::operator=(X&&)’ defaulted on its first
// declaration with an exception-specification that differs from the
// implicit declaration ‘X& X::operator=(X&&)’
std::vector<char> m;
};
// this assert holds, even without noexcept
static_assert(std::is_nothrow_move_assignable<X>::value,
"type-specification violation");
int main()
{
return 0;
}
static_assert
- интересная часть gcc: присваивание по умолчанию будет noexcept
, но я не могу объявить его таким образом.
Вариант, не включающий vector
:
template<bool b>
struct F {
F& operator=(F&&) noexcept(b) {return *this;}
};
struct X {
X& operator=(X&&) noexcept = default;
F<true> f;
};
Каково ожидаемое поведение здесь? Интуитивно clang кажется правильным.