From: Alexander Kornienko Date: Mon, 17 Jun 2013 13:19:53 +0000 (+0000) Subject: Fix a problem in ExpressionParser leading to trailing comments affecting indentation... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d71b15badeecdc049440103ef044f9cdf5e1359c;p=clang 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184078 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 85c5a36a0a..c6b491914b 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/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/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index a26bf60721..8454af32ed 100644 --- a/unittests/Format/FormatTest.cpp +++ b/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) {