From e7d3bff31e3ef4fea1e2a5a7cd5441b6b0752e3f Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Tue, 16 Jul 2013 11:37:21 +0000 Subject: [PATCH] clang-format: Improve detection of function types. 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 | 4 +++- unittests/Format/FormatTest.cpp | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 1d5904b318..2d1c1e3f4a 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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; diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index c8827c8dec..747a140846 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -3628,6 +3628,8 @@ TEST_F(FormatTest, FormatsFunctionTypes) { // Other constructs can look somewhat like function types: verifyFormat("A 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) { -- 2.40.0