summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Format/WhitespaceManager.cpp5
-rw-r--r--clang/unittests/Format/FormatTest.cpp34
2 files changed, 37 insertions, 2 deletions
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index 3fd92eaf785..93a2e490c66 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/lib/Format/WhitespaceManager.cpp
@@ -164,8 +164,9 @@ void WhitespaceManager::calculateLineBreakInformation() {
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;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index d9f56e38f84..6cc9d1979fa 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -11852,6 +11852,40 @@ TEST_F(FormatTest, AlignTrailingComments) {
" // 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
OpenPOWER on IntegriCloud