我试图编译克++下面的程序 - 4.7(20120228-1):模板偏特扩展到外类型的结果在歧义
#include <cstdlib>
#include <tuple>
template<typename X> struct Y {};
template<typename T, size_t Level, size_t TermLevel> struct A;
// (B) dummy for T=tuple<int, Ts...> just to show it works for simple expansions
template<typename ... Ts, size_t Level, size_t TermLevel>
struct A<std::tuple<int, Ts...>, Level, TermLevel>
{
A<std::tuple<int, Ts...>, Level+1, TermLevel> value;
};
template<typename ... Ts, size_t Level>
struct A<std::tuple<int, Ts...>, Level, Level> {};
// (C) ambiguous partial specialization
template<typename ... Ts, size_t Level, size_t TermLevel>
struct A<std::tuple<Y<Ts>...>, Level, TermLevel>
{
A<std::tuple<Y<Ts>...>, Level+1, TermLevel> value;
};
template<typename ... Ts, size_t Level>
struct A<std::tuple<Y<Ts>...>, Level, Level> {};
int main(int argc, const char *argv[])
{
A<std::tuple<int, float, int>, 0, 5> tint;
A<std::tuple<Y<int>, Y<float>>, 0, 1> tn;
return 0;
}
这导致歧义如下:
g++-4.7 -g -O0 -std=c++0x specialization_orig.cc -o specialization_orig
specialization_orig.cc: In instantiation of 'struct A<std::tuple<Y<int>, Y<float> >, 0ul, 1ul>':
specialization_orig.cc:33:43: required from here
specialization_orig.cc:23:49: error: ambiguous class template instantiation for 'struct A<std::tuple<Y<int>, Y<float> >, 1ul, 1ul>'
specialization_orig.cc:21:8: error: candidates are: struct A<std::tuple<Y<Ts>...>, Level, TermLevel>
specialization_orig.cc:27:8: error: struct A<std::tuple<Y<Ts>...>, Level, Level>
specialization_orig.cc:23:49: error: 'A<std::tuple<Y<Ts>...>, Level, TermLevel>::value' has incomplete type
specialization_orig.cc:6:61: error: declaration of 'struct A<std::tuple<Y<int>, Y<float> >, 1ul, 1ul>'
这是因为一种奇怪的可变参数参数扩建工程的论证组的简单扩大,而是作为一个可变参数包扩展到嵌套一些其他的模板类型中一旦出现故障。
这是简单的编译器疯狂还是我做什么可怕的错误?
ICC拒绝这一代码以及与 “错误:一个以上的部分特类的模板参数列表匹配 ”A <性病::元组,Y >,1UL,1UL>“ ” A <性病::元组 ...>,水准仪,TermLevel>” “A <性病::元组 ...>,级别,级别>” A <性病::元组 ...> Level + 1,TermLevel> value;“,但CLang接受它。任何人只要有科莫或新的足够VC++可以试试这个,因为我没有获得VS2013和科莫尝试,它出的是跌? –
LThode
2014-11-12 20:15:09