This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGee3b2c47ce41: [clang-format] PR50525 doesn't handle AlignConsecutiveAssignments correctly in… (authored by MyDeveloperDay).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D104900/new/ https://reviews.llvm.org/D104900 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 @@ -16272,6 +16272,52 @@ // clang-format on } +TEST_F(FormatTest, AlignWithInitializerPeriods) { + auto Style = getLLVMStyleWithColumns(60); + + verifyFormat("void foo1(void) {\n" + " BYTE p[1] = 1;\n" + " A B = {.one_foooooooooooooooo = 2,\n" + " .two_fooooooooooooo = 3,\n" + " .three_fooooooooooooo = 4};\n" + " BYTE payload = 2;\n" + "}", + Style); + + Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive; + Style.AlignConsecutiveDeclarations = FormatStyle::ACS_None; + verifyFormat("void foo2(void) {\n" + " BYTE p[1] = 1;\n" + " A B = {.one_foooooooooooooooo = 2,\n" + " .two_fooooooooooooo = 3,\n" + " .three_fooooooooooooo = 4};\n" + " BYTE payload = 2;\n" + "}", + Style); + + Style.AlignConsecutiveAssignments = FormatStyle::ACS_None; + Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; + verifyFormat("void foo3(void) {\n" + " BYTE p[1] = 1;\n" + " A B = {.one_foooooooooooooooo = 2,\n" + " .two_fooooooooooooo = 3,\n" + " .three_fooooooooooooo = 4};\n" + " BYTE payload = 2;\n" + "}", + Style); + + Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive; + Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; + verifyFormat("void foo4(void) {\n" + " BYTE p[1] = 1;\n" + " A B = {.one_foooooooooooooooo = 2,\n" + " .two_fooooooooooooo = 3,\n" + " .three_fooooooooooooo = 4};\n" + " BYTE payload = 2;\n" + "}", + Style); +} + TEST_F(FormatTest, LinuxBraceBreaking) { FormatStyle LinuxBraceStyle = getLLVMStyle(); LinuxBraceStyle.BreakBeforeBraces = FormatStyle::BS_Linux; Index: clang/lib/Format/WhitespaceManager.cpp =================================================================== --- clang/lib/Format/WhitespaceManager.cpp +++ clang/lib/Format/WhitespaceManager.cpp @@ -353,6 +353,10 @@ if (Changes[i].Tok->is(TT_ConditionalExpr)) return true; + // Period Initializer .XXX = 1. + if (Changes[i].Tok->is(TT_DesignatedInitializerPeriod)) + return true; + // Continued ternary operator if (Changes[i].Tok->Previous && Changes[i].Tok->Previous->is(TT_ConditionalExpr))
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -16272,6 +16272,52 @@ // clang-format on } +TEST_F(FormatTest, AlignWithInitializerPeriods) { + auto Style = getLLVMStyleWithColumns(60); + + verifyFormat("void foo1(void) {\n" + " BYTE p[1] = 1;\n" + " A B = {.one_foooooooooooooooo = 2,\n" + " .two_fooooooooooooo = 3,\n" + " .three_fooooooooooooo = 4};\n" + " BYTE payload = 2;\n" + "}", + Style); + + Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive; + Style.AlignConsecutiveDeclarations = FormatStyle::ACS_None; + verifyFormat("void foo2(void) {\n" + " BYTE p[1] = 1;\n" + " A B = {.one_foooooooooooooooo = 2,\n" + " .two_fooooooooooooo = 3,\n" + " .three_fooooooooooooo = 4};\n" + " BYTE payload = 2;\n" + "}", + Style); + + Style.AlignConsecutiveAssignments = FormatStyle::ACS_None; + Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; + verifyFormat("void foo3(void) {\n" + " BYTE p[1] = 1;\n" + " A B = {.one_foooooooooooooooo = 2,\n" + " .two_fooooooooooooo = 3,\n" + " .three_fooooooooooooo = 4};\n" + " BYTE payload = 2;\n" + "}", + Style); + + Style.AlignConsecutiveAssignments = FormatStyle::ACS_Consecutive; + Style.AlignConsecutiveDeclarations = FormatStyle::ACS_Consecutive; + verifyFormat("void foo4(void) {\n" + " BYTE p[1] = 1;\n" + " A B = {.one_foooooooooooooooo = 2,\n" + " .two_fooooooooooooo = 3,\n" + " .three_fooooooooooooo = 4};\n" + " BYTE payload = 2;\n" + "}", + Style); +} + TEST_F(FormatTest, LinuxBraceBreaking) { FormatStyle LinuxBraceStyle = getLLVMStyle(); LinuxBraceStyle.BreakBeforeBraces = FormatStyle::BS_Linux; Index: clang/lib/Format/WhitespaceManager.cpp =================================================================== --- clang/lib/Format/WhitespaceManager.cpp +++ clang/lib/Format/WhitespaceManager.cpp @@ -353,6 +353,10 @@ if (Changes[i].Tok->is(TT_ConditionalExpr)) return true; + // Period Initializer .XXX = 1. + if (Changes[i].Tok->is(TT_DesignatedInitializerPeriod)) + return true; + // Continued ternary operator if (Changes[i].Tok->Previous && Changes[i].Tok->Previous->is(TT_ConditionalExpr))
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits