[英]Which compiler is standard compliant?
Given this snippet: 给出以下代码段:
template <std::size_t Index, typename T, typename ...Args>
typename type_at<Index, T, Args...>::type
get(T t1, Args... args)
{
return
static_cast<type_at<Index, T, Args...>::type>
(
reinterpret_cast<void*>
(
value_at<Index, T, Args...>::get(t1, args...)
)
);
}
int main()
{
int * a = new int(10);
double* b = new double(3.14);
std::string c = "But I'm a string :(";
std::cout<< *get<0>(a, b, &c) <<"\n";
std::cout<< *get<1>(a, b, &c) <<"\n";
std::cout<< *get<2>(a, b, &c) <<"\n";
}
that doesn't work on GCC 4.8.1 but compiles and runs fine in VS2012 with the Nov CTP compiler ( didn't try clang by the way ) 在GCC 4.8.1上不起作用,但可以使用Nov CTP编译器在VS2012中编译并正常运行(顺便说一下,没有尝试clang)
Which compiler is right? 哪个编译器正确?
In this particular case GCC is more standard compliant as you are missing typename
when referring to a dependent type in type_at<Index, T, Args...>::type
part of your code. 在这种特殊情况下GCC是更符合标准的为你缺少
typename
在提到一个相关的类型时type_at<Index, T, Args...>::type
代码的一部分。
Clang is also doing a similar thing and gives a nice error message (as always): Clang也在做类似的事情,并给出了一个不错的错误消息(一如既往):
./test.cc:40:29: error: missing 'typename' prior to dependent type name 'type_at<Index, T, Args...>::type'
static_cast<type_at<Index, T, Args...>::type>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
typename
1 error generated.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.