在可变扩展

时间:2015-10-17 23:00:03

标签: c++ visual-c++ g++ visual-studio-2015 constexpr

我发现一些代码似乎是VC ++ 15(Visual Studio 2015)中的一个错误。它在GCC和clang中编译,但不包括VC ++。

无论如何,代码可以说明一切(我想,请留下评论!)

template<typename T>
struct doThing
{
    static int constexpr getNum() { return 3; };
};

template<int... ints>
struct iAcceptInts
{

};

template<typename... T>
void forwardThis()
{
    iAcceptInts<T::getNum()...> a; // ERROR: there are no parameter packs available to expand   
                                   //AND ERROR: term does not evaluate to a function taking 0 arguments

}

int main()
{
    forwardThis<doThing<int>, doThing<bool>, doThing<char>>();
}

这似乎应该有效,特别是考虑到它在GCC和Clang中编译。

它产生的错误信息是:

1>------ Build started: Project: CES, Configuration: Debug Win32 ------
1>  main.cpp
1>c:\users\russe\documents\visual studio 2015\projects\ces\main.cpp(59): error C3546: '...': there are no parameter packs available to expand
1>  c:\users\russe\documents\visual studio 2015\projects\ces\main.cpp(64): note: see reference to function template instantiation 'void forwardThis<doThing<int>,doThing<bool>,doThing<char>>(void)' being compiled
1>c:\users\russe\documents\visual studio 2015\projects\ces\main.cpp(59): error C2064: term does not evaluate to a function taking 0 arguments
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

在旁注中,使用非成员方法可以正常工作:

template<typename T>
constexpr int getNum() { return 3; }

template<typename T>
struct doThing
{
};

template<int... ints>
struct iAcceptInts
{

};

template<typename... T>
void forwardThis()
{
    iAcceptInts<getNum<T>()...> a;
}

int main()
{
    forwardThis<doThing<int>, doThing<bool>, doThing<char>>();
}

Here's the exact same code running like a champ on GCC

那你们觉得怎么样?编译错误?或者它不是一个广告功能?或者MSVC是否正确拒绝它?

0 个答案:

没有答案