After doing a bit of research, I see that C++11 has a defect with allocators that require the type to be movable/copyable. I'm sure that this is the cause of this problem, however I am confused about the behavior between deleted and not declared move semantics.
I have the following code which fails to compile on both MSVC12 and Clang:
#include <vector> class Copyable { public: Copyable() = default; Copyable(Copyable const& other) : m_int(other.m_int) {} Copyable& operator= (Copyable const& other) { m_int = other.m_int; return *this; } Copyable(Copyable&&) = delete; Copyable& operator= (Copyable&&) = delete; private: int m_int = 100; }; int main() { std::vector<Copyable> objects; objects.push_back(Copyable{}); } This fails to compile on MSVC with:
xmemory0(600): error C2280: 'Copyable::Copyable(Copyable &&)' : attempting to reference a deleted function
And on Clang (live sample):
new_allocator.h:120:23: error: call to deleted constructor of 'Copyable'
In both cases, when I remove the explicitly deleted move construct/assign methods, the code compiles. AFAIK when you declare copy assign/construct methods, the compiler does not implicitly declare the corresponding move members. So they should still be effectively deleted, right? Why does the code compile when I remove the explicit deletion of move construct/assign?
What is a good workaround for this C++11 defect in general? I do not want my objects to be movable (but they are copyable).