简体   繁体   English

哪个编译器符合标准?

[英]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? 哪个编译器正确?

full example 完整的例子

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.

相关问题 MSVC 2010 是符合 C++11 标准的编译器吗 - Is MSVC 2010 a C++11-standard-compliant compiler 是否有完全符合标准的方法使编译器在源文件中粘贴文件的确切(二进制)内容? - Is there a fully Standard compliant way to make the compiler paste the exact (binary) contents of a file in a source file? 此代码标准是否兼容? - Is this code standard compliant or not? 符合标准的自定义分配器 - Standard compliant custom allocator 此枚举声明是否符合标准? - Is this enum declaration a standard compliant? 是否有哪个编译器支持 C++ 标准的哪个部分的列表? - Is there a list of which compiler supports which part of the C++ standard? 我可以将带有 arg uint 的模板实例转换为带有 arg int 的相同模板实例吗?它符合哪个标准? - can i cast a template instance with arg uint to same template instance with arg int - is it compliant - to which standard? 符合标准的编译器是否可以拒绝包含非多态类型的dynamic_cast downcast的代码? - Can a standard-compliant compiler reject code containing dynamic_cast downcast from non-polymorphic type? Nifty / Schwarz计数器,符合标准? - Nifty/Schwarz counter, standard compliant? 测试自定义符合标准的容器 - Testing custom standard compliant containers
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM