[clang] [clang-format] Fix a bug in ContinuationIndenter (PR #66354)
https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/66354 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a bug in ContinuationIndenter (PR #66354)
https://github.com/owenca updated https://github.com/llvm/llvm-project/pull/66354: >From 73669f7d04070feade2282384478e96b8bc6d727 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Thu, 14 Sep 2023 02:59:43 -0700 Subject: [PATCH] [clang-format] Fix a bug in ContinuationIndenter See https://reviews.llvm.org/D136154#3890747 for context. Fixes part of #58592. --- clang/lib/Format/ContinuationIndenter.cpp | 8 clang/unittests/Format/FormatTest.cpp | 23 +++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 75ab08de42ea0e8..65a7c1e26f57d06 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -876,15 +876,15 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState , 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)) { +CurrentState.LastSpace = State.Column; + } else if (Previous.is(TT_BinaryOperator) && ((Previous.getPrecedence() != prec::Assignment && (Previous.isNot(tok::lessless) || Previous.OperatorIndex != 0 || Previous.NextOperator)) || Current.StartsBinaryExpression)) { // Indent relative to the RHS of the expression unless this is a simple -// assignment without binary expression on the RHS. Also indent relative to -// unary operators and the colons of constructor initializers. +// assignment without binary expression on the RHS. if (Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None) CurrentState.LastSpace = State.Column; } else if (Previous.is(TT_InheritanceColon)) { 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) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a bug in ContinuationIndenter (PR #66354)
https://github.com/mydeveloperday approved this pull request. https://github.com/llvm/llvm-project/pull/66354 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a bug in ContinuationIndenter (PR #66354)
llvmbot wrote: @llvm/pr-subscribers-clang Changes See 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: - (modified) clang/lib/Format/ContinuationIndenter.cpp (+3-2) - (modified) clang/unittests/Format/FormatTest.cpp (+23) 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 amp;State, bool DryRun, FormatStyle::BCIS_AfterColon) { CurrentState.Indent = State.Column; CurrentState.LastSpace = State.Column; - } else if ((Previous.isOneOf(TT_BinaryOperator, TT_ConditionalExpr, - TT_CtorInitializerColon)) amp;amp; + } else if (Previous.isOneOf(TT_ConditionalExpr, TT_CtorInitializerColon)) { +State.Stack.back().LastSpace = State.Column; + } else if (Previous.is(TT_BinaryOperator) amp;amp; ((Previous.getPrecedence() != prec::Assignment amp;amp; (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) { quot;(someOtherLongishConditionPart1 || quot; quot;someOtherEvenLongerNestedConditionPart2);quot;, Style); + + Style = getLLVMStyleWithColumns(20); + Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak; + Style.BinPackParameters = false; + Style.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment; + Style.ContinuationIndentWidth = 2; + verifyFormat(quot;struct Foo {\nquot; + quot; Foo(\nquot; + quot;int arg1,\nquot; + quot;int arg2)\nquot; + quot; : Base(\nquot; + quot; arg1,\nquot; + quot; arg2) {}\nquot; + quot;};quot;, + Style); + verifyFormat(quot;return abc\nquot; + quot; ? foo(\nquot; + quot; a,\nquot; + quot; b,\nquot; + quot; bar(\nquot; + quot; abc))\nquot; + quot; : g(abc);quot;, + Style); } TEST_F(FormatTest, ExpressionIndentationStrictAlign) { https://github.com/llvm/llvm-project/pull/66354 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a bug in ContinuationIndenter (PR #66354)
https://github.com/llvmbot labeled https://github.com/llvm/llvm-project/pull/66354 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a bug in ContinuationIndenter (PR #66354)
https://github.com/llvmbot labeled https://github.com/llvm/llvm-project/pull/66354 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a bug in ContinuationIndenter (PR #66354)
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/66354: See https://reviews.llvm.org/D136154#3890747 for context. Fixes part of #58592. >From 9a15ec3256e2d380d5eb70f0751ea1bb457895dd Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Thu, 14 Sep 2023 02:59:43 -0700 Subject: [PATCH] [clang-format] Fix a bug in ContinuationIndenter See https://reviews.llvm.org/D136154#3890747 for context. Fixes part of #58592. --- clang/lib/Format/ContinuationIndenter.cpp | 5 +++-- clang/unittests/Format/FormatTest.cpp | 23 +++ 2 files changed, 26 insertions(+), 2 deletions(-) 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 , 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) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits