@@ -1639,6 +1639,31 @@ class AnnotatingParser {
16391639 case tok::kw_operator:
16401640 if (Style.isProto ())
16411641 break ;
1642+ // Handle C++ user-defined conversion function.
1643+ if (IsCpp && CurrentToken) {
1644+ const auto *Info = CurrentToken->Tok .getIdentifierInfo ();
1645+ // What follows Tok is an identifier or a non-operator keyword.
1646+ if (Info && !(CurrentToken->isPlacementOperator () ||
1647+ CurrentToken->is (tok::kw_co_await) ||
1648+ Info->isCPlusPlusOperatorKeyword ())) {
1649+ FormatToken *LParen;
1650+ if (CurrentToken->startsSequence (tok::kw_decltype, tok::l_paren,
1651+ tok::kw_auto, tok::r_paren)) {
1652+ // Skip `decltype(auto)`.
1653+ LParen = CurrentToken->Next ->Next ->Next ->Next ;
1654+ } else {
1655+ // Skip to l_paren.
1656+ for (LParen = CurrentToken->Next ;
1657+ LParen && LParen->isNot (tok::l_paren); LParen = LParen->Next ) {
1658+ }
1659+ }
1660+ if (LParen && LParen->is (tok::l_paren)) {
1661+ Tok->setFinalizedType (TT_FunctionDeclarationName);
1662+ LParen->setFinalizedType (TT_FunctionDeclarationLParen);
1663+ break ;
1664+ }
1665+ }
1666+ }
16421667 while (CurrentToken &&
16431668 !CurrentToken->isOneOf (tok::l_paren, tok::semi, tok::r_paren)) {
16441669 if (CurrentToken->isOneOf (tok::star, tok::amp))
@@ -2999,7 +3024,7 @@ class AnnotatingParser {
29993024 return TT_UnaryOperator;
30003025 if (PrevToken->is (TT_TypeName))
30013026 return TT_PointerOrReference;
3002- if (PrevToken->isOneOf (tok::kw_new, tok::kw_delete ) && Tok.is (tok::ampamp))
3027+ if (PrevToken->isPlacementOperator ( ) && Tok.is (tok::ampamp))
30033028 return TT_BinaryOperator;
30043029
30053030 const FormatToken *NextToken = Tok.getNextNonComment ();
@@ -3071,12 +3096,10 @@ class AnnotatingParser {
30713096 if (InTemplateArgument && NextToken->Tok .isAnyIdentifier ())
30723097 return TT_BinaryOperator;
30733098
3074- // "&&" followed by "(", "*", or "&" is quite unlikely to be two successive
3075- // unary "&".
3076- if (Tok.is (tok::ampamp) &&
3077- NextToken->isOneOf (tok::l_paren, tok::star, tok::amp)) {
3099+ // "&&" followed by "*" or "&" is quite unlikely to be two successive unary
3100+ // "&".
3101+ if (Tok.is (tok::ampamp) && NextToken->isOneOf (tok::star, tok::amp))
30783102 return TT_BinaryOperator;
3079- }
30803103
30813104 // This catches some cases where evaluation order is used as control flow:
30823105 // aaa && aaa->f();
@@ -3791,7 +3814,7 @@ static bool isFunctionDeclarationName(const LangOptions &LangOpts,
37913814 return Next;
37923815 if (Next->is (TT_OverloadedOperator))
37933816 continue ;
3794- if (Next->isOneOf (tok::kw_new, tok::kw_delete, tok::kw_co_await)) {
3817+ if (Next->isPlacementOperator () || Next-> is ( tok::kw_co_await)) {
37953818 // For 'new[]' and 'delete[]'.
37963819 if (Next->Next &&
37973820 Next->Next ->startsSequence (tok::l_square, tok::r_square)) {
@@ -4802,7 +4825,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
48024825 spaceRequiredBeforeParens (Right);
48034826 }
48044827 if (Style.SpaceBeforeParens == FormatStyle::SBPO_Custom &&
4805- Left.isOneOf (tok::kw_new, tok::kw_delete ) &&
4828+ Left.isPlacementOperator ( ) &&
48064829 Right.isNot (TT_OverloadedOperatorLParen) &&
48074830 !(Line.MightBeFunctionDecl && Left.is (TT_FunctionDeclarationName))) {
48084831 const auto *RParen = Right.MatchingParen ;
@@ -4845,7 +4868,7 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
48454868 return Style.SpaceBeforeParensOptions .AfterControlStatements ||
48464869 spaceRequiredBeforeParens (Right);
48474870 }
4848- if (Left.isOneOf (tok::kw_new, tok::kw_delete ) ||
4871+ if (Left.isPlacementOperator ( ) ||
48494872 (Left.is (tok::r_square) && Left.MatchingParen &&
48504873 Left.MatchingParen ->Previous &&
48514874 Left.MatchingParen ->Previous ->is (tok::kw_delete))) {
0 commit comments