]> granicus.if.org Git - clang/commitdiff
clang-format: Fix incorrect pointer detection.
authorDaniel Jasper <djasper@google.com>
Tue, 1 Nov 2016 06:23:14 +0000 (06:23 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 1 Nov 2016 06:23:14 +0000 (06:23 +0000)
Before:
  void f() { f(float{1}, a *a); }

After:
  void f() { f(float{1}, a * a); }

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@285673 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 1a3faad6e283b2f9847c6fd3f759c20adb7df33c..d010efab3e5530393d59211e5635e8d3edcd5ba0 100644 (file)
@@ -273,8 +273,9 @@ private:
           !CurrentToken->Next->HasUnescapedNewline &&
           !CurrentToken->Next->isTrailingComment())
         HasMultipleParametersOnALine = true;
-      if (CurrentToken->isOneOf(tok::kw_const, tok::kw_auto) ||
-          CurrentToken->isSimpleTypeSpecifier())
+      if ((CurrentToken->Previous->isOneOf(tok::kw_const, tok::kw_auto) ||
+           CurrentToken->Previous->isSimpleTypeSpecifier()) &&
+          !CurrentToken->is(tok::l_brace))
         Contexts.back().IsExpression = false;
       if (CurrentToken->isOneOf(tok::semi, tok::colon))
         MightBeObjCForRangeLoop = false;
index 8fe835e5793e1c40d2c10c09c214e6f850e92cd2..6ab4a7462908c86364445f027ea3952e9089d50c 100644 (file)
@@ -5870,6 +5870,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
   verifyIndependentOfContext("MACRO(auto *a);");
   verifyIndependentOfContext("MACRO(const A *a);");
   verifyIndependentOfContext("MACRO('0' <= c && c <= '9');");
+  verifyFormat("void f() { f(float{1}, a * a); }");
   // FIXME: Is there a way to make this work?
   // verifyIndependentOfContext("MACRO(A *a);");