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 @@ -2158,12 +2158,7 @@ if (PrevToken->is(tok::r_paren) && PrevToken->is(TT_TypeDeclarationParen)) return TT_PointerOrReference; - if (PrevToken->isOneOf(tok::l_paren, tok::l_square, tok::l_brace, - tok::comma, tok::semi, tok::kw_return, tok::colon, - tok::kw_co_return, tok::kw_co_await, - tok::kw_co_yield, tok::equal, tok::kw_delete, - tok::kw_sizeof, tok::kw_throw, TT_BinaryOperator, - TT_ConditionalExpr, TT_UnaryOperator, TT_CastRParen)) + if (determinePlusMinusCaretUsage(Tok) == TT_UnaryOperator) return TT_UnaryOperator; if (NextToken->is(tok::l_square) && NextToken->isNot(TT_LambdaLSquare)) @@ -2210,19 +2205,12 @@ if (!PrevToken) return TT_UnaryOperator; - if (PrevToken->isOneOf(TT_CastRParen, TT_UnaryOperator)) - // This must be a sequence of leading unary operators. - return TT_UnaryOperator; - - // Use heuristics to recognize unary operators. - if (PrevToken->isOneOf(tok::equal, tok::l_paren, tok::comma, tok::l_square, - tok::question, tok::colon, tok::kw_return, - tok::kw_case, tok::at, tok::l_brace, tok::kw_throw, - tok::kw_co_return, tok::kw_co_yield)) - return TT_UnaryOperator; - - // There can't be two consecutive binary operators. - if (PrevToken->is(TT_BinaryOperator)) + if (PrevToken->isOneOf( + TT_BinaryOperator, TT_CastRParen, TT_ConditionalExpr, + TT_UnaryOperator, tok::l_paren, tok::comma, tok::colon, tok::semi, + tok::equal, tok::question, tok::at, tok::l_square, tok::l_brace, + tok::kw_case, tok::kw_co_await, tok::kw_co_return, tok::kw_co_yield, + tok::kw_delete, tok::kw_return, tok::kw_sizeof, tok::kw_throw)) return TT_UnaryOperator; // Fall back to marking the token as binary operator.