@@ -189,25 +189,29 @@ class AnnotatingParser {
189189 next ();
190190 }
191191
192- for (bool SeenTernaryOperator = false ; CurrentToken;) {
192+ for (bool SeenTernaryOperator = false , MaybeAngles = true ; CurrentToken;) {
193193 const bool InExpr = Contexts[Contexts.size () - 2 ].IsExpression ;
194194 if (CurrentToken->is (tok::greater)) {
195195 const auto *Next = CurrentToken->Next ;
196- // Try to do a better job at looking for ">>" within the condition of
197- // a statement. Conservatively insert spaces between consecutive ">"
198- // tokens to prevent splitting right bitshift operators and potentially
199- // altering program semantics. This check is overly conservative and
200- // will prevent spaces from being inserted in select nested template
201- // parameter cases, but should not alter program semantics.
202- if (Next && Next->is (tok::greater) &&
203- Left->ParentBracket != tok::less &&
204- CurrentToken->getStartOfNonWhitespace () ==
205- Next->getStartOfNonWhitespace ().getLocWithOffset (-1 )) {
206- return false ;
207- }
208- if (InExpr && SeenTernaryOperator &&
209- (!Next || !Next->isOneOf (tok::l_paren, tok::l_brace))) {
210- return false ;
196+ if (CurrentToken->isNot (TT_TemplateCloser)) {
197+ // Try to do a better job at looking for ">>" within the condition of
198+ // a statement. Conservatively insert spaces between consecutive ">"
199+ // tokens to prevent splitting right shift operators and potentially
200+ // altering program semantics. This check is overly conservative and
201+ // will prevent spaces from being inserted in select nested template
202+ // parameter cases, but should not alter program semantics.
203+ if (Next && Next->is (tok::greater) &&
204+ Left->ParentBracket != tok::less &&
205+ CurrentToken->getStartOfNonWhitespace () ==
206+ Next->getStartOfNonWhitespace ().getLocWithOffset (-1 )) {
207+ return false ;
208+ }
209+ if (InExpr && SeenTernaryOperator &&
210+ (!Next || !Next->isOneOf (tok::l_paren, tok::l_brace))) {
211+ return false ;
212+ }
213+ if (!MaybeAngles)
214+ return false ;
211215 }
212216 Left->MatchingParen = CurrentToken;
213217 CurrentToken->MatchingParen = Left;
@@ -247,11 +251,11 @@ class AnnotatingParser {
247251 // operator that was misinterpreted because we are parsing template
248252 // parameters.
249253 // FIXME: This is getting out of hand, write a decent parser.
250- if (InExpr && !Line.startsWith (tok::kw_template) &&
254+ if (MaybeAngles && InExpr && !Line.startsWith (tok::kw_template) &&
251255 Prev.is (TT_BinaryOperator)) {
252256 const auto Precedence = Prev.getPrecedence ();
253257 if (Precedence > prec::Conditional && Precedence < prec::Relational)
254- return false ;
258+ MaybeAngles = false ;
255259 }
256260 if (Prev.isOneOf (tok::question, tok::colon) && !Style.isProto ())
257261 SeenTernaryOperator = true ;
@@ -1627,7 +1631,7 @@ class AnnotatingParser {
16271631 return false ;
16281632 break ;
16291633 case tok::greater:
1630- if (Style.Language != FormatStyle::LK_TextProto)
1634+ if (Style.Language != FormatStyle::LK_TextProto && Tok-> is (TT_Unknown) )
16311635 Tok->setType (TT_BinaryOperator);
16321636 if (Tok->Previous && Tok->Previous ->is (TT_TemplateCloser))
16331637 Tok->SpacesRequiredBefore = 1 ;
0 commit comments