Playing around with constexpr
with GCC v14.0 (which should be close to the soon to be released GCC v13.1), I compiled the following module:
constexpr int f (int x)
{
return x + 2;
}
constexpr const int x[] = { f(1) };
with gcc -std=c2x -c foo.c -O2
but GCC throws:
foo.c:1:1: error: 'constexpr' requires an initialized data declaration
1 | constexpr int f (int x)
| ^~~~~~~~~
[...f'up errors due to the one above...]
According to constexpr
in C23 proposal (pdf) this should be correct syntax. That PDF doesn't come with any examples though, so what I am missing here?
GCC can deal with constexpr
since C++11, so implementing it in the C frontend should be known and mature technology.