As written in the clang-format documentation I set the BreakTemplateDeclarations
Option to "Yes", but when format my Code it still gets put on the same line. e.g.
template<typename type> class Class{};
instead of
template<typename type>
class Class{};
Is there anything I´m overlooking?
I tried the BreakTemplateDeclarations
Option and I also tried the (deprecated) AlwaysBreakTemplateDeclarations
Option but none made a difference.
This is my current .clang-format File:
---
BasedOnStyle: WebKit
AlignAfterOpenBracket: Align
AlignArrayOfStructures: Left
AlignOperands: AlignAfterOperator
AlignConsecutiveMacros: None
AlignEscapedNewlines: DontAlign
AlwaysBreakTemplateDeclarations: 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
...
The problem is that you've specified a wrong value true
for the key AlwaysBreakTemplateDeclarations
(renamed to BreakTemplateDeclarations
since clang-format 19). From clang format documentation the possible values are:
Possible values:
- Leave : Do not change the line breaking before the declaration.
- No : Do not force break before declaration.
- MultiLine : Force break after template declaration only when the following declaration spans multiple lines.
- Yes : Always break after template declaration.
So to solve this, change true
to Yes
.