I've run into an interesting issue with MSVC. The following code does not compile with 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;
}
https://www.godbolt.ms/z/pQnKwD
However, it does compile when either a defaulted move constructor is provided, or either the vector
or the unordered_map
are commented out. Commenting out the emplace_back
statements also "solves" the problem. The problem does not occur with GCC or Clang, interestingly (http://coliru.stacked-crooked.com/a/a4e5590bd63c0de0).
What's going on here?