C++ [temp.dep.type]/p7是否由[temp.res]/p8转换?
: 如果嵌套名称说明符引用当前实例化的限定id不是当前实例化的成员或未知专门化的成员,则即使未实例化包含限定id的模板,程序也是格式错误的;无需诊断。类似地,如果对象表达式的类型为当前实例化的类成员访问表达式中的id表达式未引用当前实例化的成员或未知专门化的成员,则即使未实例化包含成员访问表达式的模板,程序也是病态的;无需诊断。[ 例如:C++ [temp.dep.type]/p7是否由[temp.res]/p8转换?,c++,templates,language-lawyer,C++,Templates,Language Lawyer,: 如果嵌套名称说明符引用当前实例化的限定id不是当前实例化的成员或未知专门化的成员,则即使未实例化包含限定id的模板,程序也是格式错误的;无需诊断。类似地,如果对象表达式的类型为当前实例化的类成员访问表达式中的id表达式未引用当前实例化的成员或未知专门化的成员,则即使未实例化包含成员访问表达式的模板,程序也是病态的;无需诊断。[ 例如: 模板类别A{ typedef int类型; void f(){ A::type i;//确定:指当前实例化的成员 typename A::other j;//
模板类别A{
typedef int类型;
void f(){
A::type i;//确定:指当前实例化的成员
typename A::other j;//错误:既不是当前实例化的成员,也不是
//未知专业的成员
}
};
- 结束示例 ]
(不相关部分省略):
知道哪些名称是类型名称可以检查每个模板的语法。如果出现以下情况,则程序格式错误,无需诊断:
- 如果模板中的语句未实例化,则无法为模板或constexpr的子语句生成有效的专门化,或者
intj;
模板类X{
空f(T T,int i,char*p){
t=i;//如果X::f被实例化,对t的赋值是一个错误
p=i;//即使X::f没有实例化
p=j;//即使X::f没有实例化
}
空隙g(T){
+;//即使X::g没有实例化
}
};
- 结束示例 ]
我认为,如果满足[temp.dep.type]/p7中的条件,则无法为该模板生成有效的专门化(例如,在[temp.dep.type]/p7的示例中,无法为声明
typename A::other j;
)生成有效的专门化,因此程序格式错误;根据[温度恢复]/第8页
那么[temp.dep.type]/p7是否由[temp.res]/p8转换而来?如果不是,请举例说明[temp.dep.type]/p7涵盖但[temp.res]/p8不涵盖?我怀疑你是对的:既不是当前专业化的成员,也不是未知专业化的成员,只意味着“找不到,也没有可供以后搜索的依赖基”,这不是一件好事。更糟糕的是,这个例子并不严格相关:在
typename a::other
中没有限定的id。
template<class T> class A {
typedef int type;
void f() {
A<T>::type i; // OK: refers to a member of the current instantiation
typename A<T>::other j; // error: neither a member of the current instantiation nor
// a member of an unknown specialization
}
};
int j;
template<class T> class X {
void f(T t, int i, char* p) {
t = i; // diagnosed if X::f is instantiated, and the assignment to t is an error
p = i; // may be diagnosed even if X::f is not instantiated
p = j; // may be diagnosed even if X::f is not instantiated
}
void g(T t) {
+; // may be diagnosed even if X::g is not instantiated
}
};