Fix the formatting of pointer/reference types in range-based for loops.

Before: for (int & a : Values) {}
After:  for (int &a : Values) {}
llvm-svn: 173259
This commit is contained in:
Daniel Jasper 2013-01-23 12:58:14 +00:00
parent 4766fe6f10
commit 420d7d333e
2 changed files with 6 additions and 1 deletions

View File

@ -1262,7 +1262,8 @@ private:
}
}
if (Current.is(tok::kw_return) || Current.is(tok::kw_throw) ||
(Current.is(tok::l_paren) && !Line.MustBeDeclaration))
(Current.is(tok::l_paren) && !Line.MustBeDeclaration &&
(Current.Parent == NULL || Current.Parent->isNot(tok::kw_for))))
IsExpression = true;
if (Current.Type == TT_Unknown) {

View File

@ -1356,6 +1356,10 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
verifyIndependentOfContext("if (*b[i])");
verifyIndependentOfContext("if (int *a = (&b))");
verifyIndependentOfContext("while (int *a = &b)");
verifyFormat("void f() {\n"
" for (const int &v : Values) {\n"
" }\n"
"}");
verifyIndependentOfContext("A = new SomeType *[Length]();");
verifyGoogleFormat("A = new SomeType* [Length]();");