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 @@ -2177,14 +2177,22 @@ if (PrevToken->Tok.isLiteral() || PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::kw_true, - tok::kw_false, tok::r_brace) || - NextToken->Tok.isLiteral() || - NextToken->isOneOf(tok::kw_true, tok::kw_false) || - NextToken->isUnaryOperator() || - // If we know we're in a template argument, there are no named - // declarations. Thus, having an identifier on the right-hand side - // indicates a binary operator. - (InTemplateArgument && NextToken->Tok.isAnyIdentifier())) + tok::kw_false, tok::r_brace)) + return TT_BinaryOperator; + + const FormatToken *NextNonParen = NextToken; + while (NextNonParen && NextNonParen->is(tok::l_paren)) { + NextNonParen = NextNonParen->getNextNonComment(); + } + if (NextNonParen && (NextNonParen->Tok.isLiteral() || + NextNonParen->isOneOf(tok::kw_true, tok::kw_false) || + NextNonParen->isUnaryOperator())) + return TT_BinaryOperator; + + // If we know we're in a template argument, there are no named declarations. + // Thus, having an identifier on the right-hand side indicates a binary + // operator. + if (InTemplateArgument && NextToken->Tok.isAnyIdentifier()) return TT_BinaryOperator; // "&&(" is quite unlikely to be two successive unary "&". 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 @@ -10334,6 +10334,11 @@ verifyFormat("vector v;"); verifyFormat("foo();"); verifyFormat("foo();"); + verifyFormat("foo();"); + verifyFormat("foo();"); + verifyFormat("foo();"); + verifyFormat("foo();"); + verifyFormat("foo();"); verifyFormat("decltype(*::std::declval()) void F();"); verifyFormat("typeof(*::std::declval()) void F();"); verifyFormat("_Atomic(*::std::declval()) void F();");