为什么默认情况下立即函数不是noexcept,为什么它们被允许为noexcept(false)?

As of c++20 we can define immediate functions by using the consteval specifier. When a function is declared consteval every call to that function must produce a compile-time constant otherwise the program is ill-formed. Also, since c++20 try-catch blocks are allowed in constant evaluated contexts but throwing exceptions is still disallowed. Because of this I initially thought that as consteval implies inline it also implies noexcept since throwing any exception is forbidden. As you can imagine at this point, this is not true: unless you specify noexcept, an immediate function is a potentially throwing function with all the negative sides that derive from that. Is there a reason for this I'm not aware of?

评论