问题
This program:
constexpr void f() { x: ; }
is compiled by gcc, but clang says:
error: statement not allowed in constexpr function
So is this code valid?
回答1:
As pointed out in a comment, clang is correct, and the code is ill-formed. According to the current working draft (which includes C++20), dcl.constexpr#3 says:
The definition of a constexpr function shall satisfy the following requirements:
...
its function-body shall not enclose
...
an identifier label,
...
...
来源:https://stackoverflow.com/questions/64852653/can-a-constexpr-function-contain-a-label