From: Daniel Jasper Date: Wed, 6 Feb 2013 22:04:05 +0000 (+0000) Subject: Fix bug in the alignment of comments. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f79f935f387f4a34f0f20a6d6cc1bfb8ebe8fbb4;p=platform%2Fupstream%2Fllvm.git Fix bug in the alignment of comments. Before: const char *test[] = { // A "aaaa", // B "aaaaa", }; After: const char *test[] = { // A "aaaa", // B "aaaaa", }; llvm-svn: 174549 --- diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 4128785..7f78ac0 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -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; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 160126b..10742a2 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -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) {