From: Daniel Jasper Date: Mon, 13 Jun 2016 07:49:35 +0000 (+0000) Subject: clang-format: Fix incorrect function type detection. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8212e11814e016f9cd0e0e9f010b1912eb5d24c6;p=clang clang-format: Fix incorrect function type detection. Before: returnsFunction (¶m1, ¶m2)(param); After: returnsFunction(¶m1, ¶m2)(param); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272538 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 8a36aca97e..41bf10dd80 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -178,8 +178,8 @@ private: Left->Type = TT_ObjCMethodExpr; } - bool MightBeFunctionType = CurrentToken->isOneOf(tok::star, tok::amp) && - !Contexts[Contexts.size() - 2].IsExpression; + bool MightBeFunctionType = !Contexts[Contexts.size() - 2].IsExpression; + bool ProbablyFunctionType = CurrentToken->isOneOf(tok::star, tok::amp); bool HasMultipleLines = false; bool HasMultipleParametersOnALine = false; bool MightBeObjCForRangeLoop = @@ -206,14 +206,15 @@ private: if (CurrentToken->Previous->is(TT_PointerOrReference) && CurrentToken->Previous->Previous->isOneOf(tok::l_paren, tok::coloncolon)) - MightBeFunctionType = true; + ProbablyFunctionType = true; + if (CurrentToken->is(tok::comma)) + MightBeFunctionType = false; if (CurrentToken->Previous->is(TT_BinaryOperator)) Contexts.back().IsExpression = true; if (CurrentToken->is(tok::r_paren)) { - if (MightBeFunctionType && CurrentToken->Next && + if (MightBeFunctionType && ProbablyFunctionType && CurrentToken->Next && (CurrentToken->Next->is(tok::l_paren) || - (CurrentToken->Next->is(tok::l_square) && - Line.MustBeDeclaration))) + (CurrentToken->Next->is(tok::l_square) && Line.MustBeDeclaration))) Left->Type = TT_FunctionTypeLParen; Left->MatchingParen = CurrentToken; CurrentToken->MatchingParen = Left; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index d82770ba68..3b580b5ae2 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -6097,6 +6097,7 @@ TEST_F(FormatTest, FormatsFunctionTypes) { verifyFormat("some_var = function(*some_pointer_var)[0];"); verifyFormat("void f() { function(*some_pointer_var)[0] = 10; }"); verifyFormat("int x = f(&h)();"); + verifyFormat("returnsFunction(¶m1, ¶m2)(param);"); } TEST_F(FormatTest, FormatsPointersToArrayTypes) {