首页 > 解决方案 > 'if'、'while'、'catch' 等后的空格,使用 clang 格式

问题描述

无法弄清楚该选项会在if, while,catch等之后添加空格...

目前我的 .clang-format 文件产生这个:

        while(true)
        {
            if(flushedCount == count)
            {
                break;
            }
        }

标签: c++cclang-format

解决方案


The clang-format configuration option controlling space after if, while, catch and other control statements is called SpaceBeforeParens.

SpaceBeforeParens: ControlStatements

From clang-format 8 documentation:

SpaceBeforeParens (SpaceBeforeParensOptions)

Defines in which cases to put a space before opening parentheses.

Possible values:

  • [...]
  • SBPO_ControlStatements (in configuration: ControlStatements) Put a space before opening parentheses only after control statement keywords (for/if/while...).
  • [...]

推荐阅读