c++boostboost-type-erasure

Ambiguous call when compiling boost.type_erasure with VS 2015 community


I try to use boost.type_erasure (version 1.59) on the free function `foo' as shown below.

#include <boost/type_erasure/any.hpp>
#include <boost/type_erasure/free.hpp>

void Foo(int);

BOOST_TYPE_ERASURE_FREE((HasFoo), Foo, 1)

using Type = boost::type_erasure::any<
    HasFoo<void(boost::type_erasure::_self const&)>,
    boost::type_erasure::_self const&
>;

void Foo(int) {}

int main() {
    Type x{ 1 };
    Foo(x);

    return 0;
}

It compiles according to my tests on coliru with GCC and CLang. However, VS 2015 community gives the following error message.

Source.cpp
Source.cpp(17): error C2668: 'boost::type_erasure::injectHasFoo<R (const boost::type_erasure::_self &),Base,boost::type_erasure::index_list<0>>::Foo': ambiguous call to overloaded function
        with
        [
            R=void,
            Base=boost::type_erasure::any_base<boost::type_erasure::any<HasFoo<void (const boost::type_erasure::_self &)>,boost::type_erasure::_self &&>>
        ]
Source.cpp(6): note: could be 'void boost::type_erasure::injectHasFoo<R (const boost::type_erasure::_self &),Base,boost::type_erasure::index_list<0>>::Foo(eval_if_c<0,boost::type_erasure::detail::maybe_const_this_param<const boost::type_erasure::_self &,Base>,boost::type_erasure::as_param<Base,const boost::type_erasure::_self &>>::type)' [found using argument-dependent lookup]
        with
        [
            R=void,
            Base=boost::type_erasure::any_base<boost::type_erasure::any<HasFoo<void (const boost::type_erasure::_self &)>,boost::type_erasure::_self &&>>
        ]
Source.cpp(6): note: or       'void boost::type_erasure::injectHasFoo<R (const boost::type_erasure::_self &),Base,boost::type_erasure::index_list<0>>::Foo(eval_if_c<0,boost::type_erasure::detail::maybe_const_this_param<const boost::type_erasure::_self &,Base>,boost::type_erasure::as_param<Base,const boost::type_erasure::_self &>>::type)' [found using argument-dependent lookup]
        with
        [
            R=void,
            Base=boost::type_erasure::any_base<boost::type_erasure::any<HasFoo<void (const boost::type_erasure::_self &)>,boost::type_erasure::_self &>>
        ]
Source.cpp(6): note: or       'void boost::type_erasure::injectHasFoo<R (const boost::type_erasure::_self &),Base,boost::type_erasure::index_list<0>>::Foo(eval_if_c<0,boost::type_erasure::detail::maybe_const_this_param<const boost::type_erasure::_self &,Base>,boost::type_erasure::as_param<Base,const boost::type_erasure::_self &>>::type)' [found using argument-dependent lookup]
        with
        [
            R=void,
            Base=boost::type_erasure::any_base<boost::type_erasure::any<HasFoo<void (const boost::type_erasure::_self &)>,boost::type_erasure::_self>>
        ]
Source.cpp(6): note: or       'void boost::type_erasure::injectHasFoo<R (const boost::type_erasure::_self &),Base,boost::type_erasure::index_list<0>>::Foo(eval_if_c<0,boost::type_erasure::detail::maybe_const_this_param<const boost::type_erasure::_self &,Base>,boost::type_erasure::as_param<Base,const boost::type_erasure::_self &>>::type)' [found using argument-dependent lookup]
        with
        [
            R=void,
            Base=boost::type_erasure::any_base<boost::type_erasure::any<HasFoo<void (const boost::type_erasure::_self &)>,const boost::type_erasure::_self &>>
        ]
Source.cpp(13): note: or       'void Foo(int)'
Source.cpp(17): note: while trying to match the argument list '(Type)'

Solution

  • According to the response from Boost-users mailing list, it is caused by the variadic template bug of VS. And the code compiles by defining BOOST_NO_CXX11_VARIADIC_TEMPLATES.