summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/Format/WhitespaceManager.cpp11
-rw-r--r--unittests/Format/FormatTestComments.cpp7
2 files changed, 15 insertions, 3 deletions
diff --git a/lib/Format/WhitespaceManager.cpp b/lib/Format/WhitespaceManager.cpp
index 4b4fd13145..b1a5f1eab5 100644
--- a/lib/Format/WhitespaceManager.cpp
+++ b/lib/Format/WhitespaceManager.cpp
@@ -472,9 +472,14 @@ void WhitespaceManager::alignTrailingComments() {
continue;
unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn;
- unsigned ChangeMaxColumn = Style.ColumnLimit >= Changes[i].TokenLength
- ? Style.ColumnLimit - Changes[i].TokenLength
- : ChangeMinColumn;
+ unsigned ChangeMaxColumn;
+
+ if (Style.ColumnLimit == 0)
+ ChangeMaxColumn = UINT_MAX;
+ else if (Style.ColumnLimit >= Changes[i].TokenLength)
+ ChangeMaxColumn = Style.ColumnLimit - Changes[i].TokenLength;
+ else
+ ChangeMaxColumn = ChangeMinColumn;
// If we don't create a replacement for this change, we have to consider
// it to be immovable.
diff --git a/unittests/Format/FormatTestComments.cpp b/unittests/Format/FormatTestComments.cpp
index 7916e65e51..f3c45fac34 100644
--- a/unittests/Format/FormatTestComments.cpp
+++ b/unittests/Format/FormatTestComments.cpp
@@ -2267,6 +2267,13 @@ TEST_F(FormatTestComments, AlignTrailingComments) {
"int k; // line longg long",
getLLVMStyleWithColumns(20)));
+ // Always align if ColumnLimit = 0
+ EXPECT_EQ("int i, j; // line 1\n"
+ "int k; // line longg long",
+ format("int i, j; // line 1\n"
+ "int k; // line longg long",
+ getLLVMStyleWithColumns(0)));
+
// Align comment line sections aligned with the next token with the next
// token.
EXPECT_EQ("class A {\n"