【问题标题】:Is [temp.dep.type]/p7 covered by [temp.res]/p8?[temp.dep.type]/p7 是否被 [temp.res]/p8 覆盖?
【发布时间】:2018-08-04 23:31:39
【问题描述】:

[temp.dep.type]/p7:

如果 qualified-id 其中 nested-name-specifier 指的是 当前实例化不是当前实例化的成员或 一个未知专业的成员,该程序甚至是错误的 如果包含 qualified-id 的模板没有被实例化;不 需要诊断。同样,如果类中的 id-expression 对象表达式的类型的成员访问表达式 是当前实例化不引用当前的成员 实例化或未知专业化的成员,程序是 即使包含成员访问的模板也是格式错误的 表达式未实例化;无需诊断。 [ 示例

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
  }
};

— 结束示例 ]

[temp.res]/p8(无关部分省略):

知道哪些名称是类型名称允许每个模板的语法 被检查。该程序格式错误,不需要诊断,如果:

  • 无法为模板或模板中的 constexpr if 语句的子语句生成有效的特化,并且 模板未实例化,或

...

[ 示例

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
  }
};

...

— 结束示例 ]


在我看来,如果满足[temp.dep.type]/p7中的条件,那么就无法为这个模板生成有效的特化(例如,在[temp.dep.type]的example中.dep.type]/p7,不能为声明 typename A&lt;T&gt;::other j;) 生成有效的特化,因此程序格式错误;根据 [temp.res]/p8 无需诊断。

那么 [temp.dep.type]/p7 是否被 [temp.res]/p8 覆盖?如果没有,您能否举一个 [temp.dep.type]/p7 涵盖但 [temp.res]/p8 不涵盖的示例?

【问题讨论】:

  • 我怀疑你是对的:既不是当前专业化的成员也不是未知专业化的成员只是意味着“没有找到并且没有依赖的基础可以稍后搜索”,而且不能成为一件好事。更糟糕的是,该示例并非严格相关:typename A&lt;T&gt;::other 中没有 qualified-id

标签: c++ templates language-lawyer


【解决方案1】:

是的,[temp.dep.type]/p7 确实被 [temp.res]/p8 覆盖了。

现在 [temp.dep.type]/p7 已通过P1787 完全删除,部分示例添加到 [temp.res]/8 中。

【讨论】:

    猜你喜欢
    • 2022-12-18
    • 1970-01-01
    • 2015-05-08
    • 1970-01-01
    • 1970-01-01
    • 2012-09-18
    • 2017-02-02
    • 2011-05-29
    • 1970-01-01
    相关资源
    最近更新 更多