【问题标题】:Clang-format 10.0 vs. 5.0 const member fuction is formated differentlyClang-format 10.0 与 5.0 const 成员函数的格式不同
【发布时间】:2020-06-24 08:05:18
【问题描述】:

我们正在将 clang 格式从 5.0 更新到 10.0(是的,我知道这是一个很大的飞跃 :-)) 文件.clang-format 保持不变。

在 5.0 版本中,我们得到了这样的格式

virtual Composite *copy_composite_tree(Composite *parent  // parent of copied tree
                                      ) const;

在 10.0 版本中,此更改为

virtual Composite *copy_composite_tree(Composite *parent  // parent of copied tree
) const;

是否有保留 5.0 格式样式的选项?

【问题讨论】:

  • 尝试转储两个版本的配置并检查属性的默认值在哪里更改。将该属性与原始值添加到您的 .clang-format 文件中。或者你可以尝试在一些在线配置器上试验属性,比如zed0.co.uk/clang-format-configurator
  • 我强烈建议您查看更改日志以更新您的 .clang 格式文件。我确信一些选项已被弃用,并添加了许多新选项。这是在之前的建议之上的。

标签: c++ constants member-functions clang-format


【解决方案1】:

我认为这是一个 bug,它是在 clang-format 9.0.1 中引入的,因为所有的内置样式,例如 LLVM、Google,... 都表现出完全相同的行为。

我将此错误报告给 llvm 项目。

https://bugs.llvm.org/show_bug.cgi?id=46509

【讨论】:

    【解决方案2】:

    我假设这只是由括号对齐控制,就像其他一切一样,引用 clang 文档:

    AlignAfterOpenBracket (BracketAlignmentStyle) 如果true,则在左括号后水平对齐参数。 这适用于圆括号(圆括号)、尖括号和方括号。

    可能的值:

    BAS_Align (in configuration: Align) 对齐左括号上的参数,例如:

    someLongFunction(argument1,
                     argument2);
    

    BAS_DontAlign (in configuration: DontAlign) 不对齐,而是使用 ContinuationIndentWidth,例如:

    someLongFunction(argument1,
        argument2);
    

    BAS_AlwaysBreak(在配置中:AlwaysBreak)如果参数不适合单行,则始终在左括号后中断,例如:

    someLongFunction(
        argument1, argument2);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-12
      • 1970-01-01
      • 1970-01-01
      • 2015-06-07
      • 2011-06-04
      • 2022-12-23
      • 2017-10-30
      • 2019-06-18
      相关资源
      最近更新 更多