llvm-project
e958fafc - [clang-format] Handle TT_EnumEqual in expression precedence and RHS indentation (#232918)

Commit
8 days ago
[clang-format] Handle TT_EnumEqual in expression precedence and RHS indentation (#232918) Follow-up to #223011 and #223435; Fixes #231986 When #194154 changed enum assignment `=` from `TT_BinaryOperator` to `TT_EnumEqual`, `ExpressionParser::getCurrentPrecedence()` and `ContinuationIndenter::addTokenOnCurrentLine()` were not updated to check `TT_EnumEqual`: 1. Because `ExpressionParser::getCurrentPrecedence()` ignored `TT_EnumEqual`, an enum initializer with a binary expression (such as `FLAG = 1 << 21`) was not split at `=`. Instead, `FakeLParens` for the RHS operator was attached to the enum identifier itself, causing `moveStatePastFakeLParens()` and `getNewLineColumn()` to apply `ContinuationIndentWidth` twice (+8 spaces instead of +4) when breaking after `=`. 2. When `<EnumIdentifier> = <FirstOperand>` fit within the column limit, both the double indentation penalty after `=` and the missing `TT_EnumEqual` check in `ContinuationIndenter::addTokenOnCurrentLine()` caused `clang-format` to break before the binary operator (`FLAG = 1\n << 21`) instead of after `=`. Include `TT_EnumEqual` in `ExpressionParser::getCurrentPrecedence()` and `ContinuationIndenter::addTokenOnCurrentLine()` so enum initializers with binary expressions break after `=` and indent by a single `ContinuationIndentWidth`. More detailed reproducer is at #231986
Author
Parents
Loading