clang-format: Improve *-detection.

Before:
  S << a *(10);

After:
  S << a * (10);

This fixes llvm.org/PR16500.

llvm-svn: 237690
This commit is contained in:
Daniel Jasper 2015-05-19 12:29:27 +00:00
parent c8cd58fa26
commit 9310166a63
2 changed files with 5 additions and 0 deletions

View File

@ -825,6 +825,9 @@ private:
Previous->Type = TT_PointerOrReference; Previous->Type = TT_PointerOrReference;
} }
} }
} else if (Current.is(tok::lessless) &&
(!Current.Previous || !Current.Previous->is(tok::kw_operator))) {
Contexts.back().IsExpression = true;
} else if (Current.isOneOf(tok::kw_return, tok::kw_throw)) { } else if (Current.isOneOf(tok::kw_return, tok::kw_throw)) {
Contexts.back().IsExpression = true; Contexts.back().IsExpression = true;
} else if (Current.is(TT_TrailingReturnArrow)) { } else if (Current.is(TT_TrailingReturnArrow)) {

View File

@ -5468,6 +5468,8 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
verifyIndependentOfContext("int a = *b;"); verifyIndependentOfContext("int a = *b;");
verifyIndependentOfContext("int a = *b * c;"); verifyIndependentOfContext("int a = *b * c;");
verifyIndependentOfContext("int a = b * *c;"); verifyIndependentOfContext("int a = b * *c;");
verifyIndependentOfContext("int a = b * (10);");
verifyIndependentOfContext("S << b * (10);");
verifyIndependentOfContext("return 10 * b;"); verifyIndependentOfContext("return 10 * b;");
verifyIndependentOfContext("return *b * *c;"); verifyIndependentOfContext("return *b * *c;");
verifyIndependentOfContext("return a & ~b;"); verifyIndependentOfContext("return a & ~b;");