clang-format: Fix incorrect classification of "*".

Before:
  *a = b *c;

After:
  *a = b * c;

llvm-svn: 226923
This commit is contained in:
Daniel Jasper 2015-01-23 19:04:49 +00:00
parent 0823ea636e
commit 7509216a41
2 changed files with 15 additions and 13 deletions

View File

@ -747,22 +747,23 @@ private:
void modifyContext(const FormatToken &Current) {
if (Current.getPrecedence() == prec::Assignment &&
!Line.First->isOneOf(tok::kw_template, tok::kw_using,
TT_UnaryOperator) &&
!Line.First->isOneOf(tok::kw_template, tok::kw_using) &&
(!Current.Previous || Current.Previous->isNot(tok::kw_operator))) {
Contexts.back().IsExpression = true;
for (FormatToken *Previous = Current.Previous;
Previous && !Previous->isOneOf(tok::comma, tok::semi);
Previous = Previous->Previous) {
if (Previous->isOneOf(tok::r_square, tok::r_paren)) {
Previous = Previous->MatchingParen;
if (!Previous)
break;
if (!Line.First->is(TT_UnaryOperator)) {
for (FormatToken *Previous = Current.Previous;
Previous && !Previous->isOneOf(tok::comma, tok::semi);
Previous = Previous->Previous) {
if (Previous->isOneOf(tok::r_square, tok::r_paren)) {
Previous = Previous->MatchingParen;
if (!Previous)
break;
}
if (Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator) &&
Previous->isOneOf(tok::star, tok::amp) && Previous->Previous &&
Previous->Previous->isNot(tok::equal))
Previous->Type = TT_PointerOrReference;
}
if (Previous->isOneOf(TT_BinaryOperator, TT_UnaryOperator) &&
Previous->isOneOf(tok::star, tok::amp) && Previous->Previous &&
Previous->Previous->isNot(tok::equal))
Previous->Type = TT_PointerOrReference;
}
} else if (Current.isOneOf(tok::kw_return, tok::kw_throw)) {
Contexts.back().IsExpression = true;

View File

@ -5220,6 +5220,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
" aaaaaaaaaaaaaaaaaaaaaaaaaaaa, *aaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");
verifyGoogleFormat("**outparam = 1;");
verifyGoogleFormat("*outparam = a * b;");
verifyGoogleFormat("int main(int argc, char** argv) {}");
verifyGoogleFormat("A<int*> a;");
verifyGoogleFormat("A<int**> a;");