diff options
| author | Daniel Jasper <djasper@google.com> | 2016-06-13 07:49:35 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2016-06-13 07:49:35 +0000 |
| commit | 215616691a21ced6ab8cc9fe899a4ae8c46dd0e2 (patch) | |
| tree | 7f06d41cd59504a99a9b29b8fe1dd314c159ad1e /clang | |
| parent | 43e4d3a05be7e797045e36091ab354face31800f (diff) | |
| download | bcm5719-llvm-215616691a21ced6ab8cc9fe899a4ae8c46dd0e2.tar.gz bcm5719-llvm-215616691a21ced6ab8cc9fe899a4ae8c46dd0e2.zip | |
clang-format: Fix incorrect function type detection.
Before:
returnsFunction (¶m1, ¶m2)(param);
After:
returnsFunction(¶m1, ¶m2)(param);
llvm-svn: 272538
Diffstat (limited to 'clang')
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 13 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 1 |
2 files changed, 8 insertions, 6 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 8a36aca97e5..41bf10dd800 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/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/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index d82770ba683..3b580b5ae24 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/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) { |

