r272538 - clang-format: Fix incorrect function type detection.
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 13 00:49:36 PDT 2016
Author: djasper
Date: Mon Jun 13 02:49:35 2016
New Revision: 272538
URL: http://llvm.org/viewvc/llvm-project?rev=272538&view=rev
Log:
clang-format: Fix incorrect function type detection.
Before:
returnsFunction (¶m1, ¶m2)(param);
After:
returnsFunction(¶m1, ¶m2)(param);
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=272538&r1=272537&r2=272538&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Jun 13 02:49:35 2016
@@ -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;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=272538&r1=272537&r2=272538&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jun 13 02:49:35 2016
@@ -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) {
More information about the cfe-commits
mailing list