首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >clang格式展开空初始化器

clang格式展开空初始化器
EN

Stack Overflow用户
提问于 2020-05-22 19:31:10
回答 1查看 212关注 0票数 0

我有一个简单的结构变量声明:struct sigaction act{};

clang-format (10.0版)将其展开如下:

代码语言:javascript
复制
struct sigaction act
    {
    };

我确实设置了AllowShortBlocksOnASingleLine: Empty,但是仍然缺少一些东西。还可以设置什么来避免这种转换?.clang-format文件如下:

代码语言:javascript
复制
---
Language:        Cpp
BasedOnStyle:  Google
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignEscapedNewlines: Left
AlignOperands:   true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Empty
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true # false
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterCaseLabel:  true
AfterClass:      true # false
AfterControlStatement: MultiLine # false
AfterEnum:       false
AfterFunction:   true # false
AfterNamespace:  true # false
AfterObjCDeclaration: true # false
AfterStruct:     true # false
AfterUnion:      true # false
AfterExternBlock: true # false
BeforeCatch:     true # false
BeforeElse:      true # false
IndentBraces:    true # false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Allman # Attach
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit:     120
CommentPragmas:  '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat:   false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth:   4  #2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd:   ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Middle # Right
ReflowComments:  true
SortIncludes:    true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: false
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles:  false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Never
...
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-08-17 20:35:24

AllowShortBlocksOnASingleLine选项不会影响struct声明,它会影响while语句(参见文档)。也许你想要的是"AllowShortStructsOnASingleLine“之类的东西,但它并不存在。

问题的根源是BreakBeforeBraces: Allman。将其改为Attach将解决您的问题。但在大多数情况下,您可能喜欢Allman。然后,您可以使用Custom,如下所示:

代码语言:javascript
复制
BraceWrapping:
  AfterClass:      true
  AfterControlStatement: true
  AfterEnum:       true
  AfterFunction:   true
  AfterNamespace:  true
  AfterObjCDeclaration: true
  AfterStruct:     false # <-- You need this
  AfterUnion:      false
  AfterExternBlock: true
  BeforeCatch:     true
  BeforeElse:      true
  IndentBraces:    false
  SplitEmptyFunction: true
  SplitEmptyRecord: false # <-- And this
  SplitEmptyNamespace: true
BreakBeforeBraces: Custom # <-- And this

其余的BraceWrapping设置可以按照BreakBeforeBreaces: Allman设置的方式保留;只有AfterStructSplitEmptyRecord会影响您的结构声明。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61962548

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档