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

如何配置clang-format避免enum枚举类型的左大括号单独换行

解决方案

你当前配置不生效的核心原因是:BreakBeforeBraces 设置为 Attach 这类预设值时,会覆盖 BraceWrapping 下的自定义规则,要让枚举大括号不换行的配置生效,需要先将 BreakBeforeBraces 调整为 Custom 启用自定义大括号规则。

调整后的完整相关配置如下:

BreakBeforeBraces: Custom
AllowShortEnumsOnASingleLine: false
BraceWrapping:
  AfterEnum: false
  # 其余原有BraceWrapping规则可按需保留,若你其他代码的大括号也保持Attach风格,对应项统一设为false即可,示例:
  AfterClass: false
  AfterFunction: false
  AfterStruct: false
  AfterNamespace: false
  BeforeCatch: false
  BeforeElse: false

应用上述配置后,格式化后的枚举格式就能符合预期:

enum class Fruit {
  Apple = 0,
  Banana = 1
};

内容的提问来源于stack exchange,提问作者jasonxia

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.02 18:39:01