]> granicus.if.org Git - clang/commitdiff
Fix the formatting of pointer/reference types in range-based for loops.
authorDaniel Jasper <djasper@google.com>
Wed, 23 Jan 2013 12:58:14 +0000 (12:58 +0000)
committerDaniel Jasper <djasper@google.com>
Wed, 23 Jan 2013 12:58:14 +0000 (12:58 +0000)
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

lib/Format/Format.cpp
unittests/Format/FormatTest.cpp

index c75b8ef834bc334fd0f6d401c19550d3f00f73c0..d95deb570465293faed72fad015aed9611ef3ba0 100644 (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) {
index 279b61c262b871815199cd13bec1f663b25eb1cd..d1af838a730dfcc61e46c7885d0a4b197ddc2dcc 100644 (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]();");