【问题标题】:FixNamespaceComment not working as expected in .clang-formatFixNamespaceComment 在 .clang 格式中未按预期工作
【发布时间】:2018-11-14 08:58:20
【问题描述】:

我有一个类似的 cpp 代码:

#include<bits/stdc++.h>
using namespace std;

namespace a {
    const int b=1;
}

int main() {
    cout << "hello" << endl;
    return 0;
}

我尝试了以下.clang-format的配置

Language:        Cpp 
BreakBeforeBraces: Custom
BraceWrapping:
  AfterClass:      false
  AfterStruct:     true
  BeforeCatch:     false
  BeforeElse:      false

FixNamespaceComments: true # add commend at end:
NamespaceIndentation: All #intend content of namespace

预期的输出包括命名空间右括号 // namespace a 末尾的注释。 但如果命名空间中只有 int a 则不会显示。

当我尝试在命名空间中再添加一个变量时,它工作正常。

我正在使用 clang-format-6.0

【问题讨论】:

  • 这也发生在我身上。也许这是只有一条语句的命名空间的预期结果?

标签: c++ clang-format


【解决方案1】:

已以 clang 格式硬编码命名空间结束 cmets 不会添加到只有 1 行的命名空间,这似乎很随意,因为具有 1 或 2 或 3 个语句的命名空间之间没有太大区别。

违规代码:

// The maximal number of unwrapped lines that a short namespace spans.
// Short namespaces don't need an end comment.
static const int kShortNamespaceMaxLines = 1;

https://github.com/llvm-mirror/clang/blob/release_70/lib/Format/NamespaceEndCommentsFixer.cpp

【讨论】:

  • 无论如何,这些“终结者”首先是令人反感的选择:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-19
  • 2011-10-11
相关资源
最近更新 更多