简体   繁体   English

自动模板参数:g ++ 7.3 vs clang ++ 6.0:哪个编译器正确?

[英]auto template parameters: g++ 7.3 vs clang++ 6.0 : Which compiler is correct?

Two compilers produce different results for this code example. 对于此代码示例,两个编译器产生不同的结果。 Clang generates two different types. lang产生两种不同的类型。 G++ uses same type for fu and fi . G ++对fufi使用相同的类型。 Which one is standard compliant? 哪一个符合标准?

#include <iostream>

template< auto IVAL>
struct foo {
    decltype(IVAL) x = -IVAL;
};

int main()
{
    foo<10u> fu;
    foo<10> fi;
    std::cout << fi.x << " " << fu.x << '\n';
    return 0;
}

g++-7.3 output: g ++-7.3输出:

4294967286 4294967286 4294967286 4294967286

clang-6.0 output: clang-6.0输出:

-10 4294967286 -10 4294967286

gcc is wrong here, these are clearly two distinct types. gcc在这里是错误的,显然这是两种不同的类型。

And to confirm - this bug is fixed in gcc 8.0.1 并确认-此错误已在gcc 8.0.1中修复

Sample code 样例代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 g ++和clang ++使用自动参数的模板特化的不同行为 - g++ and clang++ different behaviour with template specialization for auto argument g ++ / clang ++中带有makefile的参数顺序 - Order of parameters in g++/clang++ with makefile g ++和clang ++不同的行为推导可变参数模板`auto`值 - g++ and clang++ different behaviour deducing variadic template `auto` values 函数指针的模板参数推导(g ++&ICC vs Clang ++&VC ++) - template argument deduction for function pointer (g++ & ICC vs Clang++ & VC++ ) 这是 g++ 或 clang++ 中的错误 - Is this a bug in g++ or clang++ g ++和clang ++使用变量模板和SFINAE的不同行为 - g++ and clang++ different behaviour with variable template and SFINAE 编译模板类因g ++或clang ++失败 - Compile template class failed by g++ or clang++ g ++和clang ++使用指向可变参数模板函数的指针的不同行为 - g++ and clang++ different behaviour with pointer to variadic template functions 使用lambdas的变量模板:使用g ++但使用clang ++运行时出错 - Variadic template using lambdas : error with g++ but running with clang++ `apply`模板在g ++中编译,但不在clang ++和vc ++中编译 - `apply` template compiles in g++ but not in clang++ and vc++
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM