c++ - FixNamespaceComment 在 .clang 格式中未按预期工作
问题描述
我有一个 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
解决方案
它以 clang 格式硬编码,命名空间结束注释不会添加到只有 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
推荐阅读
- c++ - 如何将大型元数据文件读入 C++ 中的数组
- soap - Sabre 用于多城市搜索的 SOAP 方法
- excel - VBA - 计算 Range 对象中的列数
- javascript - React 和 Express 阻止了跨域请求
- javascript - 将 vuex 的状态传递给图表 - vue
- ios - UIButton press 不适用于 IF 语句
- python - 单击后如何删除内联键盘?(Python)
- c# - 更改实时图表圆圈大小
- node.js - Hyperledger - 作曲家 REST API 或提交交易以添加/修改资产?
- logstash - 确定 logstash 管道是否完整