MSVC需要带有向量和映射的显式默认移动构造函数

N. *_*ead 7 c++ visual-c++ c++17

我遇到了MSVC的一个有趣问题.以下代码无法使用MSVC进行编译:

#include <vector>
#include <unordered_map>
#include <memory>
#include <string>

struct S {
    explicit S(const std::string&);

    // S(S&&) = default;

    std::vector<std::unique_ptr<int>> v;
    std::unordered_map<int, int> a;
    std::string s;
};

std::vector<S> foo() {
    std::vector<S> s;
    s.emplace_back("hello");
    s.emplace_back("world");
    return s;
}
Run Code Online (Sandbox Code Playgroud)

https://www.godbolt.ms/z/pQnKwD

然而,当无论是默认的移动构造函数提供,或者它编译无论是vectorunordered_map已被注释掉.评论这些emplace_back陈述也"解决"了这个问题.有趣的是,GCC或Clang不会出现这个问题(http://coliru.stacked-crooked.com/a/a4e5590bd63c0de0).

这里发生了什么?