diff options
author | Daniel Jasper <djasper@google.com> | 2013-01-23 12:58:14 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-01-23 12:58:14 +0000 |
commit | 20d3583857c2cc99dcc9c27ff5f23916df9c0812 (patch) | |
tree | 2acc41d0440fd2e0147720561bacac8425b50a27 | |
parent | 7006e7ebc0098b7627bd3cc13367ea576c25dcbb (diff) |
Fix the formatting of pointer/reference types in range-based for loops.
Before: for (int & a : Values) {}
After: for (int &a : Values) {}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@173259 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Format/Format.cpp | 3 | ||||
-rw-r--r-- | unittests/Format/FormatTest.cpp | 4 |
2 files changed, 6 insertions, 1 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index c75b8ef834..d95deb5704 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -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) { diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 279b61c262..d1af838a73 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -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]();"); |