简体   繁体   English

Clang自动变量模板bug

[英]Clang auto variable template bug

I went to see if you could use auto in a variable template declaration. 我去看看你是否可以在变量模板声明中使用auto。

template <typename T>
auto F = T{};

Fine, but as soon as you try to use it, clang craps. 很好,但是一旦你尝试使用它,就会嘎吱作响。

int f = F<int>; // error: cannot initialize a variable of type 'int' with an lvalue of type 'auto'
auto f = F<int>; // Stacktrace
decltype(F<int>) f = F<int>; // StackFace
std::cout << std::is_same<int, decltype(F<int>)>::value; // false
std::cout << typeid(decltype(F<int>)).name(); // Stacktrace
std::cout << std::is_same<decltype(F<int>), decltype(F<int>)>::value; // true

Any combination of decltype(auto) , auto doesn't work even though it says that auto is an lvalue. decltype(auto)auto任何组合都不起作用,即使它表示auto是一个左值。

int f = static_cast<int>(F<int>); // error: static_cast from 'auto' to 'int' is not allowed

I've never seen auto act this way before. 我以前从未见过这种方式。 Is it because of variable templates or because of how clang treats auto? 是因为变量模板还是因为clang如何对待auto?

This seems to be addressed in the latest version of clang ; 这似乎是在最新版本的clang ; putting that into a file and calling 将它放入文件并调用

clang++ -std=c++1y test.cpp

gives me no errors. 没有错误。

kevinushey@Kevin-MBP:~$ clang++ -v
clang version 3.5 (trunk 201469)
Target: x86_64-apple-darwin13.0.0
Thread model: posix

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM