@@ -189,25 +189,29 @@ class AnnotatingParser {
189
189
next ();
190
190
}
191
191
192
- for (bool SeenTernaryOperator = false ; CurrentToken;) {
192
+ for (bool SeenTernaryOperator = false , MaybeAngles = true ; CurrentToken;) {
193
193
const bool InExpr = Contexts[Contexts.size () - 2 ].IsExpression ;
194
194
if (CurrentToken->is (tok::greater)) {
195
195
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 ;
211
215
}
212
216
Left->MatchingParen = CurrentToken;
213
217
CurrentToken->MatchingParen = Left;
@@ -243,11 +247,11 @@ class AnnotatingParser {
243
247
// operator that was misinterpreted because we are parsing template
244
248
// parameters.
245
249
// FIXME: This is getting out of hand, write a decent parser.
246
- if (InExpr && !Line.startsWith (tok::kw_template) &&
250
+ if (MaybeAngles && InExpr && !Line.startsWith (tok::kw_template) &&
247
251
Prev.is (TT_BinaryOperator)) {
248
252
const auto Precedence = Prev.getPrecedence ();
249
253
if (Precedence > prec::Conditional && Precedence < prec::Relational)
250
- return false ;
254
+ MaybeAngles = false ;
251
255
}
252
256
if (Prev.isOneOf (tok::question, tok::colon) && !Style .isProto ())
253
257
SeenTernaryOperator = true ;
@@ -1615,7 +1619,7 @@ class AnnotatingParser {
1615
1619
return false ;
1616
1620
break ;
1617
1621
case tok::greater:
1618
- if (Style .Language != FormatStyle::LK_TextProto)
1622
+ if (Style .Language != FormatStyle::LK_TextProto && Tok-> is (TT_Unknown) )
1619
1623
Tok->setType (TT_BinaryOperator);
1620
1624
if (Tok->Previous && Tok->Previous ->is (TT_TemplateCloser))
1621
1625
Tok->SpacesRequiredBefore = 1 ;
0 commit comments