aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2014-04-27 10:03:19 +0000
committerDaniel Jasper <djasper@google.com>2014-04-27 10:03:19 +0000
commit394dfe84015000ce205ff9336f37553d6dd59061 (patch)
tree1624098ff9dba55e23eca4397b0a5ffdbf50ced0
parent2e3eed3e5bdca4f5c1fd2af2320e3761869d292e (diff)
downloadclang_35a-394dfe84015000ce205ff9336f37553d6dd59061.tar.gz
clang-format: Fix bug when aligning trailing /**/-comments in macros.
Previously this could lead to a column limit violation with the required escaped newlines. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207351 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Format/WhitespaceManager.cpp3
-rw-r--r--unittests/Format/FormatTest.cpp11
2 files changed, 13 insertions, 1 deletions
diff --git a/lib/Format/WhitespaceManager.cpp b/lib/Format/WhitespaceManager.cpp
index cea4799743..2906b17d7b 100644
--- a/lib/Format/WhitespaceManager.cpp
+++ b/lib/Format/WhitespaceManager.cpp
@@ -154,8 +154,9 @@ void WhitespaceManager::alignTrailingComments() {
continue;
unsigned ChangeMinColumn = Changes[i].StartOfTokenColumn;
- // FIXME: Correctly handle ChangeMaxColumn in PP directives.
unsigned ChangeMaxColumn = Style.ColumnLimit - Changes[i].TokenLength;
+ if (i + 1 != e && Changes[i + 1].ContinuesPPDirective)
+ ChangeMaxColumn -= 2;
// If this comment follows an } in column 0, it probably documents the
// closing of a namespace and we don't want to align it.
bool FollowsRBraceInColumn0 = i > 0 && Changes[i].NewlinesBefore == 0 &&
diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp
index 398850c38a..d18968afd5 100644
--- a/unittests/Format/FormatTest.cpp
+++ b/unittests/Format/FormatTest.cpp
@@ -832,6 +832,17 @@ TEST_F(FormatTest, UnderstandsSingleLineComments) {
" // first\n"
"// at start\n"
"otherLine();"));
+
+ verifyFormat(
+ "#define A \\\n"
+ " int i; /* iiiiiiiiiiiiiiiiiiiii */ \\\n"
+ " int jjjjjjjjjjjjjjjjjjjjjjjj; /* */",
+ getLLVMStyleWithColumns(60));
+ verifyFormat(
+ "#define A \\\n"
+ " int i; /* iiiiiiiiiiiiiiiiiiiii */ \\\n"
+ " int jjjjjjjjjjjjjjjjjjjjjjjj; /* */",
+ getLLVMStyleWithColumns(61));
}
TEST_F(FormatTest, KeepsParameterWithTrailingCommentsOnTheirOwnLine) {