]> granicus.if.org Git - clang/commitdiff
clang-format: Fix aligning of comments and escaped newlines in macros.
authorDaniel Jasper <djasper@google.com>
Fri, 28 Mar 2014 15:06:01 +0000 (15:06 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 28 Mar 2014 15:06:01 +0000 (15:06 +0000)
Before:
  #define A      \
    int i;   /*a*/ \
    int jjj; /*b*/

After:
  #define A        \
    int i;   /*a*/ \
    int jjj; /*b*/

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@205011 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/WhitespaceManager.cpp
unittests/Format/FormatTest.cpp

index 26a8d41e87417ff1f025104449a7014bfa142732..4c393ed4397633251c3e18ab336cd6a01be5be01 100644 (file)
@@ -193,6 +193,10 @@ void WhitespaceManager::alignTrailingComments(unsigned Start, unsigned End,
     if (Changes[i].IsTrailingComment) {
       assert(Column >= Changes[i].StartOfTokenColumn);
       Changes[i].Spaces += Column - Changes[i].StartOfTokenColumn;
+      if (i + 1 != End) {
+        Changes[i + 1].PreviousEndOfTokenColumn +=
+            Column - Changes[i].StartOfTokenColumn;
+      }
       Changes[i].StartOfTokenColumn = Column;
     }
   }
index 2bf55125765f3a0c20be9673456f5365b4a1fde5..7332fd04e063e504ead6070cb31096dc5d4b86c9 100644 (file)
@@ -946,6 +946,11 @@ TEST_F(FormatTest, UnderstandsBlockComments) {
                "         /* parameter 3 */ aaaaaa,\n"
                "         /* parameter 4 */ aaaaaa);",
                NoBinPacking);
+
+  // Aligning block comments in macros.
+  verifyGoogleFormat("#define A        \\\n"
+                     "  int i;   /*a*/ \\\n"
+                     "  int jjj; /*b*/");
 }
 
 TEST_F(FormatTest, AlignsBlockComments) {