是否应该延迟类模板定义中由 this-> 限定的类/命名空间名称的名称查找?
Should name lookup be deferred for a class/namespace-name qualified by this-> in a class template definition?
clang 3.0和g++4.8.1都拒绝了以下代码,并在注释中显示错误:
template<typename T>
struct S
{
void f()
{
this->dependent(); // no error: type of 'this' is dependent?
this->Dependent::dependent(); // error: 'Dependent' has not been declared
}
};
根据【basic.lookup.classref】
后面的类名或命名空间名称。or->运算符在整个后缀表达式的上下文和对象表达式的类的范围中都会查找。
和〔temp.dep.expr〕
如果封闭成员函数的类类型是依赖的,则
this
是依赖于类型的。
如果类或命名空间名称Dependent
是在对象表达式*this
的类的作用域中查找的,并且对象表达式的类是依赖的,那么是否应该将此查找推迟到模板实例化之后?标准是否规定了正确的行为?
编辑:clang 3.0接受以下代码,但g++4.8给出了与上述相同的错误
template<typename T>
struct S
{
T m;
void f()
{
m.dependent();
m.Dependent::dependent();
}
};
在您的第一个代码中,两行都是"illformed,no diagnostic required",因为"this"指的是当前实例化,但没有找到成员,类模板也没有依赖基类。
它既不是当前实例化的成员,也不是未知专业化的成员。参见14.6.2.1p6
相关文章:
- 命名空间中具有.h和.cpp文件的类
- 从父命名空间重载类型
- 在命名空间中定义函数还是限定函数
- C++:对不存在的命名空间使用命名空间指令
- 通过继承类使用来自不同命名空间的运算符
- 使用命名空间时出现多个定义错误
- CUDA内核和数学函数的显式命名空间
- 嵌套的匿名命名空间
- CMakeLists.txt中的命名空间表示法
- 类是C++中的命名空间吗
- 在命名空间中使用全局命名空间中的函数
- 如何使 std::sort 在 std::swap 和我的命名空间的模板化交换之间没有名称冲突?
- '使用命名空间{嵌套在另一个命名空间中的某个命名空间}"
- 是否可以将函数导入命名空间,但不能导出它?
- C++ C++类中的命名空间降级
- 如何使用 soong 命名空间来有条件地编译模块
- 使用 Clang++ 有没有办法将文件作为命名空间等包含?
- 使用 make 编译 MPI,几个命名空间错误,例如"错误:未知类型名称'使用'?
- 如何通过命名空间调用非静态方法
- 在命名空间名称之前加上 :: 是什么意思?