]> granicus.if.org Git - clang/commitdiff
clang-format: Improve detection of function types.
authorDaniel Jasper <djasper@google.com>
Tue, 16 Jul 2013 11:37:21 +0000 (11:37 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 16 Jul 2013 11:37:21 +0000 (11:37 +0000)
This fixes an incorrect detection that led to a formatting error.
Before:
  some_var = function (*some_pointer_var)[0];
After:
  some_var = function(*some_pointer_var)[0];

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

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

index 1d5904b3186709be1556a9328f924bfc3748b228..2d1c1e3f4ac0ff0ff30315281ce227311b02d91e 100644 (file)
@@ -122,7 +122,9 @@ private:
 
       if (CurrentToken->is(tok::r_paren)) {
         if (MightBeFunctionType && CurrentToken->Next &&
-            CurrentToken->Next->isOneOf(tok::l_paren, tok::l_square))
+            (CurrentToken->Next->is(tok::l_paren) ||
+             (CurrentToken->Next->is(tok::l_square) &&
+              !Contexts.back().IsExpression)))
           Left->Type = TT_FunctionTypeLParen;
         Left->MatchingParen = CurrentToken;
         CurrentToken->MatchingParen = Left;
index c8827c8dec63511877320ba45267eaccf2fc1241..747a140846ba11fce934507a80ef0324bc53abf1 100644 (file)
@@ -3628,6 +3628,8 @@ TEST_F(FormatTest, FormatsFunctionTypes) {
   // Other constructs can look somewhat like function types:
   verifyFormat("A<sizeof(*x)> a;");
   verifyFormat("#define DEREF_AND_CALL_F(x) f(*x)");
+  verifyFormat("some_var = function(*some_pointer_var)[0];");
+  verifyFormat("void f() { function(*some_pointer_var)[0] = 10; }");
 }
 
 TEST_F(FormatTest, BreaksLongDeclarations) {