New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[clang-format] Fix a bug in ContinuationIndenter #66354
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
llvmbot
added
clang
Clang issues not falling into any other category
clang-format
labels
Sep 14, 2023
@llvm/pr-subscribers-clang-format @llvm/pr-subscribers-clang ChangesSee https://reviews.llvm.org/D136154#3890747 for context.Fixes part of #58592.Full diff: https://github.com/llvm/llvm-project/pull/66354.diff 2 Files Affected:
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 75ab08de42ea0e8..8f14105751daefa 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -876,8 +876,9 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun, FormatStyle::BCIS_AfterColon) { CurrentState.Indent = State.Column; CurrentState.LastSpace = State.Column; - } else if ((Previous.isOneOf(TT_BinaryOperator, TT_ConditionalExpr, - TT_CtorInitializerColon)) && + } else if (Previous.isOneOf(TT_ConditionalExpr, TT_CtorInitializerColon)) { + State.Stack.back().LastSpace = State.Column; + } else if (Previous.is(TT_BinaryOperator) && ((Previous.getPrecedence() != prec::Assignment && (Previous.isNot(tok::lessless) || Previous.OperatorIndex != 0 || Previous.NextOperator)) || diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 4f72166bdce2d73..0d0fbdb84e3271b 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -7108,6 +7108,29 @@ TEST_F(FormatTest, ExpressionIndentationBreakingBeforeOperators) { "(someOtherLongishConditionPart1 || " "someOtherEvenLongerNestedConditionPart2);", Style); + + Style = getLLVMStyleWithColumns(20); + Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak; + Style.BinPackParameters = false; + Style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment; + Style.ContinuationIndentWidth = 2; + verifyFormat("struct Foo {\n" + " Foo(\n" + " int arg1,\n" + " int arg2)\n" + " : Base(\n" + " arg1,\n" + " arg2) {}\n" + "};", + Style); + verifyFormat("return abc\n" + " ? foo(\n" + " a,\n" + " b,\n" + " bar(\n" + " abc))\n" + " : g(abc);", + Style); } TEST_F(FormatTest, ExpressionIndentationStrictAlign) { |
mydeveloperday
approved these changes
Sep 14, 2023
See https://reviews.llvm.org/D136154#3890747 for context. Fixes part of llvm#58592.
ZijunZhaoCCK
pushed a commit
to ZijunZhaoCCK/llvm-project
that referenced
this pull request
Sep 19, 2023
See https://reviews.llvm.org/D136154#3890747 for context. Fixes part of llvm#58592.
zahiraam
pushed a commit
to tahonermann/llvm-project
that referenced
this pull request
Oct 24, 2023
See https://reviews.llvm.org/D136154#3890747 for context. Fixes part of llvm#58592.
zahiraam
pushed a commit
to tahonermann/llvm-project
that referenced
this pull request
Oct 24, 2023
See https://reviews.llvm.org/D136154#3890747 for context. Fixes part of llvm#58592.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See https://reviews.llvm.org/D136154#3890747 for context.
Fixes part of #58592.