我正在寻找一种方法来使用 clang-format(版本 9.0.0)格式化下面的 C++ 代码,以便在参数声明后破坏超过 80 列限制的函数定义,而不是像 noexcept
这样的 C++ 函数限定符| :
void scheduler::stop_mark(service ¤t, service const &stopped) const
noexcept {
// ...
}
上面的代码片段显示了我用
LLVM
格式化的代码默认样式和下面的代码是正确格式化后我想要的样式:void scheduler::stop_mark(service& current,
service const& stopped) const noexcept {
// ...
}
两个片段之间的区别在于
service& current,
之后的行被断开而不是 noexcept
.使用
LLVM
时,此行为可重现默认样式,但我使用以下选项作为引用:---
BasedOnStyle: LLVM
AlignAfterOpenBracket: Align
AllowAllArgumentsOnNextLine: 'true'
AllowAllConstructorInitializersOnNextLine: 'true'
AllowAllParametersOfDeclarationOnNextLine: 'true'
AllowShortCaseLabelsOnASingleLine: 'false'
AllowShortFunctionsOnASingleLine: Empty
AllowShortLambdasOnASingleLine: Empty
AlwaysBreakTemplateDeclarations: 'Yes'
BinPackArguments: 'true'
BinPackParameters: 'true'
BreakConstructorInitializers: BeforeComma
BreakConstructorInitializersBeforeComma: 'true'
ConstructorInitializerIndentWidth: 2
FixNamespaceComments: 'true'
IndentCaseLabels: 'true'
IndentPPDirectives: AfterHash
PenaltyBreakAssignment: 1000
PenaltyBreakBeforeFirstCallParameter: 50
PointerAlignment: Left
...
是否有可能通过 clang-format 获得这样的格式?
我在 https://zed0.co.uk/clang-format-configurator/ 上检查了所有可能的选项已经并且找不到匹配的 clang-format 选项。
最佳答案
我同意任何规则的组合都不会获得所需的输出,但是当你发现这样的东西时,有一种方法可以强制它。
在第一个参数后添加一行注释(可以为空)。然后 clang-format 将为您对齐您的参数。
void scheduler::stop_mark(service& current, //
service const& stopped) const noexcept {
// ...
}
关于c++ - clang-format:中断函数参数而不是函数限定符(noexcept),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60679472/