You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

[temp.dep.type]/p7 是否被 [temp.res]/p8 涵盖?

Is [temp.dep.type]/p7 covered by [temp.res]/p8?

Short answer: No—these two standard clauses govern distinct, non-overlapping scenarios for template validity, so neither covers the other.

Let’s Break Down Each Clause

[temp.dep.type]/p7

First, here’s the clause as you provided it:

若嵌套名称指定符指代当前实例化的限定id并非当前实例化的成员或未知特化的成员,即使包含该限定id的模板未被实例化,程序亦为病态;无需诊断。类似地,若对象表达式类型为当前实例化的类成员访问表达式中的id表达式未指代当前实例化的成员或未知特化的成员,即使包含该id表达式的模板未被实例化,程序亦为病态;无需诊断。

In simpler terms: This rule kicks in when you use a nested name specifier (like MyTemplate::) that refers to the current instantiation (the template class/struct you’re writing), but the name you’re trying to access isn’t actually a member of that template or an unknown specialization. The critical point here is that this makes the program ill-formed even if the template is never instantiated—it’s a "no diagnostic required" (NDR) rule that applies at template definition time.

For example:

template<typename T>
struct MyTemplate {
    void foo() {
        MyTemplate::does_not_exist; // Violates [temp.dep.type]/p7
    }
};

Even if MyTemplate is never used anywhere in your code, this program is technically ill-formed, though compilers might not flag it (due to NDR).

[temp.res]/p8

[temp.res]/p8 focuses on dependent names that can’t be resolved during template instantiation. To paraphrase the standard:

If a dependent name used in a template isn’t found by unqualified lookup at definition time, and also can’t be found by qualified lookup when the template is instantiated, the program is ill-formed.

The key difference here is that this rule only applies when the template is actually instantiated. If the template is never used, there’s no ill-formedness under this clause.

For example:

template<typename T>
void bar() {
    some_dependent_function(); // Dependent name (assume T affects lookup)
}

If some_dependent_function isn’t declared anywhere when bar<T> is instantiated, this violates [temp.res]/p8—but if bar is never called, there’s no issue.

Core Differences Between the Two Clauses

  • When they apply: [temp.dep.type]/p7 applies to template definitions, regardless of instantiation. [temp.res]/p8 only applies when the template is instantiated.
  • What they target: [temp.dep.type]/p7 is specific to invalid member references on the current instantiation. [temp.res]/p8 is a broader rule about missing dependent names during instantiation.
  • Root cause: The former is about referencing a non-member as if it’s part of the current template; the latter is about a dependent name that can’t be found at all when needed.

Since these rules address separate issues with distinct triggers, [temp.dep.type]/p7 is not covered by [temp.res]/p8.

内容的提问来源于stack exchange,提问作者xskxzr

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:12:12