clang-format: Fix unary operator detection in for loops.

Before:
  for (;; * a = b) {}

After:
  for (;; *a = b) {}

llvm-svn: 242849
This commit is contained in:
Daniel Jasper 2015-07-21 22:51:00 +00:00
parent 1c65094d5b
commit bcad06640b
2 changed files with 3 additions and 1 deletions

View File

@ -836,7 +836,8 @@ private:
Contexts.back().IsExpression = true;
if (!Line.startsWith(TT_UnaryOperator)) {
for (FormatToken *Previous = Current.Previous;
Previous && !Previous->isOneOf(tok::comma, tok::semi);
Previous && Previous->Previous &&
!Previous->Previous->isOneOf(tok::comma, tok::semi);
Previous = Previous->Previous) {
if (Previous->isOneOf(tok::r_square, tok::r_paren)) {
Previous = Previous->MatchingParen;

View File

@ -5458,6 +5458,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
FormatStyle Left = getLLVMStyle();
Left.PointerAlignment = FormatStyle::PAS_Left;
verifyFormat("x = *a(x) = *a(y);", Left);
verifyFormat("for (;; * = b) {\n}", Left);
verifyIndependentOfContext("a = *(x + y);");
verifyIndependentOfContext("a = &(x + y);");