clang(trunk) gives an error for the following code:
consteval void f() {}
int main()
{
f(); // error: call to consteval function 'f' is not a constant expression
// note: subobject of type 'void' is not initialized
}
while gcc(trunk) compiles this without error.
I feel this is probably a clang bug, since both gcc and clang accept this code:
consteval int g() { return 42; }
int main()
{
g(); // ok
}
Here's the code to play with.
So is this a clang bug, or is the code ill-formed, or have ub, or something else?
Edit: I feel it might be relevant to point out that clang allows calling f
from other functions if they are also consteval. It only gives the error when f
is called from non-consteval functions:
consteval int h()
{
f(); // ok
return 42;
}
demo.