我在C++中使用来自LLVM 7.0.0和Windows 10的clang格式。
我有下一节课
class FooooooooooooooooooC
{
public:
FooooooooooooooooooC() = default;
const FooooooooooooooooooC& operator=( const FooooooooooooooooooC& ) = delete;
};运行clang格式之后,它应该如下所示
class FooooooooooooooooooC
{
public:
FooooooooooooooooooC() = default;
const FooooooooooooooooooC& operator=(
const FooooooooooooooooooC& ) = delete;
};但是实际上在运行clang格式之后,它看起来是这样的。
class FooooooooooooooooooC
{
public:
FooooooooooooooooooC() = default;
const FooooooooooooooooooC&
operator=( const FooooooooooooooooooC& ) = delete;
};我在.clang格式中的clang-fromat设置如下
---
AccessModifierOffset: -3
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: true
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakAfterJavaFieldAnnotations: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeComma
BreakInheritanceList: BeforeComma
BreakStringLiterals: true
CommentPragmas: '^ IWYU pragma:'
ColumnLimit: 80
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 0
ContinuationIndentWidth: 3
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
- Regex: '.*'
Priority: 1
IncludeIsMainRegex: '(Test)?$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 3
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
Language: Cpp
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 1000000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: true
SpacesInParentheses: true
SpacesInSquareBrackets: true
Standard: Cpp11
TabWidth: 3
UseTab: Never
...是否有人知道如何配置clang,以便在之后创建一个中断?
operator=(
谢谢!
发布于 2020-08-06 22:22:40
总之,你不能做你想做的事。
下面是如何配置clang-格式,使其在const FooooooooooooooooooC&之后不出现中断。
在决定如何拆分行时,clang使用了几个加权因素,其名称都以Penalty开头。在本例中,您希望返回类型与函数名保持在同一行上,因此需要调整PenaltyReturnTypeOnItsOwnLine。您的..clang格式中的值是60。相反,请使用:
PenaltyReturnTypeOnItsOwnLine: 200使其值110或更大,以防止行在const FooooooooooooooooooC&返回类型后中断。我建议200与铬、谷歌和Mozilla预定义的clang格式风格相匹配。(而且,我也不知道为什么110是阈值;惩罚值相当不透明,我只是通过实验才找到这个值的。)
然而,您最终得到的结果是:
const FooooooooooooooooooC& operator=( const FooooooooooooooooooC& ) =
delete;我不相信在operator=(之后有什么办法来强迫休息。如果您的类名比您的类名长4个字符,那么您将得到所要求的内容,因为在delete之前,上面的分隔将超过80个字符。
ColumnLimit。即使允许增加列限制,它也只允许将operator=声明保持在一行上。它不允许您强迫它在operator=(之后拆分行。AllowAllParametersOfDeclarationOnNextLine: false。正如你所发现的,这并不能解决问题。当有多个参数时,这将影响是否将所有参数放在单独的行上的决定。但你只有一个参数。(参见文档。)最后,请注意,我使用的是clang-格式6.0.0,与您的7.0.0相比。但是,在clang-格式上似乎没有任何不同,在这里会有任何不同:
https://stackoverflow.com/questions/53835831
复制相似问题