This revision was automatically updated to reflect the committed changes. Closed by commit rG5987d7c59da5: [clang-format] fix indent in alignChainedConditionals (authored by krasimir).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D101033/new/ https://reviews.llvm.org/D101033 Files: clang/lib/Format/WhitespaceManager.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -6459,6 +6459,30 @@ " bbbb ? cccccccccccccccccc :\n" " ddddd;\n", Style); + + EXPECT_EQ( + "MMMMMMMMMMMMMMMMMMMMMMMMMMM = A ?\n" + " /*\n" + " */\n" + " function() {\n" + " try {\n" + " return JJJJJJJJJJJJJJ(\n" + " pppppppppppppppppppppppppppppppppppppppppppppppppp);\n" + " }\n" + " } :\n" + " function() {};", + format( + "MMMMMMMMMMMMMMMMMMMMMMMMMMM = A ?\n" + " /*\n" + " */\n" + " function() {\n" + " try {\n" + " return JJJJJJJJJJJJJJ(\n" + " pppppppppppppppppppppppppppppppppppppppppppppppppp);\n" + " }\n" + " } :\n" + " function() {};", + getGoogleStyle(FormatStyle::LK_JavaScript))); } TEST_F(FormatTest, BreaksConditionalExpressionsAfterOperator) { Index: clang/lib/Format/WhitespaceManager.cpp =================================================================== --- clang/lib/Format/WhitespaceManager.cpp +++ clang/lib/Format/WhitespaceManager.cpp @@ -778,12 +778,11 @@ Changes, /*StartAt=*/0); } else { static auto AlignWrappedOperand = [](Change const &C) { - auto Previous = C.Tok->getPreviousNonComment(); // Previous; + FormatToken *Previous = C.Tok->getPreviousNonComment(); return C.NewlinesBefore && Previous && Previous->is(TT_ConditionalExpr) && - (Previous->is(tok::question) || - (Previous->is(tok::colon) && - (C.Tok->FakeLParens.size() == 0 || - C.Tok->FakeLParens.back() != prec::Conditional))); + (Previous->is(tok::colon) && + (C.Tok->FakeLParens.size() == 0 || + C.Tok->FakeLParens.back() != prec::Conditional)); }; // Ensure we keep alignment of wrapped operands with non-wrapped operands // Since we actually align the operators, the wrapped operands need the
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -6459,6 +6459,30 @@ " bbbb ? cccccccccccccccccc :\n" " ddddd;\n", Style); + + EXPECT_EQ( + "MMMMMMMMMMMMMMMMMMMMMMMMMMM = A ?\n" + " /*\n" + " */\n" + " function() {\n" + " try {\n" + " return JJJJJJJJJJJJJJ(\n" + " pppppppppppppppppppppppppppppppppppppppppppppppppp);\n" + " }\n" + " } :\n" + " function() {};", + format( + "MMMMMMMMMMMMMMMMMMMMMMMMMMM = A ?\n" + " /*\n" + " */\n" + " function() {\n" + " try {\n" + " return JJJJJJJJJJJJJJ(\n" + " pppppppppppppppppppppppppppppppppppppppppppppppppp);\n" + " }\n" + " } :\n" + " function() {};", + getGoogleStyle(FormatStyle::LK_JavaScript))); } TEST_F(FormatTest, BreaksConditionalExpressionsAfterOperator) { Index: clang/lib/Format/WhitespaceManager.cpp =================================================================== --- clang/lib/Format/WhitespaceManager.cpp +++ clang/lib/Format/WhitespaceManager.cpp @@ -778,12 +778,11 @@ Changes, /*StartAt=*/0); } else { static auto AlignWrappedOperand = [](Change const &C) { - auto Previous = C.Tok->getPreviousNonComment(); // Previous; + FormatToken *Previous = C.Tok->getPreviousNonComment(); return C.NewlinesBefore && Previous && Previous->is(TT_ConditionalExpr) && - (Previous->is(tok::question) || - (Previous->is(tok::colon) && - (C.Tok->FakeLParens.size() == 0 || - C.Tok->FakeLParens.back() != prec::Conditional))); + (Previous->is(tok::colon) && + (C.Tok->FakeLParens.size() == 0 || + C.Tok->FakeLParens.back() != prec::Conditional)); }; // Ensure we keep alignment of wrapped operands with non-wrapped operands // Since we actually align the operators, the wrapped operands need the
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits