cha5on updated this revision to Diff 428262. cha5on added a comment. Update for review
- Add and link bug report. - Remove braces per LLVM style. - Shrink down test case and add second case for direct-list-initialization alignment. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D125162/new/ https://reviews.llvm.org/D125162 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 @@ -17280,6 +17280,33 @@ // " ccc ? aaaaa : bbbbb,\n" // " dddddddddddddddddddddddddd);", // Alignment); + + // Confirm proper handling of AlignConsecutiveAssignments with + // BinPackArguments. + // See https://github.com/llvm/llvm-project/issues/55360 + Alignment = getLLVMStyleWithColumns(50); + Alignment.AlignConsecutiveAssignments.Enabled = true; + Alignment.BinPackArguments = false; + verifyFormat("int a_long_name = 1;\n" + "auto b = B({a_long_name, a_long_name},\n" + " {a_longer_name_for_wrap,\n" + " a_longer_name_for_wrap});", + "int a_long_name = 1;\n" + "auto b = B({a_long_name,\n" + " a_long_name},\n" + " {a_longer_name_for_wrap,\n" + "a_longer_name_for_wrap});", + Alignment); + verifyFormat("int a_long_name = 1;\n" + "auto b = B{{a_long_name, a_long_name},\n" + " {a_longer_name_for_wrap,\n" + " a_longer_name_for_wrap}};", + "int a_long_name = 1;\n" + "auto b = B{{a_long_name,\n" + " a_long_name},\n" + " {a_longer_name_for_wrap,\n" + "a_longer_name_for_wrap}};", + Alignment); } TEST_F(FormatTest, AlignConsecutiveBitFields) { Index: clang/lib/Format/WhitespaceManager.cpp =================================================================== --- clang/lib/Format/WhitespaceManager.cpp +++ clang/lib/Format/WhitespaceManager.cpp @@ -371,6 +371,9 @@ return false; if (Changes[ScopeStart].NewlinesBefore > 0) return false; + if (Changes[i].Tok->is(tok::l_brace) && + Changes[i].Tok->is(BK_BracedInit)) + return true; return Style.BinPackArguments; } @@ -387,6 +390,14 @@ Changes[i].Tok->Previous->is(TT_ConditionalExpr)) return true; + // Continued direct-list-initialization using braced list. + if (ScopeStart > Start + 1 && + Changes[ScopeStart - 2].Tok->is(tok::identifier) && + Changes[ScopeStart - 1].Tok->is(tok::l_brace) && + Changes[i].Tok->is(tok::l_brace) && + Changes[i].Tok->is(BK_BracedInit)) + return true; + // Continued braced list. if (ScopeStart > Start + 1 && Changes[ScopeStart - 2].Tok->isNot(tok::identifier) &&
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -17280,6 +17280,33 @@ // " ccc ? aaaaa : bbbbb,\n" // " dddddddddddddddddddddddddd);", // Alignment); + + // Confirm proper handling of AlignConsecutiveAssignments with + // BinPackArguments. + // See https://github.com/llvm/llvm-project/issues/55360 + Alignment = getLLVMStyleWithColumns(50); + Alignment.AlignConsecutiveAssignments.Enabled = true; + Alignment.BinPackArguments = false; + verifyFormat("int a_long_name = 1;\n" + "auto b = B({a_long_name, a_long_name},\n" + " {a_longer_name_for_wrap,\n" + " a_longer_name_for_wrap});", + "int a_long_name = 1;\n" + "auto b = B({a_long_name,\n" + " a_long_name},\n" + " {a_longer_name_for_wrap,\n" + "a_longer_name_for_wrap});", + Alignment); + verifyFormat("int a_long_name = 1;\n" + "auto b = B{{a_long_name, a_long_name},\n" + " {a_longer_name_for_wrap,\n" + " a_longer_name_for_wrap}};", + "int a_long_name = 1;\n" + "auto b = B{{a_long_name,\n" + " a_long_name},\n" + " {a_longer_name_for_wrap,\n" + "a_longer_name_for_wrap}};", + Alignment); } TEST_F(FormatTest, AlignConsecutiveBitFields) { Index: clang/lib/Format/WhitespaceManager.cpp =================================================================== --- clang/lib/Format/WhitespaceManager.cpp +++ clang/lib/Format/WhitespaceManager.cpp @@ -371,6 +371,9 @@ return false; if (Changes[ScopeStart].NewlinesBefore > 0) return false; + if (Changes[i].Tok->is(tok::l_brace) && + Changes[i].Tok->is(BK_BracedInit)) + return true; return Style.BinPackArguments; } @@ -387,6 +390,14 @@ Changes[i].Tok->Previous->is(TT_ConditionalExpr)) return true; + // Continued direct-list-initialization using braced list. + if (ScopeStart > Start + 1 && + Changes[ScopeStart - 2].Tok->is(tok::identifier) && + Changes[ScopeStart - 1].Tok->is(tok::l_brace) && + Changes[i].Tok->is(tok::l_brace) && + Changes[i].Tok->is(BK_BracedInit)) + return true; + // Continued braced list. if (ScopeStart > Start + 1 && Changes[ScopeStart - 2].Tok->isNot(tok::identifier) &&
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits