使用 GCC v14.0(应该接近即将发布的 GCC v13.1)玩
constexpr
,我编译了以下模块:
constexpr int f (int x)
{
return x + 2;
}
constexpr const int x[] = { f(1) };
与
gcc -std=c2x -c foo.c -O2
但是 GCC 抛出:
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...]
constexpr
(pdf) 这应该是正确的语法。该 PDF 没有附带任何示例,所以我在这里缺少什么?
GCC从C++11开始就可以处理
constexpr
,所以在C前端实现它应该是众所周知的成熟技术。