Index: cfe/trunk/lib/Format/WhitespaceManager.cpp =================================================================== --- cfe/trunk/lib/Format/WhitespaceManager.cpp +++ cfe/trunk/lib/Format/WhitespaceManager.cpp @@ -164,8 +164,9 @@ const WhitespaceManager::Change *LastBlockComment = nullptr; for (auto &Change : Changes) { // Reset the IsTrailingComment flag for changes inside of trailing comments - // so they don't get realigned later. - if (Change.IsInsideToken) + // so they don't get realigned later. Comment line breaks however still need + // to be aligned. + if (Change.IsInsideToken && Change.NewlinesBefore == 0) Change.IsTrailingComment = false; Change.StartOfBlockComment = nullptr; Change.IndentationOffset = 0; Index: cfe/trunk/unittests/Format/FormatTest.cpp =================================================================== --- cfe/trunk/unittests/Format/FormatTest.cpp +++ cfe/trunk/unittests/Format/FormatTest.cpp @@ -11852,6 +11852,40 @@ " // line 3\n" " b);", getLLVMStyleWithColumns(40))); + + // Align newly broken trailing comments. + EXPECT_EQ("int ab; // line\n" + "int a; // long\n" + " // long\n", + format("int ab; // line\n" + "int a; // long long\n", + getLLVMStyleWithColumns(15))); + EXPECT_EQ("int ab; // line\n" + "int a; // long\n" + " // long\n" + " // long", + format("int ab; // line\n" + "int a; // long long\n" + " // long", + getLLVMStyleWithColumns(15))); + EXPECT_EQ("int ab; // line\n" + "int a; // long\n" + " // long\n" + "pt c; // long", + format("int ab; // line\n" + "int a; // long long\n" + "pt c; // long", + getLLVMStyleWithColumns(15))); + EXPECT_EQ("int ab; // line\n" + "int a; // long\n" + " // long\n" + "\n" + "// long", + format("int ab; // line\n" + "int a; // long long\n" + "\n" + "// long", + getLLVMStyleWithColumns(15))); } } // end namespace } // end namespace format