概念评估能否取决于评估地点?

Can a concept evaluation depend on where it is evaluated?

[temp.concept]/5 说:

A concept is not instantiated ([temp.spec]). [ Note: An id-expression that denotes a concept specialization is evaluated as an expression ([expr.prim.id]). [...]]

这是否意味着以下规则 ([temp.point]/8) 不适用?

If two different points of instantiation give a template specialization different meanings according to the one-definition rule, the program is ill-formed, no diagnostic required.


例如,如果此规则不适用,则以下代码格式正确:

template<class T>
concept Complete = sizeof(T)==sizeof(T);

struct A;

constexpr inline bool b1 = Complete<A>; //Complete<A>==false;

struct A{};

constexpr inline bool b2 = Complete<A>; //Complete<A>==true;

这个问题后面跟这个one

Can a concept evaluation depend on where it is evaluated?

没有。

过去确实如此(正如我在本次编辑之前的回答所述),但事实证明这会严重抑制编译器吞吐量(因为您无法缓存概念检查的结果)和动机因为一开始就很弱。这是一个非常晚的更改,在 2020 年布拉格会议中作为 P2104 的一部分通过,在 [temp.constr.atomic] 中添加了以下句子:

If, at different points in the program, the satisfaction result is different for identical atomic constraints and template arguments, the program is ill-formed, no diagnostic required.

因此,这:

template<class T>
concept Complete = sizeof(T) == sizeof(T);

struct A;
static_assert(!Complete<A>);
struct A {};
static_assert(Complete<A>);   

是ill-formed,NDR(实际上Complete<A>A完成后还是false)。换句话说,我们 "memoize" 的概念与我们 "memoize" 模板实例化的方式相同。