Boost logo

Boost :

Subject: [boost] [utility][enable_if]Fiddly function lookup failure on msvc11
From: B (kenich.yamamoto_at_[hidden])
Date: 2013-10-06 16:41:05


Hi,

I found a part of my code failed to compile with boost::enable_if_c when I
was porting my code for msvc11 (Visual Studio 2012). The original code was
bit too complex but I simplified it to boil down the issue. The simplified
code is eventually like this:

#include <boost/mpl/bool.hpp>
#include <boost/mpl/not.hpp>
#include <boost/utility/enable_if.hpp>

template <class T>
struct always_true :
    boost::mpl::true_
{
};

template <class T> inline
typename boost::enable_if_c<
    !boost::mpl::not_<
        always_true<T> // Argument of boost::mpl::not_
>::type::value // Refer the result of boost::mpl::not_
, int
>::type
get_one(T)
{
    return 1;
}

void test()
{
    get_one('a'); // Compile fails at this line with error C2893
}

msvc11 fails to resolve the call to get_one() but I believe the code is
definitely correct. With some more extra test, I found:
(1)The same code compiles on msvc10 (Visual Studio 2010) and msvc9 (Visual
Studio 2008).

(2)If I changed the line I commented "//Argument of boost::mpl::not_" to
"boost::mpl::true_", the code compiled on msvc11.

template <class T> inline
typename boost::enable_if_c<
    !boost::mpl::not_<
        boost::mpl::true_ // *** Argument of boost::mpl::not_
>::type::value // Refer the result of boost::mpl::not_
, int
>::type
get_one(T)
{
    return 1;
}

(3)If changed the line I commented "// Refer the result
of boost::mpl::not_" to ">::value", the code compiled on msvc11.

template <class T> inline
typename boost::enable_if_c<
    !boost::mpl::not_<
        always_true<T> // Argument of boost::mpl::not_
>::value // *** Refer the result of boost::mpl::not_
, int
>::type
get_one(T)
{
    return 1;
}

The issue seems to be rather a compiler quirk of msvc11 than a enable_if's
problem, but I posted the issue here because we need a workaround to avoid
it (on msvc11) when we use enable_if. Please let me know if you have any
idea about the issue. Thanks.

Yamamoto


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk