关于[[constexpr函数的标准指出了[decl.constexpr]的第5点:
接着给出以下示例:对于非模板,非默认constexpr函数或非模板,非默认,非继承constexpr构造函数,如果不存在任何参数值,则对该函数或构造函数的调用可以是评估的子表达式核心常数表达式(5.19)的程序格式错误;不需要诊断。
constexpr int f(bool b){ return b ? throw 0 : 0; } // OK
constexpr int f() { return f(true); } // ill-formed, no diagnostic required
我从中得出的结论是,带有空参数列表的函数是无法诊断的格式错误。这让我大跌眼镜,[
constexpr int g() { return 0; } // ill-formed?
如果是这样,其背后的原理是什么,如果不是,那么该限定条件意味着什么?何时constexpr函数的格式不正确?大概以下可以吗?
constexpr int h(int x) { return x; } // presumably fine? constexpr int l = h(42); // also fine
关于constexpr函数的标准在[decl.constexpr]的第5点下指出:对于非模板,非默认constexpr函数或非模板,非默认,非继承constexpr ...