vendredi 1 décembre 2017

Move-only type related error on MSVC 2017

I am moving my project from VS2015 to VS2017, which of course does not go smoothly.

I am seeing strange compiler error that can be reproduced by the following code:

struct MoveOnly
{
    MoveOnly() {}
    MoveOnly(const MoveOnly&) = delete;
    MoveOnly& operator = (const MoveOnly&) = delete;
    MoveOnly(MoveOnly&&) = default;
    MoveOnly& operator = (MoveOnly&&) = default;
    bool operator == (const MoveOnly& rhs)const{return false;}
};
struct Hasher
{
    size_t operator()(const MoveOnly&)const{return 0;}
};
std::vector < std::unordered_map<MoveOnly, int, Hasher> > test;
test.emplace_back();

I can successfully compile this code with all compilers (gcc 7.2, clang 5.0.0, icc 18, as well as MSVC 2015). Please follow this link to see the test: http://ift.tt/2AO7CjQ. On MSVC 2017, however there is an error that is caused by the compiler trying to reference deleted copy constructor of MoveOnly type. This error does not make much sense to me, because there is no reason to copy anything here instead of moving. Also the fact the gcc and clang handle the code correctly makes me suspicious about msvc 2017 compiler.

Aucun commentaire:

Enregistrer un commentaire