It seems that adding a default constructor prevents from calling emplace_back and produces the error message: "static assertion failed: type is not assignable" (gcc 5.3 with -std=c++14). Here is a simple code that illustrates the issue:
class A { public: int a; A() = default; A(int a) { this->a = a; } A(A const & a) = delete; A& operator =(A const & a) = delete; A(A && a) = default; A& operator =(A && a) = default; }; int main() { A a(4); std::vector<A> vec; vec.emplace_back(std::move(a)); // Error: type is not assignable return 0; } When removing the default constructor, the error goes away! Also, if the default constructor is defined (even if it does nothing), the error also goes away:
class A { public: int a; A() { } A(int a) { this->a = a; } A(A const & a) = delete; A& operator =(A const & a) = delete; A(A && a) = default; A& operator =(A && a) = default; }; int main() { A b; A a(4); std::vector<A> vec; vec.emplace_back(std::move(a)); // Error gone return 0; } It seems that "A() = default;" is what is causing the problem. Is this normal behaviour on part of the compiler or is it a bug?
emplace_backfor trivial types to amemcpycall, and that call chain involves calling a function that asserts that the type is copy assignable.A() = default;might be trivial, butA() {}definitely isn't. That can affect optimisations (as in this case, although here the std::lib's attempt to optimise has a bug).