You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在requires子句中使用`enum : bool`是否合规?GCC与Clang编译差异的技术问询

在requires子句中使用enum : bool是否合规?GCC与Clang编译差异的技术问询

最近碰到一个C++模板编译的小坑,先看这段测试代码:

template <typename T> struct S {
    enum : bool { b = sizeof(S) > 32 };
    void f() requires(b) { }
};

这段代码用Clang编译完全没问题,但GCC直接报错了,错误信息是:

error: constraint expression does not have type 'bool' [-Wtemplate-body]
    4 |     void f() requires(b) { }
      |                      ~^~

我现在有点懵,想问问大家:C++标准里有没有明确规定这种在requires子句里使用enum : bool类型的枚举值是非法的?还是说这其实是GCC的一个bug?

备注:内容来源于stack exchange,提问作者Vittorio Romeo

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.13 17:18:23