【问题标题】:How to force brackets on the same line even with comments即使有注释,如何在同一行强制使用括号
【发布时间】:2020-10-23 16:13:57
【问题描述】:

如果我在以下代码中仅使用 BasedOnStyle: Google 运行 clang-format

int main() {
  if (1 < 2)  // This is a comment
              // I am a comment
  {
    return 1;
  }
  return 0
}

我得到相同的代码。是否可以强制左括号位于同一行?

int main() {
  if (1 < 2) {  // This is a comment
                // I am a comment
    return 1;
  }
  return 0
}

【问题讨论】:

    标签: clang-format


    【解决方案1】:

    不,clang-format 不会这样做。除了少数例外,clang-format 仅更改空格(例外包括 FixNamespaceCommmentsReflowCommentsSortIncludesSortUsingDeclarations)。您的更改需要将左括号从 cmets 之前移动到 cmets 之后,因此 clang-format 不会这样做。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-20
      • 2021-08-02
      • 2011-07-16
      • 1970-01-01
      相关资源
      最近更新 更多