Reputation: 365
I went to see if you could use auto in a variable template declaration.
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.
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?
Upvotes: 4
Views: 330
Reputation: 21315
This seems to be addressed in the latest version of 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
Upvotes: 1