【发布时间】:2018-03-06 20:50:53
【问题描述】:
最近,在将库更新到 Clang 5.x 时,我注意到我之前在 Clang 4.x、GCC 5.x-6.x 以及 MSVC 2015 和 2017 上编译的代码中有一个错误。
#include <iostream>
#include <typeinfo>
#include <vector>
int main()
{
using a = typename std::vector<int>::vector;
std::cout << typeid(a).name() << std::endl;
return 0;
}
Clang-5.x 会产生以下警告消息,而所有其他编译器都会静默编译上述代码:
a.cpp:7:42: warning: ISO C++ specifies that qualified reference to 'vector' is a
constructor name rather than a type in this context, despite preceding
'typename' keyword [-Winjected-class-name]
using a = typename std::vector<int>::vector;
哪个编译器有问题?我是否正确假设 Clang5.x 在这里具有正确的行为,并且所有其他编译器(和版本)都不正确。如果是这样,是否值得向 MSVC 和 GCC 提交错误报告?
【问题讨论】:
-
另一方面,
using a = class std::vector<int>::vector;是合法的。如果你喜欢这样奇怪的东西。
标签: c++ clang language-lawyer