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

如何恢复clang-format 18中函数括号前空格的旧默认行为?

恢复clang-format 17单行函数括号与大括号无空格的默认行为

clang-format 18在空配置下,会给单行函数的)和{之间自动插入空格,但clang-format 17的旧默认是移除这个空格。要回到旧行为,只需在.clang-format文件中添加以下配置:

SpaceBeforeParens: ControlStatementsOnly

添加这个配置后,格式化后的代码会和clang-format 17的结果一致:

#ifndef LIBRARY_CSVLOG_HPP
#define LIBRARY_CSVLOG_HPP

class CsvLog {
  void Print(const char *value){};
};

#endif

这个配置的作用是:仅在if、for、while这类控制语句的括号前保留空格,函数定义的括号与后续大括号之间不会添加空格,完美匹配clang-format 17的默认逻辑。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 06:12:31