Den*_*ank 6 c++ llvm clang-format
我正在寻找一种使用 clang-format(版本 9.0.0)格式化下面的 C++ 代码的方法,这样超过 80 列限制的函数定义在参数声明而不是 C++ 函数限定符之后被破坏,例如noexcept:
void scheduler::stop_mark(service ¤t, service const &stopped) const
noexcept {
// ...
}
Run Code Online (Sandbox Code Playgroud)
上面的代码片段显示了我使用LLVM默认样式格式化的代码,下面的代码是我在正确格式化后想要的代码:
void scheduler::stop_mark(service& current,
service const& stopped) const noexcept {
// ...
}
Run Code Online (Sandbox Code Playgroud)
两个片段之间的区别在于,该行在 之后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
...
Run Code Online (Sandbox Code Playgroud)
是否有可能通过 clang-format 获得这样的格式?
我已经在https://zed0.co.uk/clang-format-configurator/上检查了所有可能的选项,但找不到匹配的 clang-format 选项。
就其价值而言, clang-format 10.0.1 似乎可以满足您的要求:
$> clang-format --version
clang-format version 10.0.1 (Fedora 10.0.1-3.fc32)
$> echo " void scheduler::stop_mark(service ¤t, service const &stopped) const noexcept { /* ... */ }" | clang-format --style=LLVM
void scheduler::stop_mark(service ¤t,
service const &stopped) const noexcept { /* ... */
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
464 次 |
| 最近记录: |