@@ -246,30 +246,6 @@ bool Parser::isNotExpressionStart() {
246
246
return isKnownToBeDeclarationSpecifier ();
247
247
}
248
248
249
- // / We've parsed something that could plausibly be intended to be a template
250
- // / name (\p LHS) followed by a '<' token, and the following code can't possibly
251
- // / be an expression. Determine if this is likely to be a template-id and if so,
252
- // / diagnose it.
253
- bool Parser::diagnoseUnknownTemplateId (ExprResult LHS, SourceLocation Less) {
254
- TentativeParsingAction TPA (*this );
255
- // FIXME: We could look at the token sequence in a lot more detail here.
256
- if (SkipUntil (tok::greater, tok::greatergreater, tok::greatergreatergreater,
257
- StopAtSemi | StopBeforeMatch)) {
258
- TPA.Commit ();
259
-
260
- SourceLocation Greater;
261
- ParseGreaterThanInTemplateList (Greater, true , false );
262
- Actions.diagnoseExprIntendedAsTemplateName (getCurScope (), LHS,
263
- Less, Greater);
264
- return true ;
265
- }
266
-
267
- // There's no matching '>' token, this probably isn't supposed to be
268
- // interpreted as a template-id. Parse it as an (ill-formed) comparison.
269
- TPA.Revert ();
270
- return false ;
271
- }
272
-
273
249
bool Parser::isFoldOperator (prec::Level Level) const {
274
250
return Level > prec::Unknown && Level != prec::Conditional &&
275
251
Level != prec::Spaceship;
@@ -303,57 +279,12 @@ Parser::ParseRHSOfBinaryExpression(ExprResult LHS, prec::Level MinPrec) {
303
279
return ExprError (Diag (Tok, diag::err_opencl_logical_exclusive_or));
304
280
}
305
281
306
- // If we have a name-shaped expression followed by '<', track it in case we
307
- // later find we're probably supposed to be in a template-id.
308
- ExprResult TemplateName = LHS;
309
- bool DependentTemplateName = false ;
310
- if (OpToken.is (tok::less) && Actions.mightBeIntendedToBeTemplateName (
311
- TemplateName, DependentTemplateName)) {
312
- AngleBracketTracker::Priority Priority =
313
- (DependentTemplateName ? AngleBracketTracker::DependentName
314
- : AngleBracketTracker::PotentialTypo) |
315
- (OpToken.hasLeadingSpace () ? AngleBracketTracker::SpaceBeforeLess
316
- : AngleBracketTracker::NoSpaceBeforeLess);
317
- AngleBrackets.add (*this , TemplateName.get (), OpToken.getLocation (),
318
- Priority);
319
- }
320
-
321
282
// If we're potentially in a template-id, we may now be able to determine
322
283
// whether we're actually in one or not.
323
- if (auto *Info = AngleBrackets.getCurrent (*this )) {
324
- // If an operator is followed by a type that can be a template argument
325
- // and cannot be an expression, then this is ill-formed, but might be
326
- // intended to be part of a template-id. Likewise if this is <>.
327
- if ((OpToken.isOneOf (tok::less, tok::comma) &&
328
- isKnownToBeDeclarationSpecifier ()) ||
329
- (OpToken.is (tok::less) &&
330
- Tok.isOneOf (tok::greater, tok::greatergreater,
331
- tok::greatergreatergreater))) {
332
- if (diagnoseUnknownTemplateId (Info->TemplateName , Info->LessLoc )) {
333
- AngleBrackets.clear (*this );
334
- return ExprError ();
335
- }
336
- }
337
-
338
- // If a context that looks like a template-id is followed by '()', then
339
- // this is ill-formed, but might be intended to be a template-id followed
340
- // by '()'.
341
- if (OpToken.is (tok::greater) && Tok.is (tok::l_paren) &&
342
- NextToken ().is (tok::r_paren)) {
343
- Actions.diagnoseExprIntendedAsTemplateName (
344
- getCurScope (), Info->TemplateName , Info->LessLoc ,
345
- OpToken.getLocation ());
346
- AngleBrackets.clear (*this );
347
- return ExprError ();
348
- }
349
- }
350
-
351
- // After a '>' (etc), we're no longer potentially in a construct that's
352
- // intended to be treated as a template-id.
353
- if (OpToken.is (tok::greater) ||
354
- (getLangOpts ().CPlusPlus11 &&
355
- OpToken.isOneOf (tok::greatergreater, tok::greatergreatergreater)))
356
- AngleBrackets.clear (*this );
284
+ if (OpToken.isOneOf (tok::comma, tok::greater, tok::greatergreater,
285
+ tok::greatergreatergreater) &&
286
+ checkPotentialAngleBracketDelimiter (OpToken))
287
+ return ExprError ();
357
288
358
289
// Bail out when encountering a comma followed by a token which can't
359
290
// possibly be the start of an expression. For instance:
@@ -879,6 +810,8 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
879
810
assert (Res.get () == nullptr && " Stray primary-expression annotation?" );
880
811
Res = getExprAnnotation (Tok);
881
812
ConsumeAnnotationToken ();
813
+ if (!Res.isInvalid () && Tok.is (tok::less))
814
+ checkPotentialAngleBracket (Res);
882
815
break ;
883
816
884
817
case tok::kw___super:
@@ -1098,11 +1031,13 @@ ExprResult Parser::ParseCastExpression(bool isUnaryExpression,
1098
1031
isAddressOfOperand, std::move (Validator),
1099
1032
/* IsInlineAsmIdentifier=*/ false ,
1100
1033
Tok.is (tok::r_paren) ? nullptr : &Replacement);
1101
- if (!Res.isInvalid () && ! Res.get ()) {
1034
+ if (!Res.isInvalid () && Res.isUnset ()) {
1102
1035
UnconsumeToken (Replacement);
1103
1036
return ParseCastExpression (isUnaryExpression, isAddressOfOperand,
1104
1037
NotCastExpr, isTypeCast);
1105
1038
}
1039
+ if (!Res.isInvalid () && Tok.is (tok::less))
1040
+ checkPotentialAngleBracket (Res);
1106
1041
break ;
1107
1042
}
1108
1043
case tok::char_constant: // constant: character-constant
@@ -1841,6 +1776,8 @@ Parser::ParsePostfixExpressionSuffix(ExprResult LHS) {
1841
1776
OpKind, SS, TemplateKWLoc, Name,
1842
1777
CurParsedObjCImpl ? CurParsedObjCImpl->Dcl
1843
1778
: nullptr );
1779
+ if (!LHS.isInvalid () && Tok.is (tok::less))
1780
+ checkPotentialAngleBracket (LHS);
1844
1781
break ;
1845
1782
}
1846
1783
case tok::plusplus: // postfix-expression: postfix-expression '++'
@@ -2878,7 +2815,10 @@ bool Parser::ParseExpressionList(SmallVectorImpl<Expr *> &Exprs,
2878
2815
if (Tok.isNot (tok::comma))
2879
2816
break ;
2880
2817
// Move to the next argument, remember where the comma was.
2818
+ Token Comma = Tok;
2881
2819
CommaLocs.push_back (ConsumeToken ());
2820
+
2821
+ checkPotentialAngleBracketDelimiter (Comma);
2882
2822
}
2883
2823
if (SawError) {
2884
2824
// Ensure typos get diagnosed when errors were encountered while parsing the
@@ -2913,7 +2853,10 @@ Parser::ParseSimpleExpressionList(SmallVectorImpl<Expr*> &Exprs,
2913
2853
return false ;
2914
2854
2915
2855
// Move to the next argument, remember where the comma was.
2856
+ Token Comma = Tok;
2916
2857
CommaLocs.push_back (ConsumeToken ());
2858
+
2859
+ checkPotentialAngleBracketDelimiter (Comma);
2917
2860
}
2918
2861
}
2919
2862
0 commit comments