curdeius created this revision. curdeius added reviewers: MyDeveloperDay, HazardyKnusperkeks, owenpan. curdeius requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
Fixes https://github.com/llvm/llvm-project/issues/52914. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D116527 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 @@ -15170,9 +15170,9 @@ "int i = 0;\n" "float i2 = 0;\n" "auto v = type{\n" - " i = 1, //\n" - " (i = 2), //\n" - " i = 3 //\n" + " i = 1, //\n" + " (i = 2), //\n" + " i = 3 //\n" "};", Style); @@ -16402,6 +16402,11 @@ " double bar();\n" "};\n", Alignment); + // http://llvm.org/PR52914 + verifyFormat("char *a[] = {\"a\", // comment\n" + " \"bb\"};\n" + "int bbbbbbb = 0;", + Alignment); // PAS_Right EXPECT_EQ("void SomeFunction(int parameter = 0) {\n" @@ -16660,9 +16665,9 @@ "int i = 0;\n" "float i2 = 0;\n" "auto v = type{\n" - " i = 1, //\n" - " (i = 2), //\n" - " i = 3 //\n" + " i = 1, //\n" + " (i = 2), //\n" + " i = 3 //\n" "};", Alignment); Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_None; Index: clang/lib/Format/WhitespaceManager.cpp =================================================================== --- clang/lib/Format/WhitespaceManager.cpp +++ clang/lib/Format/WhitespaceManager.cpp @@ -362,6 +362,11 @@ Changes[i].Tok->Previous->is(TT_ConditionalExpr)) return true; + // Continued braced list. + if (Changes[ScopeStart - 1].Tok->is(tok::l_brace) && + Changes[i].Tok->isNot(tok::r_brace)) + return true; + return false; };
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -15170,9 +15170,9 @@ "int i = 0;\n" "float i2 = 0;\n" "auto v = type{\n" - " i = 1, //\n" - " (i = 2), //\n" - " i = 3 //\n" + " i = 1, //\n" + " (i = 2), //\n" + " i = 3 //\n" "};", Style); @@ -16402,6 +16402,11 @@ " double bar();\n" "};\n", Alignment); + // http://llvm.org/PR52914 + verifyFormat("char *a[] = {\"a\", // comment\n" + " \"bb\"};\n" + "int bbbbbbb = 0;", + Alignment); // PAS_Right EXPECT_EQ("void SomeFunction(int parameter = 0) {\n" @@ -16660,9 +16665,9 @@ "int i = 0;\n" "float i2 = 0;\n" "auto v = type{\n" - " i = 1, //\n" - " (i = 2), //\n" - " i = 3 //\n" + " i = 1, //\n" + " (i = 2), //\n" + " i = 3 //\n" "};", Alignment); Alignment.AlignConsecutiveAssignments = FormatStyle::ACS_None; Index: clang/lib/Format/WhitespaceManager.cpp =================================================================== --- clang/lib/Format/WhitespaceManager.cpp +++ clang/lib/Format/WhitespaceManager.cpp @@ -362,6 +362,11 @@ Changes[i].Tok->Previous->is(TT_ConditionalExpr)) return true; + // Continued braced list. + if (Changes[ScopeStart - 1].Tok->is(tok::l_brace) && + Changes[i].Tok->isNot(tok::r_brace)) + return true; + return false; };
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits