班级名称注入和构造函数
Class Name Injection and Constructors
最近,将库更新为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提交错误报告?
clang-5非常正确。在[class.qual]/2:
在查找中,函数名称不忽略,并且 Nested-name-specifier 提名类C :
- 如果在嵌套名称指示符之后指定的名称,在C中抬头时,是C
的注入式名称。- ...
该名称被视为命名C 的构造函数。
至于问题的另一部分。是的,提交错误报告绝对值得。要鼓励IMO标准合规性(或至少对其进行更多诊断)。
相关文章:
- "error: no matching function for call to"构造函数错误
- C++17复制构造函数,在std::unordereded_map上进行深度复制
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 为什么在没有显式默认构造函数的情况下,将另一个结构封装在联合中作为成员的结构不能编译
- 为什么在C++中使用私有复制构造函数与删除复制构造函数
- 选择要调用的构造函数
- 如何委托派生类使用其父构造函数?
- 构造函数正在调用一个使用当前类类型的函数
- 没有用于初始化C++中的变量模板的匹配构造函数
- 初始化具有非默认构造函数的std::数组项的更好方法
- 班级名称注入和构造函数
- C 对象组成,注入和复制构造函数
- 依赖注入/继承设计模式的构造函数参数太多
- C++中构造函数注入的高级配置
- 正在注入模板构造函数
- C++通过构造函数注入"策略"
- 构造函数依赖注入:unique_ptr + move vs shared_ptr
- c++ 11在构造函数中的依赖注入
- 构造函数中的循环指针注入
- 通过构造函数进行依赖注入的最佳实践