为什么使用一个无效的概念被认为是错误的
Why the using of a noneffective concept regarded as ill-formed
新发布的草稿在[expr.prim.req]/6中提到:
If the substitution of template arguments into a requirement would
always result in a substitution failure, the program is ill-formed; no
diagnostic required. [ Example:
template<typename T> concept C =
requires {
new int[-(int)sizeof(T)]; // ill-formed, no diagnostic required
};
— end example ]
但为什么我们不能保证诊断总是失败,而不是跳过诊断?
需求表达式几乎可以做任何事情。它们可以引发进一步的模板替换,通过任意数量的代码向外级联。回想一下,模板替换构成了 Turning complete language.
所以你要求编译器,给定一个图灵完备的程序,证明是否有一些输入导致该程序格式正确。这只是暂停问题的重述。就像停机问题一样,在一些简单的情况下,程序显然 halts/doesn 不会停机。但是当你处理图灵完备的语言时,它可能会变得任意复杂。
该标准不会强制编译器解决停机问题。
新发布的草稿在[expr.prim.req]/6中提到:
If the substitution of template arguments into a requirement would always result in a substitution failure, the program is ill-formed; no diagnostic required. [ Example:
template<typename T> concept C = requires { new int[-(int)sizeof(T)]; // ill-formed, no diagnostic required };
— end example ]
但为什么我们不能保证诊断总是失败,而不是跳过诊断?
需求表达式几乎可以做任何事情。它们可以引发进一步的模板替换,通过任意数量的代码向外级联。回想一下,模板替换构成了 Turning complete language.
所以你要求编译器,给定一个图灵完备的程序,证明是否有一些输入导致该程序格式正确。这只是暂停问题的重述。就像停机问题一样,在一些简单的情况下,程序显然 halts/doesn 不会停机。但是当你处理图灵完备的语言时,它可能会变得任意复杂。
该标准不会强制编译器解决停机问题。