【问题标题】:Clang auto variable template bugClang 自动变量模板错误
【发布时间】:2014-02-15 19:29:41
【问题描述】:

我去看看你是否可以在变量模板声明中使用 auto。

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

很好,但是一旦你尝试使用它,就会发出嘀嘀咕咕的声音。

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

decltype(auto)auto 的任何组合都不起作用,即使它说auto 是一个左值。

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

我以前从未见过自动这样做。是因为模板变量的原因,还是因为 clang 对待 auto 的方式?

【问题讨论】:

  • 我认为它可能还没有完全实现。
  • "// Stacktrace" 每当你得到那个消息时,消息“clang: note: diagnostic msg: PLEASE submit a bug report to llvm.org/bugs and include crash backtrace, preprocessed source, and associated run script 。”包含在输出中。请这样做,这显然是 clang 中的一个错误,并且 clang 开发人员比 SO 上的人们更有可能给出有用的响应。

标签: c++ clang c++14 variable-templates


【解决方案1】:

这似乎在最新版本的clang 中得到解决;将其放入文件并调用

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

没有错误。

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

【讨论】:

  • 我今天也用最新的存储库遇到了这个错误:clang 版本 3.5 (202594) 目标:x86_64-pc-win32 线程模型:posix
猜你喜欢
  • 2016-10-29
  • 2013-05-04
  • 1970-01-01
  • 1970-01-01
  • 2015-11-10
  • 1970-01-01
  • 2015-09-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多