在 clang 格式中,如何确保模板声明后有换行符

问题描述 投票:0回答:1

clang-format文档中所写我将

BreakTemplateDeclarations
选项设置为“是”,但是当格式化我的代码时,它仍然被放在同一行。例如

template<typename type> class Class{};

而不是

template<typename type>
class Class{};

有什么我忽略的吗?

我尝试了

BreakTemplateDeclarations
选项,我也尝试了(已弃用)
AlwaysBreakTemplateDeclarations
选项,但没有任何效果。

这是我当前的 .clang 格式文件:

---
BasedOnStyle: WebKit
AlignAfterOpenBracket: Align
AlignArrayOfStructures: Left
AlignOperands: AlignAfterOperator
AlignConsecutiveMacros: None
AlignEscapedNewlines: DontAlign
AlwaysBreakkTemplateDeclarations: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Empty
AllowShortFunctionsOnASingleLine: Empty
BinPackArguments: false
BinPackParameters: false
BreakBeforeBraces: Attach
BreakBeforeConceptDeclarations: Always
BreakTemplateDeclarations: Yes
ColumnLimit: 120
Cpp11BracedListStyle: true
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: Always
FixNamespaceComments: true
IncludeBlocks: Regroup
IndentAccessModifiers: true
IndentCaseLabels: true
IndentExternBlock: Indent
IndentWidth: 4
InsertBraces: true
IntegerLiteralSeperator:
  Binary: -1
  Decimal: 3
  DecimalMinDigits: 5
  Hex: 2
  HexMinDigits: 6
JavaScriptQuotes: Double
KeepEmptyLinesAtEOF: false
KeepEmptyLinesAtTheStartOfBlocks: false
LineEnding: LF
MaxEmptyLinesToKeep: 1
PackConstructorInitializers: NextLine
NamespaceIndentation: None
PenaltyReturnTypeOnItsOwnLine: 200
PenaltyBreakOpenParenthesis: 200
PenaltyBreakTemplateDeclaration: 0
PenaltyIndentedWhitespace: 1
PointerAlignment: Right
ReferenceAlignment: Right
RemoveParentheses: MultipleParentheses
SeperateDefinitionBlocks: Always
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: false 
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: false
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false 
SpacesInAngles: Never
SpacesInContainerLiterals: false
SpacesInLineCommentPrefix:
  Minimum: 1
  Maximum: 1
SpacesInParens: Never
SpacesInSquareBrackets: false
TabWidth: 4
UseTab: Always
...
c++ clang-format
1个回答
0
投票

问题是您为键true

指定了错误的值
AlwaysBreakkTemplateDeclarations
。从 
clang 格式文档 可能的值是:

可能的值:

  • 离开请勿更改声明前的换行符。
  • : 声明前请勿强制中断。
  • 模板声明后始终中断。
  • MultiLine仅当以下声明跨越多行时,才在模板声明后强制中断。
© www.soinside.com 2019 - 2024. All rights reserved.