The following code compiles well for Visual Studio < 17.2:
#include <optional>
#include <string>
#include <map>
class __declspec(dllexport) A {
public:
using M = std::map<std::string, A>;
private:
mutable std::optional<M> map_;
};
But failed for Visual Studio 17.2 and newer with an error:
example.cpp
...utility(330): error C2079: 'std::pair<const std::string,A>::second' uses undefined class 'A'
...optional(159): note: see reference to class template instantiation 'std::pair<const std::string,A>' being compiled
...optional(158): note: while compiling class template member function 'void std::_Optional_construct_base<_Ty>::_Construct_from<const _Base&>(_Self) noexcept(<expr>)'
with
[
_Ty=A::M,
_Base=std::_Optional_construct_base<A::M>,
_Self=const std::_Optional_construct_base<A::M> &
]
Compiler returned: 2
It works fine in any version if I drop __declspec(dllexport)
from the code or change std::optional
to boost::optional
.
Is this compiler bug, or I’m missing something?