Can a constexpr function contain a label?

Viewed 123

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 Answers

As pointed out in a comment by Nathan Pierson, 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,

...

...

Related