std::tuple of no default constructible class makes compile error on MSVC2015 C++11 build
See:
#339 (comment)
#include <msgpack.hpp> struct no_def_con { no_def_con() = delete; no_def_con(int i) :i(i) {} int i; MSGPACK_DEFINE(i); }; namespace msgpack { MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) { namespace adaptor { template <> struct as<no_def_con> { no_def_con operator()(msgpack::object const& o) const { if (o.type != msgpack::type::ARRAY) throw msgpack::type_error(); if (o.via.array.size != 1) throw msgpack::type_error(); return no_def_con(o.via.array.ptr[0].as<int>()); } }; } // adaptor } // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) } // msgpack int main() { { // OK std::tuple<no_def_con> val1{ 1 }; msgpack::zone z; msgpack::object o(val1, z); o.as<std::tuple<no_def_con>>(); } { // ERROR std::tuple<no_def_con, no_def_con> val1{ 1, 2 }; msgpack::zone z; msgpack::object o(val1, z); // o.as<std::tuple<no_def_con, no_def_con>>(); // ERROR *1 } }
When the line *1 uncomment, I got the following compile error:
1>------ Build started: Project: no_def_con_tuple, Configuration: Debug Win32 ------
1> Source.cpp
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\tuple(69): error C2280: 'no_def_con::no_def_con(void)': attempting to reference a deleted function
1> c:\users\kondo\documents\visual studio 2015\projects\no_def_con_tuple\no_def_con_tuple\source.cpp(4): note: see declaration of 'no_def_con::no_def_con'
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\tuple(67): note: while compiling class template member function 'std::_Tuple_val<_This>::_Tuple_val(void)'
1> with
1> [
1> _This=no_def_con
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\tuple(181): note: see reference to function template instantiation 'std::_Tuple_val<_This>::_Tuple_val(void)' being compiled
1> with
1> [
1> _This=no_def_con
1> ]
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\tuple(462): note: see reference to class template instantiation 'std::_Tuple_val<_This>' being compiled
1> with
1> [
1> _This=no_def_con
1> ]
1> c:\users\kondo\documents\visual studio 2015\projects\no_def_con_tuple\no_def_con_tuple\source.cpp(27): note: see reference to class template instantiation 'std::tuple<no_def_con>' being compiled
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The error message indicates line 27:
std::tuple<no_def_con> val1{ 1 };but the line 36:
o.as<std::tuple<no_def_con, no_def_con>>(); // ERROR *1causes the compile error.
If the elements of the std::tuple is one, no errors are occurred, if the elements of the std::tuple are two or more, the compile error occurs.
This compile error only happens C++11 msgpack-c, So you can avoid the compile error with MSGPACK_USE_CPP03 macro definition.
I analyzed msgpack-c code. I think that https://github.com/msgpack/msgpack-c/blob/master/include/msgpack/adaptor/cpp11/tuple.hpp#L75 is something relate to the problem. This code works well on Linux with libstdc++ and osx with libc++. I think that MSVC2015's tuple implementation might have a problem. But I couldn't write a minimal code that reproduces the problem.
Any help is welcome.