我正在尝试创建一个构造函数初始化程序格式,如:
Constructor()
: initializer1(),
initializer2()
根据the documentation,我尝试将BreakConstructorInitializers
设置为BeforeColon
(描述说明:“在冒号之前和逗号之后打破构造函数初始化程序。”,这正是我的意思想要),但它是在逗号之前放置,这不是我想要的。我做错了什么,或者这是clang格式的错误?我尝试了clang-format-5.0和clang-format-6.0,它们的行为方式相同。
这是我完整的.clang格式文件:
---
Language: Cpp
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: All
AlwaysBreakAfterReturnType: TopLevel
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
BeforeCatch: true
BeforeElse: true
IndentBraces: true
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: GNU
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: true
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 140
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: false
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Right
ReflowComments: true
SortIncludes: false
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: true
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
...
我尝试了BreakConstructorInitializersBeforeComma
和BreakConstructorInitializers
键的所有可能组合;他们似乎都不是我想要的。
结果如下:
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
Constructor() : a(1), b(1)
{
}
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeComma
Constructor()
: a(1)
, b(1)
{
}
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: AfterColon
Constructor() : a(1), b(1)
{
}
BreakConstructorInitializersBeforeComma: true
BreakConstructorInitializers: BeforeColon
Constructor()
: a(1)
, b(1)
{
}
BreakConstructorInitializersBeforeComma: true
BreakConstructorInitializers: BeforeComma
Constructor()
: a(1)
, b(1)
{
}
BreakConstructorInitializersBeforeComma: true
BreakConstructorInitializers: AfterColon
Constructor() : a(1), b(1)
{
}
答案 0 :(得分:4)
我和你有同样的问题并进行了一些调查。
首先,BreakConstructorInitializers
被更改为枚举,并且不推荐使用BreakConstructorInitializersBeforeComma。 (https://reviews.llvm.org/D32479)
当我看到你真正希望实现的目标时,你想要BreakConstructorInitializersAFTERComma
,这不是一件事。您只能通过ColumnLimit
实现所需目的。不幸的是
答案 1 :(得分:0)
这些可行。
BreakConstructorInitializers: AfterColon
ConstructorInitializerAllOnOneLineOrOnePerLine: true