Open JohelEGP opened 2 years ago
@llvm/issue-subscribers-clang-format
So, looks like this is being interpreted as some Objective-C thing, all the way back in UnwrappedLineParser:
https://github.com/llvm/llvm-project/blob/1809414fe19a80afb1fb929e2e6a0c80b0f854f1/clang/lib/Format/UnwrappedLineParser.cpp#L1891-L1901
(parseChildBlock()
sets the block kind to BK_Block
, which does weird stuff in TokenAnnotator::spaceRequiredBetween
)
Introduced in these commits: https://github.com/llvm/llvm-project/commit/516e054c05fcf92b89fbac3e22048f2c00cf218f, https://github.com/llvm/llvm-project/commit/395193c7a0cd1366e33c1bd23590eb6ea06f5251
Since my only exposure to Objective-C is though clang-format tests, I can't say if this case is actually ambiguous, or if the heuristic could be improved.
https://github.com/llvm/llvm-project/blob/1809414fe19a80afb1fb929e2e6a0c80b0f854f1/clang/unittests/Format/FormatTest.cpp#L22574-L22575
this definitely looks ambigious from a purely UnwrappedLineParser perspective, perhaps a fixup could be performed in spaceRequiredBetween
or something, if the caret is a BinaryOperator
This is my actual .clang-format
, which includes Language: Cpp
, which should hopefully avoid Objective-C interpretations.
AccessModifierOffset: -2
AlignAfterOpenBracket: AlwaysBreak
AlignArrayOfStructures: None
AlignConsecutiveAssignments: Consecutive
AlignConsecutiveBitFields: Consecutive
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: None
AlignEscapedNewlines: Right
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: No
BinPackArguments: true
BinPackParameters: true
BitFieldColonSpacing: Both
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeConceptDeclarations: Allowed
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
BreakStringLiterals: true
ColumnLimit: 120
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
DeriveLineEnding: false
DerivePointerAlignment: false
DisableFormat: false
EmptyLineAfterAccessModifier: Never
EmptyLineBeforeAccessModifier: Always
FixNamespaceComments: true
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '<(experimental/)?[a-z_]+>' # C++ standard library
Priority: 1
IndentAccessModifiers: false
IndentCaseBlocks: false
IndentCaseLabels: false
IndentPPDirectives: AfterHash
IndentRequiresClause: true
IndentWidth: 2
IndentWrappedFunctionNames: false
InsertBraces: false
KeepEmptyLinesAtTheStartOfBlocks: false
LambdaBodyIndentation: Signature
Language: Cpp
MaxEmptyLinesToKeep: 1
NamespaceIndentation: Inner
PackConstructorInitializers: NextLine
PointerAlignment: Left
PPIndentWidth: -1
QualifierAlignment: Custom
QualifierOrder: ["static", "inline", "constexpr", "const", "volatile", "type"]
ReferenceAlignment: Pointer
ReflowComments: true
RequiresClausePosition: SingleLine
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 0
SortIncludes: CaseInsensitive
SortUsingDeclarations: true
SpaceAfterLogicalNot: true
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: Never
SpacesInConditionalStatement: false
SpacesInLineCommentPrefix:
Minimum: 1
Maximum: 1
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Latest
TabWidth: 2
UseCRLF: false
UseTab: Never
No
.clang-format
.Input and expected output:
Actual output:
Using parentheses works as expected: