diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -397,9 +397,13 @@ !CurrentToken->Next->HasUnescapedNewline && !CurrentToken->Next->isTrailingComment()) HasMultipleParametersOnALine = true; + bool ProbablyFunctionTypeLParen = + (CurrentToken->is(tok::l_paren) && CurrentToken->Next && + CurrentToken->Next->isOneOf(tok::star, tok::amp, tok::caret)); if ((CurrentToken->Previous->isOneOf(tok::kw_const, tok::kw_auto) || CurrentToken->Previous->isSimpleTypeSpecifier()) && - !CurrentToken->isOneOf(tok::l_brace, tok::l_paren)) + !(CurrentToken->is(tok::l_brace) || + (CurrentToken->is(tok::l_paren) && !ProbablyFunctionTypeLParen))) Contexts.back().IsExpression = false; if (CurrentToken->isOneOf(tok::semi, tok::colon)) { MightBeObjCForRangeLoop = false; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -8707,6 +8707,11 @@ verifyIndependentOfContext("MACRO('0' <= c && c <= '9');"); verifyFormat("void f() { f(float{1}, a * a); }"); verifyFormat("void f() { f(float(1), a * a); }"); + + verifyFormat("f((void (*)(int))g);"); + verifyFormat("f((void (&)(int))g);"); + verifyFormat("f((void (^)(int))g);"); + // FIXME: Is there a way to make this work? // verifyIndependentOfContext("MACRO(A *a);"); verifyFormat("MACRO(A &B);");