mapbox / variant

C++11/C++14 Variant
BSD 3-Clause "New" or "Revised" License
371 stars 101 forks source link

recursive_wrapper fail to compile when used with 2 classes which are base and derived #146

Closed BlueSolei closed 7 years ago

BlueSolei commented 7 years ago

The following code fails to compile (Visual Studio 2015 update 3):

#include <mapbox/variant.hpp>
using namespace mapbox::util;

struct Base;
struct Derived;
using Variant = variant<recursive_wrapper<Base>, recursive_wrapper<Derived>>;

struct Base { };
struct Derived : public Base { };

void TestMultipleRecursiveWrappers()
{
    Base base;
    Derived derived;
    Variant v;
    v = base;
    v = derived; // error
}

void OrEvenShorterExample()
{
        Derived derived;
    Variant v(derived); // error
}

error C2664: 'mapbox::util::variant<mapbox::util::recursive_wrapper,mapbox::util::recursive_wrapper>::variant(mapbox::util::variant<mapbox::util::recursive_wrapper,mapbox::util::recursive_wrapper> &&) noexcept()': cannot convert argument 1 from 'Derived' to 'mapbox::util::no_init' note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

artemp commented 7 years ago

Fixed in #147, closing.