diff options
author | Alexander Kornienko <alexfh@google.com> | 2013-06-17 13:19:53 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2013-06-17 13:19:53 +0000 |
commit | afaa8f556b9d62fd6e6a0486abbc64ee9a1a4110 (patch) | |
tree | 6918034a79a3e707dcb063f5ecb8eb9c9bea0734 /clang | |
parent | 3ff679a19a62c079ae4aca24becb5c86febbc0d9 (diff) | |
download | bcm5719-llvm-afaa8f556b9d62fd6e6a0486abbc64ee9a1a4110.tar.gz bcm5719-llvm-afaa8f556b9d62fd6e6a0486abbc64ee9a1a4110.zip |
Fix a problem in ExpressionParser leading to trailing comments affecting indentation of an expression after a line break.
Summary:
E.g. the second line in
return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
b; //
is indented 4 characters more than in
return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
b;
Reviewers: klimek
Reviewed By: klimek
CC: cfe-commits
Differential Revision: http://llvm-reviews.chandlerc.com/D984
llvm-svn: 184078
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 11 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 7 |
2 files changed, 11 insertions, 7 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 85c5a36a0a7..c6b491914b3 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -151,7 +151,7 @@ private: if (!CurrentToken) return false; - // A '[' could be an index subscript (after an indentifier or after + // A '[' could be an index subscript (after an identifier or after // ')' or ']'), it could be the start of an Objective-C method // expression, or it could the the start of an Objective-C array literal. FormatToken *Left = CurrentToken->Previous; @@ -792,11 +792,6 @@ public: if (Precedence > prec::PointerToMember || Current == NULL) return; - // Eagerly consume trailing comments. - while (Current && Current->isTrailingComment()) { - next(); - } - FormatToken *Start = Current; bool OperatorFound = false; @@ -862,7 +857,9 @@ private: } void next() { - if (Current != NULL) + if (Current) + Current = Current->Next; + while (Current && Current->isTrailingComment()) Current = Current->Next; } diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index a26bf607214..8454af32ed5 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -2150,6 +2150,13 @@ TEST_F(FormatTest, ExpressionIndentation) { "} else if (aaaaa && bbbbb > // break\n" " ccccc) {\n" "}"); + + // Presence of a trailing comment used to change indentation of b. + verifyFormat("return aaaaaaaaaaaaaaaaaaa +\n" + " b;\n" + "return aaaaaaaaaaaaaaaaaaa +\n" + " b; //", + getLLVMStyleWithColumns(30)); } TEST_F(FormatTest, ConstructorInitializers) { |