]> granicus.if.org Git - clang/commitdiff
Fix bug in the alignment of comments.
authorDaniel Jasper <djasper@google.com>
Wed, 6 Feb 2013 22:04:05 +0000 (22:04 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 6 Feb 2013 22:04:05 +0000 (22:04 +0000)
Before:
const char *test[] = {
  // A
  "aaaa",
               // B
  "aaaaa",
};

After:
const char *test[] = {
  // A
  "aaaa",
  // B
  "aaaaa",
};

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

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

index 4128785f637ce04e7f27a5f8b2c1a582b6ad960f..7f78ac0bcf094626d0a3c494419dfa3bc4accbb5 100644 (file)
@@ -111,7 +111,10 @@ public:
         Comments.back().Tok = Tok.FormatTok;
         Comments.back().Spaces = Spaces;
         Comments.back().NewLines = NewLines;
-        Comments.back().MinColumn = WhitespaceStartColumn + Spaces;
+        if (NewLines == 0)
+          Comments.back().MinColumn = WhitespaceStartColumn + Spaces;
+        else
+          Comments.back().MinColumn = Spaces;
         Comments.back().MaxColumn =
             Style.ColumnLimit - Spaces - Tok.FormatTok.TokenLength;
         return;
index 160126ba3d91d043d1871eb84f4c0dca1a05f91a..10742a2609031b8c04f87ed00ff20f2383700317 100644 (file)
@@ -485,6 +485,13 @@ TEST_F(FormatTest, UnderstandsSingleLineComments) {
                "    parameter));");
 
   verifyGoogleFormat("#endif  // HEADER_GUARD");
+
+  verifyFormat("const char *test[] = {\n"
+               "  // A\n"
+               "  \"aaaa\",\n"
+               "  // B\n"
+               "  \"aaaaa\",\n"
+               "};");
 }
 
 TEST_F(FormatTest, UnderstandsMultiLineComments) {