clang  7.0.0svn
ParseTemplate.cpp
Go to the documentation of this file.
1 //===--- ParseTemplate.cpp - Template Parsing -----------------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements parsing of C++ templates.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/DeclTemplate.h"
17 #include "clang/Parse/Parser.h"
19 #include "clang/Sema/DeclSpec.h"
21 #include "clang/Sema/Scope.h"
22 using namespace clang;
23 
24 /// \brief Parse a template declaration, explicit instantiation, or
25 /// explicit specialization.
26 Decl *
27 Parser::ParseDeclarationStartingWithTemplate(DeclaratorContext Context,
28  SourceLocation &DeclEnd,
29  AccessSpecifier AS,
30  AttributeList *AccessAttrs) {
31  ObjCDeclContextSwitch ObjCDC(*this);
32 
33  if (Tok.is(tok::kw_template) && NextToken().isNot(tok::less)) {
34  return ParseExplicitInstantiation(Context,
36  DeclEnd, AS);
37  }
38  return ParseTemplateDeclarationOrSpecialization(Context, DeclEnd, AS,
39  AccessAttrs);
40 }
41 
42 
43 
44 /// \brief Parse a template declaration or an explicit specialization.
45 ///
46 /// Template declarations include one or more template parameter lists
47 /// and either the function or class template declaration. Explicit
48 /// specializations contain one or more 'template < >' prefixes
49 /// followed by a (possibly templated) declaration. Since the
50 /// syntactic form of both features is nearly identical, we parse all
51 /// of the template headers together and let semantic analysis sort
52 /// the declarations from the explicit specializations.
53 ///
54 /// template-declaration: [C++ temp]
55 /// 'export'[opt] 'template' '<' template-parameter-list '>' declaration
56 ///
57 /// explicit-specialization: [ C++ temp.expl.spec]
58 /// 'template' '<' '>' declaration
59 Decl *
60 Parser::ParseTemplateDeclarationOrSpecialization(DeclaratorContext Context,
61  SourceLocation &DeclEnd,
62  AccessSpecifier AS,
63  AttributeList *AccessAttrs) {
64  assert(Tok.isOneOf(tok::kw_export, tok::kw_template) &&
65  "Token does not start a template declaration.");
66 
67  // Enter template-parameter scope.
68  ParseScope TemplateParmScope(this, Scope::TemplateParamScope);
69 
70  // Tell the action that names should be checked in the context of
71  // the declaration to come.
73  ParsingTemplateParams(*this, ParsingDeclRAIIObject::NoParent);
74 
75  // Parse multiple levels of template headers within this template
76  // parameter scope, e.g.,
77  //
78  // template<typename T>
79  // template<typename U>
80  // class A<T>::B { ... };
81  //
82  // We parse multiple levels non-recursively so that we can build a
83  // single data structure containing all of the template parameter
84  // lists to easily differentiate between the case above and:
85  //
86  // template<typename T>
87  // class A {
88  // template<typename U> class B;
89  // };
90  //
91  // In the first case, the action for declaring A<T>::B receives
92  // both template parameter lists. In the second case, the action for
93  // defining A<T>::B receives just the inner template parameter list
94  // (and retrieves the outer template parameter list from its
95  // context).
96  bool isSpecialization = true;
97  bool LastParamListWasEmpty = false;
98  TemplateParameterLists ParamLists;
99  TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
100 
101  do {
102  // Consume the 'export', if any.
103  SourceLocation ExportLoc;
104  TryConsumeToken(tok::kw_export, ExportLoc);
105 
106  // Consume the 'template', which should be here.
107  SourceLocation TemplateLoc;
108  if (!TryConsumeToken(tok::kw_template, TemplateLoc)) {
109  Diag(Tok.getLocation(), diag::err_expected_template);
110  return nullptr;
111  }
112 
113  // Parse the '<' template-parameter-list '>'
114  SourceLocation LAngleLoc, RAngleLoc;
115  SmallVector<NamedDecl*, 4> TemplateParams;
116  if (ParseTemplateParameters(CurTemplateDepthTracker.getDepth(),
117  TemplateParams, LAngleLoc, RAngleLoc)) {
118  // Skip until the semi-colon or a '}'.
119  SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch);
120  TryConsumeToken(tok::semi);
121  return nullptr;
122  }
123 
124  ExprResult OptionalRequiresClauseConstraintER;
125  if (!TemplateParams.empty()) {
126  isSpecialization = false;
127  ++CurTemplateDepthTracker;
128 
129  if (TryConsumeToken(tok::kw_requires)) {
130  OptionalRequiresClauseConstraintER =
132  if (!OptionalRequiresClauseConstraintER.isUsable()) {
133  // Skip until the semi-colon or a '}'.
134  SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch);
135  TryConsumeToken(tok::semi);
136  return nullptr;
137  }
138  }
139  } else {
140  LastParamListWasEmpty = true;
141  }
142 
143  ParamLists.push_back(Actions.ActOnTemplateParameterList(
144  CurTemplateDepthTracker.getDepth(), ExportLoc, TemplateLoc, LAngleLoc,
145  TemplateParams, RAngleLoc, OptionalRequiresClauseConstraintER.get()));
146  } while (Tok.isOneOf(tok::kw_export, tok::kw_template));
147 
148  unsigned NewFlags = getCurScope()->getFlags() & ~Scope::TemplateParamScope;
149  ParseScopeFlags TemplateScopeFlags(this, NewFlags, isSpecialization);
150 
151  // Parse the actual template declaration.
152  return ParseSingleDeclarationAfterTemplate(Context,
153  ParsedTemplateInfo(&ParamLists,
154  isSpecialization,
155  LastParamListWasEmpty),
156  ParsingTemplateParams,
157  DeclEnd, AS, AccessAttrs);
158 }
159 
160 /// \brief Parse a single declaration that declares a template,
161 /// template specialization, or explicit instantiation of a template.
162 ///
163 /// \param DeclEnd will receive the source location of the last token
164 /// within this declaration.
165 ///
166 /// \param AS the access specifier associated with this
167 /// declaration. Will be AS_none for namespace-scope declarations.
168 ///
169 /// \returns the new declaration.
170 Decl *
171 Parser::ParseSingleDeclarationAfterTemplate(
172  DeclaratorContext Context,
173  const ParsedTemplateInfo &TemplateInfo,
174  ParsingDeclRAIIObject &DiagsFromTParams,
175  SourceLocation &DeclEnd,
176  AccessSpecifier AS,
177  AttributeList *AccessAttrs) {
178  assert(TemplateInfo.Kind != ParsedTemplateInfo::NonTemplate &&
179  "Template information required");
180 
181  if (Tok.is(tok::kw_static_assert)) {
182  // A static_assert declaration may not be templated.
183  Diag(Tok.getLocation(), diag::err_templated_invalid_declaration)
184  << TemplateInfo.getSourceRange();
185  // Parse the static_assert declaration to improve error recovery.
186  return ParseStaticAssertDeclaration(DeclEnd);
187  }
188 
189  if (Context == DeclaratorContext::MemberContext) {
190  // We are parsing a member template.
191  ParseCXXClassMemberDeclaration(AS, AccessAttrs, TemplateInfo,
192  &DiagsFromTParams);
193  return nullptr;
194  }
195 
196  ParsedAttributesWithRange prefixAttrs(AttrFactory);
197  MaybeParseCXX11Attributes(prefixAttrs);
198 
199  if (Tok.is(tok::kw_using)) {
200  auto usingDeclPtr = ParseUsingDirectiveOrDeclaration(Context, TemplateInfo, DeclEnd,
201  prefixAttrs);
202  if (!usingDeclPtr || !usingDeclPtr.get().isSingleDecl())
203  return nullptr;
204  return usingDeclPtr.get().getSingleDecl();
205  }
206 
207  // Parse the declaration specifiers, stealing any diagnostics from
208  // the template parameters.
209  ParsingDeclSpec DS(*this, &DiagsFromTParams);
210 
211  ParseDeclarationSpecifiers(DS, TemplateInfo, AS,
212  getDeclSpecContextFromDeclaratorContext(Context));
213 
214  if (Tok.is(tok::semi)) {
215  ProhibitAttributes(prefixAttrs);
216  DeclEnd = ConsumeToken();
217  RecordDecl *AnonRecord = nullptr;
219  getCurScope(), AS, DS,
220  TemplateInfo.TemplateParams ? *TemplateInfo.TemplateParams
222  TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation,
223  AnonRecord);
224  assert(!AnonRecord &&
225  "Anonymous unions/structs should not be valid with template");
226  DS.complete(Decl);
227  return Decl;
228  }
229 
230  // Move the attributes from the prefix into the DS.
231  if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation)
232  ProhibitAttributes(prefixAttrs);
233  else
234  DS.takeAttributesFrom(prefixAttrs);
235 
236  // Parse the declarator.
237  ParsingDeclarator DeclaratorInfo(*this, DS, (DeclaratorContext)Context);
238  ParseDeclarator(DeclaratorInfo);
239  // Error parsing the declarator?
240  if (!DeclaratorInfo.hasName()) {
241  // If so, skip until the semi-colon or a }.
242  SkipUntil(tok::r_brace, StopAtSemi | StopBeforeMatch);
243  if (Tok.is(tok::semi))
244  ConsumeToken();
245  return nullptr;
246  }
247 
248  LateParsedAttrList LateParsedAttrs(true);
249  if (DeclaratorInfo.isFunctionDeclarator())
250  MaybeParseGNUAttributes(DeclaratorInfo, &LateParsedAttrs);
251 
252  if (DeclaratorInfo.isFunctionDeclarator() &&
253  isStartOfFunctionDefinition(DeclaratorInfo)) {
254 
255  // Function definitions are only allowed at file scope and in C++ classes.
256  // The C++ inline method definition case is handled elsewhere, so we only
257  // need to handle the file scope definition case.
258  if (Context != DeclaratorContext::FileContext) {
259  Diag(Tok, diag::err_function_definition_not_allowed);
261  return nullptr;
262  }
263 
264  if (DS.getStorageClassSpec() == DeclSpec::SCS_typedef) {
265  // Recover by ignoring the 'typedef'. This was probably supposed to be
266  // the 'typename' keyword, which we should have already suggested adding
267  // if it's appropriate.
268  Diag(DS.getStorageClassSpecLoc(), diag::err_function_declared_typedef)
269  << FixItHint::CreateRemoval(DS.getStorageClassSpecLoc());
270  DS.ClearStorageClassSpecs();
271  }
272 
273  if (TemplateInfo.Kind == ParsedTemplateInfo::ExplicitInstantiation) {
274  if (DeclaratorInfo.getName().getKind() !=
276  // If the declarator-id is not a template-id, issue a diagnostic and
277  // recover by ignoring the 'template' keyword.
278  Diag(Tok, diag::err_template_defn_explicit_instantiation) << 0;
279  return ParseFunctionDefinition(DeclaratorInfo, ParsedTemplateInfo(),
280  &LateParsedAttrs);
281  } else {
282  SourceLocation LAngleLoc
283  = PP.getLocForEndOfToken(TemplateInfo.TemplateLoc);
284  Diag(DeclaratorInfo.getIdentifierLoc(),
285  diag::err_explicit_instantiation_with_definition)
286  << SourceRange(TemplateInfo.TemplateLoc)
287  << FixItHint::CreateInsertion(LAngleLoc, "<>");
288 
289  // Recover as if it were an explicit specialization.
290  TemplateParameterLists FakedParamLists;
291  FakedParamLists.push_back(Actions.ActOnTemplateParameterList(
292  0, SourceLocation(), TemplateInfo.TemplateLoc, LAngleLoc, None,
293  LAngleLoc, nullptr));
294 
295  return ParseFunctionDefinition(
296  DeclaratorInfo, ParsedTemplateInfo(&FakedParamLists,
297  /*isSpecialization=*/true,
298  /*LastParamListWasEmpty=*/true),
299  &LateParsedAttrs);
300  }
301  }
302  return ParseFunctionDefinition(DeclaratorInfo, TemplateInfo,
303  &LateParsedAttrs);
304  }
305 
306  // Parse this declaration.
307  Decl *ThisDecl = ParseDeclarationAfterDeclarator(DeclaratorInfo,
308  TemplateInfo);
309 
310  if (Tok.is(tok::comma)) {
311  Diag(Tok, diag::err_multiple_template_declarators)
312  << (int)TemplateInfo.Kind;
313  SkipUntil(tok::semi);
314  return ThisDecl;
315  }
316 
317  // Eat the semi colon after the declaration.
318  ExpectAndConsumeSemi(diag::err_expected_semi_declaration);
319  if (LateParsedAttrs.size() > 0)
320  ParseLexedAttributeList(LateParsedAttrs, ThisDecl, true, false);
321  DeclaratorInfo.complete(ThisDecl);
322  return ThisDecl;
323 }
324 
325 /// ParseTemplateParameters - Parses a template-parameter-list enclosed in
326 /// angle brackets. Depth is the depth of this template-parameter-list, which
327 /// is the number of template headers directly enclosing this template header.
328 /// TemplateParams is the current list of template parameters we're building.
329 /// The template parameter we parse will be added to this list. LAngleLoc and
330 /// RAngleLoc will receive the positions of the '<' and '>', respectively,
331 /// that enclose this template parameter list.
332 ///
333 /// \returns true if an error occurred, false otherwise.
334 bool Parser::ParseTemplateParameters(
335  unsigned Depth, SmallVectorImpl<NamedDecl *> &TemplateParams,
336  SourceLocation &LAngleLoc, SourceLocation &RAngleLoc) {
337  // Get the template parameter list.
338  if (!TryConsumeToken(tok::less, LAngleLoc)) {
339  Diag(Tok.getLocation(), diag::err_expected_less_after) << "template";
340  return true;
341  }
342 
343  // Try to parse the template parameter list.
344  bool Failed = false;
345  if (!Tok.is(tok::greater) && !Tok.is(tok::greatergreater))
346  Failed = ParseTemplateParameterList(Depth, TemplateParams);
347 
348  if (Tok.is(tok::greatergreater)) {
349  // No diagnostic required here: a template-parameter-list can only be
350  // followed by a declaration or, for a template template parameter, the
351  // 'class' keyword. Therefore, the second '>' will be diagnosed later.
352  // This matters for elegant diagnosis of:
353  // template<template<typename>> struct S;
354  Tok.setKind(tok::greater);
355  RAngleLoc = Tok.getLocation();
357  } else if (!TryConsumeToken(tok::greater, RAngleLoc) && Failed) {
358  Diag(Tok.getLocation(), diag::err_expected) << tok::greater;
359  return true;
360  }
361  return false;
362 }
363 
364 /// ParseTemplateParameterList - Parse a template parameter list. If
365 /// the parsing fails badly (i.e., closing bracket was left out), this
366 /// will try to put the token stream in a reasonable position (closing
367 /// a statement, etc.) and return false.
368 ///
369 /// template-parameter-list: [C++ temp]
370 /// template-parameter
371 /// template-parameter-list ',' template-parameter
372 bool
373 Parser::ParseTemplateParameterList(const unsigned Depth,
374  SmallVectorImpl<NamedDecl*> &TemplateParams) {
375  while (1) {
376 
377  if (NamedDecl *TmpParam
378  = ParseTemplateParameter(Depth, TemplateParams.size())) {
379  TemplateParams.push_back(TmpParam);
380  } else {
381  // If we failed to parse a template parameter, skip until we find
382  // a comma or closing brace.
383  SkipUntil(tok::comma, tok::greater, tok::greatergreater,
385  }
386 
387  // Did we find a comma or the end of the template parameter list?
388  if (Tok.is(tok::comma)) {
389  ConsumeToken();
390  } else if (Tok.isOneOf(tok::greater, tok::greatergreater)) {
391  // Don't consume this... that's done by template parser.
392  break;
393  } else {
394  // Somebody probably forgot to close the template. Skip ahead and
395  // try to get out of the expression. This error is currently
396  // subsumed by whatever goes on in ParseTemplateParameter.
397  Diag(Tok.getLocation(), diag::err_expected_comma_greater);
398  SkipUntil(tok::comma, tok::greater, tok::greatergreater,
400  return false;
401  }
402  }
403  return true;
404 }
405 
406 /// \brief Determine whether the parser is at the start of a template
407 /// type parameter.
408 bool Parser::isStartOfTemplateTypeParameter() {
409  if (Tok.is(tok::kw_class)) {
410  // "class" may be the start of an elaborated-type-specifier or a
411  // type-parameter. Per C++ [temp.param]p3, we prefer the type-parameter.
412  switch (NextToken().getKind()) {
413  case tok::equal:
414  case tok::comma:
415  case tok::greater:
416  case tok::greatergreater:
417  case tok::ellipsis:
418  return true;
419 
420  case tok::identifier:
421  // This may be either a type-parameter or an elaborated-type-specifier.
422  // We have to look further.
423  break;
424 
425  default:
426  return false;
427  }
428 
429  switch (GetLookAheadToken(2).getKind()) {
430  case tok::equal:
431  case tok::comma:
432  case tok::greater:
433  case tok::greatergreater:
434  return true;
435 
436  default:
437  return false;
438  }
439  }
440 
441  if (Tok.isNot(tok::kw_typename))
442  return false;
443 
444  // C++ [temp.param]p2:
445  // There is no semantic difference between class and typename in a
446  // template-parameter. typename followed by an unqualified-id
447  // names a template type parameter. typename followed by a
448  // qualified-id denotes the type in a non-type
449  // parameter-declaration.
450  Token Next = NextToken();
451 
452  // If we have an identifier, skip over it.
453  if (Next.getKind() == tok::identifier)
454  Next = GetLookAheadToken(2);
455 
456  switch (Next.getKind()) {
457  case tok::equal:
458  case tok::comma:
459  case tok::greater:
460  case tok::greatergreater:
461  case tok::ellipsis:
462  return true;
463 
464  default:
465  return false;
466  }
467 }
468 
469 /// ParseTemplateParameter - Parse a template-parameter (C++ [temp.param]).
470 ///
471 /// template-parameter: [C++ temp.param]
472 /// type-parameter
473 /// parameter-declaration
474 ///
475 /// type-parameter: (see below)
476 /// 'class' ...[opt] identifier[opt]
477 /// 'class' identifier[opt] '=' type-id
478 /// 'typename' ...[opt] identifier[opt]
479 /// 'typename' identifier[opt] '=' type-id
480 /// 'template' '<' template-parameter-list '>'
481 /// 'class' ...[opt] identifier[opt]
482 /// 'template' '<' template-parameter-list '>' 'class' identifier[opt]
483 /// = id-expression
484 NamedDecl *Parser::ParseTemplateParameter(unsigned Depth, unsigned Position) {
485  if (isStartOfTemplateTypeParameter())
486  return ParseTypeParameter(Depth, Position);
487 
488  if (Tok.is(tok::kw_template))
489  return ParseTemplateTemplateParameter(Depth, Position);
490 
491  // Is there just a typo in the input code? ('typedef' instead of 'typename')
492  if (Tok.is(tok::kw_typedef)) {
493  Diag(Tok.getLocation(), diag::err_expected_template_parameter);
494 
495  Diag(Tok.getLocation(), diag::note_meant_to_use_typename)
497  Tok.getLocation(), Tok.getEndLoc()),
498  "typename");
499 
500  Tok.setKind(tok::kw_typename);
501 
502  return ParseTypeParameter(Depth, Position);
503  }
504 
505  // If it's none of the above, then it must be a parameter declaration.
506  // NOTE: This will pick up errors in the closure of the template parameter
507  // list (e.g., template < ; Check here to implement >> style closures.
508  return ParseNonTypeTemplateParameter(Depth, Position);
509 }
510 
511 /// ParseTypeParameter - Parse a template type parameter (C++ [temp.param]).
512 /// Other kinds of template parameters are parsed in
513 /// ParseTemplateTemplateParameter and ParseNonTypeTemplateParameter.
514 ///
515 /// type-parameter: [C++ temp.param]
516 /// 'class' ...[opt][C++0x] identifier[opt]
517 /// 'class' identifier[opt] '=' type-id
518 /// 'typename' ...[opt][C++0x] identifier[opt]
519 /// 'typename' identifier[opt] '=' type-id
520 NamedDecl *Parser::ParseTypeParameter(unsigned Depth, unsigned Position) {
521  assert(Tok.isOneOf(tok::kw_class, tok::kw_typename) &&
522  "A type-parameter starts with 'class' or 'typename'");
523 
524  // Consume the 'class' or 'typename' keyword.
525  bool TypenameKeyword = Tok.is(tok::kw_typename);
526  SourceLocation KeyLoc = ConsumeToken();
527 
528  // Grab the ellipsis (if given).
529  SourceLocation EllipsisLoc;
530  if (TryConsumeToken(tok::ellipsis, EllipsisLoc)) {
531  Diag(EllipsisLoc,
533  ? diag::warn_cxx98_compat_variadic_templates
534  : diag::ext_variadic_templates);
535  }
536 
537  // Grab the template parameter name (if given)
538  SourceLocation NameLoc;
539  IdentifierInfo *ParamName = nullptr;
540  if (Tok.is(tok::identifier)) {
541  ParamName = Tok.getIdentifierInfo();
542  NameLoc = ConsumeToken();
543  } else if (Tok.isOneOf(tok::equal, tok::comma, tok::greater,
544  tok::greatergreater)) {
545  // Unnamed template parameter. Don't have to do anything here, just
546  // don't consume this token.
547  } else {
548  Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
549  return nullptr;
550  }
551 
552  // Recover from misplaced ellipsis.
553  bool AlreadyHasEllipsis = EllipsisLoc.isValid();
554  if (TryConsumeToken(tok::ellipsis, EllipsisLoc))
555  DiagnoseMisplacedEllipsis(EllipsisLoc, NameLoc, AlreadyHasEllipsis, true);
556 
557  // Grab a default argument (if available).
558  // Per C++0x [basic.scope.pdecl]p9, we parse the default argument before
559  // we introduce the type parameter into the local scope.
560  SourceLocation EqualLoc;
561  ParsedType DefaultArg;
562  if (TryConsumeToken(tok::equal, EqualLoc))
563  DefaultArg = ParseTypeName(/*Range=*/nullptr,
565 
566  return Actions.ActOnTypeParameter(getCurScope(), TypenameKeyword, EllipsisLoc,
567  KeyLoc, ParamName, NameLoc, Depth, Position,
568  EqualLoc, DefaultArg);
569 }
570 
571 /// ParseTemplateTemplateParameter - Handle the parsing of template
572 /// template parameters.
573 ///
574 /// type-parameter: [C++ temp.param]
575 /// 'template' '<' template-parameter-list '>' type-parameter-key
576 /// ...[opt] identifier[opt]
577 /// 'template' '<' template-parameter-list '>' type-parameter-key
578 /// identifier[opt] = id-expression
579 /// type-parameter-key:
580 /// 'class'
581 /// 'typename' [C++1z]
582 NamedDecl *
583 Parser::ParseTemplateTemplateParameter(unsigned Depth, unsigned Position) {
584  assert(Tok.is(tok::kw_template) && "Expected 'template' keyword");
585 
586  // Handle the template <...> part.
587  SourceLocation TemplateLoc = ConsumeToken();
588  SmallVector<NamedDecl*,8> TemplateParams;
589  SourceLocation LAngleLoc, RAngleLoc;
590  {
591  ParseScope TemplateParmScope(this, Scope::TemplateParamScope);
592  if (ParseTemplateParameters(Depth + 1, TemplateParams, LAngleLoc,
593  RAngleLoc)) {
594  return nullptr;
595  }
596  }
597 
598  // Provide an ExtWarn if the C++1z feature of using 'typename' here is used.
599  // Generate a meaningful error if the user forgot to put class before the
600  // identifier, comma, or greater. Provide a fixit if the identifier, comma,
601  // or greater appear immediately or after 'struct'. In the latter case,
602  // replace the keyword with 'class'.
603  if (!TryConsumeToken(tok::kw_class)) {
604  bool Replace = Tok.isOneOf(tok::kw_typename, tok::kw_struct);
605  const Token &Next = Tok.is(tok::kw_struct) ? NextToken() : Tok;
606  if (Tok.is(tok::kw_typename)) {
607  Diag(Tok.getLocation(),
608  getLangOpts().CPlusPlus17
609  ? diag::warn_cxx14_compat_template_template_param_typename
610  : diag::ext_template_template_param_typename)
611  << (!getLangOpts().CPlusPlus17
612  ? FixItHint::CreateReplacement(Tok.getLocation(), "class")
613  : FixItHint());
614  } else if (Next.isOneOf(tok::identifier, tok::comma, tok::greater,
615  tok::greatergreater, tok::ellipsis)) {
616  Diag(Tok.getLocation(), diag::err_class_on_template_template_param)
617  << (Replace ? FixItHint::CreateReplacement(Tok.getLocation(), "class")
618  : FixItHint::CreateInsertion(Tok.getLocation(), "class "));
619  } else
620  Diag(Tok.getLocation(), diag::err_class_on_template_template_param);
621 
622  if (Replace)
623  ConsumeToken();
624  }
625 
626  // Parse the ellipsis, if given.
627  SourceLocation EllipsisLoc;
628  if (TryConsumeToken(tok::ellipsis, EllipsisLoc))
629  Diag(EllipsisLoc,
631  ? diag::warn_cxx98_compat_variadic_templates
632  : diag::ext_variadic_templates);
633 
634  // Get the identifier, if given.
635  SourceLocation NameLoc;
636  IdentifierInfo *ParamName = nullptr;
637  if (Tok.is(tok::identifier)) {
638  ParamName = Tok.getIdentifierInfo();
639  NameLoc = ConsumeToken();
640  } else if (Tok.isOneOf(tok::equal, tok::comma, tok::greater,
641  tok::greatergreater)) {
642  // Unnamed template parameter. Don't have to do anything here, just
643  // don't consume this token.
644  } else {
645  Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
646  return nullptr;
647  }
648 
649  // Recover from misplaced ellipsis.
650  bool AlreadyHasEllipsis = EllipsisLoc.isValid();
651  if (TryConsumeToken(tok::ellipsis, EllipsisLoc))
652  DiagnoseMisplacedEllipsis(EllipsisLoc, NameLoc, AlreadyHasEllipsis, true);
653 
654  TemplateParameterList *ParamList =
656  TemplateLoc, LAngleLoc,
657  TemplateParams,
658  RAngleLoc, nullptr);
659 
660  // Grab a default argument (if available).
661  // Per C++0x [basic.scope.pdecl]p9, we parse the default argument before
662  // we introduce the template parameter into the local scope.
663  SourceLocation EqualLoc;
664  ParsedTemplateArgument DefaultArg;
665  if (TryConsumeToken(tok::equal, EqualLoc)) {
666  DefaultArg = ParseTemplateTemplateArgument();
667  if (DefaultArg.isInvalid()) {
668  Diag(Tok.getLocation(),
669  diag::err_default_template_template_parameter_not_template);
670  SkipUntil(tok::comma, tok::greater, tok::greatergreater,
672  }
673  }
674 
675  return Actions.ActOnTemplateTemplateParameter(getCurScope(), TemplateLoc,
676  ParamList, EllipsisLoc,
677  ParamName, NameLoc, Depth,
678  Position, EqualLoc, DefaultArg);
679 }
680 
681 /// ParseNonTypeTemplateParameter - Handle the parsing of non-type
682 /// template parameters (e.g., in "template<int Size> class array;").
683 ///
684 /// template-parameter:
685 /// ...
686 /// parameter-declaration
687 NamedDecl *
688 Parser::ParseNonTypeTemplateParameter(unsigned Depth, unsigned Position) {
689  // Parse the declaration-specifiers (i.e., the type).
690  // FIXME: The type should probably be restricted in some way... Not all
691  // declarators (parts of declarators?) are accepted for parameters.
692  DeclSpec DS(AttrFactory);
693  ParseDeclarationSpecifiers(DS, ParsedTemplateInfo(), AS_none,
694  DeclSpecContext::DSC_template_param);
695 
696  // Parse this as a typename.
698  ParseDeclarator(ParamDecl);
699  if (DS.getTypeSpecType() == DeclSpec::TST_unspecified) {
700  Diag(Tok.getLocation(), diag::err_expected_template_parameter);
701  return nullptr;
702  }
703 
704  // Recover from misplaced ellipsis.
705  SourceLocation EllipsisLoc;
706  if (TryConsumeToken(tok::ellipsis, EllipsisLoc))
707  DiagnoseMisplacedEllipsisInDeclarator(EllipsisLoc, ParamDecl);
708 
709  // If there is a default value, parse it.
710  // Per C++0x [basic.scope.pdecl]p9, we parse the default argument before
711  // we introduce the template parameter into the local scope.
712  SourceLocation EqualLoc;
713  ExprResult DefaultArg;
714  if (TryConsumeToken(tok::equal, EqualLoc)) {
715  // C++ [temp.param]p15:
716  // When parsing a default template-argument for a non-type
717  // template-parameter, the first non-nested > is taken as the
718  // end of the template-parameter-list rather than a greater-than
719  // operator.
720  GreaterThanIsOperatorScope G(GreaterThanIsOperator, false);
721  EnterExpressionEvaluationContext ConstantEvaluated(
723 
725  if (DefaultArg.isInvalid())
726  SkipUntil(tok::comma, tok::greater, StopAtSemi | StopBeforeMatch);
727  }
728 
729  // Create the parameter.
730  return Actions.ActOnNonTypeTemplateParameter(getCurScope(), ParamDecl,
731  Depth, Position, EqualLoc,
732  DefaultArg.get());
733 }
734 
735 void Parser::DiagnoseMisplacedEllipsis(SourceLocation EllipsisLoc,
736  SourceLocation CorrectLoc,
737  bool AlreadyHasEllipsis,
738  bool IdentifierHasName) {
739  FixItHint Insertion;
740  if (!AlreadyHasEllipsis)
741  Insertion = FixItHint::CreateInsertion(CorrectLoc, "...");
742  Diag(EllipsisLoc, diag::err_misplaced_ellipsis_in_declaration)
743  << FixItHint::CreateRemoval(EllipsisLoc) << Insertion
744  << !IdentifierHasName;
745 }
746 
747 void Parser::DiagnoseMisplacedEllipsisInDeclarator(SourceLocation EllipsisLoc,
748  Declarator &D) {
749  assert(EllipsisLoc.isValid());
750  bool AlreadyHasEllipsis = D.getEllipsisLoc().isValid();
751  if (!AlreadyHasEllipsis)
752  D.setEllipsisLoc(EllipsisLoc);
753  DiagnoseMisplacedEllipsis(EllipsisLoc, D.getIdentifierLoc(),
754  AlreadyHasEllipsis, D.hasName());
755 }
756 
757 /// \brief Parses a '>' at the end of a template list.
758 ///
759 /// If this function encounters '>>', '>>>', '>=', or '>>=', it tries
760 /// to determine if these tokens were supposed to be a '>' followed by
761 /// '>', '>>', '>=', or '>='. It emits an appropriate diagnostic if necessary.
762 ///
763 /// \param RAngleLoc the location of the consumed '>'.
764 ///
765 /// \param ConsumeLastToken if true, the '>' is consumed.
766 ///
767 /// \param ObjCGenericList if true, this is the '>' closing an Objective-C
768 /// type parameter or type argument list, rather than a C++ template parameter
769 /// or argument list.
770 ///
771 /// \returns true, if current token does not start with '>', false otherwise.
772 bool Parser::ParseGreaterThanInTemplateList(SourceLocation &RAngleLoc,
773  bool ConsumeLastToken,
774  bool ObjCGenericList) {
775  // What will be left once we've consumed the '>'.
776  tok::TokenKind RemainingToken;
777  const char *ReplacementStr = "> >";
778 
779  switch (Tok.getKind()) {
780  default:
781  Diag(Tok.getLocation(), diag::err_expected) << tok::greater;
782  return true;
783 
784  case tok::greater:
785  // Determine the location of the '>' token. Only consume this token
786  // if the caller asked us to.
787  RAngleLoc = Tok.getLocation();
788  if (ConsumeLastToken)
789  ConsumeToken();
790  return false;
791 
792  case tok::greatergreater:
793  RemainingToken = tok::greater;
794  break;
795 
796  case tok::greatergreatergreater:
797  RemainingToken = tok::greatergreater;
798  break;
799 
800  case tok::greaterequal:
801  RemainingToken = tok::equal;
802  ReplacementStr = "> =";
803  break;
804 
805  case tok::greatergreaterequal:
806  RemainingToken = tok::greaterequal;
807  break;
808  }
809 
810  // This template-id is terminated by a token which starts with a '>'. Outside
811  // C++11, this is now error recovery, and in C++11, this is error recovery if
812  // the token isn't '>>' or '>>>'.
813  // '>>>' is for CUDA, where this sequence of characters is parsed into
814  // tok::greatergreatergreater, rather than two separate tokens.
815  //
816  // We always allow this for Objective-C type parameter and type argument
817  // lists.
818  RAngleLoc = Tok.getLocation();
819  Token Next = NextToken();
820  if (!ObjCGenericList) {
821  // The source range of the '>>' or '>=' at the start of the token.
822  CharSourceRange ReplacementRange =
825  getLangOpts()));
826 
827  // A hint to put a space between the '>>'s. In order to make the hint as
828  // clear as possible, we include the characters either side of the space in
829  // the replacement, rather than just inserting a space at SecondCharLoc.
830  FixItHint Hint1 = FixItHint::CreateReplacement(ReplacementRange,
831  ReplacementStr);
832 
833  // A hint to put another space after the token, if it would otherwise be
834  // lexed differently.
835  FixItHint Hint2;
836  if ((RemainingToken == tok::greater ||
837  RemainingToken == tok::greatergreater) &&
838  (Next.isOneOf(tok::greater, tok::greatergreater,
839  tok::greatergreatergreater, tok::equal,
840  tok::greaterequal, tok::greatergreaterequal,
841  tok::equalequal)) &&
842  areTokensAdjacent(Tok, Next))
843  Hint2 = FixItHint::CreateInsertion(Next.getLocation(), " ");
844 
845  unsigned DiagId = diag::err_two_right_angle_brackets_need_space;
846  if (getLangOpts().CPlusPlus11 &&
847  (Tok.is(tok::greatergreater) || Tok.is(tok::greatergreatergreater)))
848  DiagId = diag::warn_cxx98_compat_two_right_angle_brackets;
849  else if (Tok.is(tok::greaterequal))
850  DiagId = diag::err_right_angle_bracket_equal_needs_space;
851  Diag(Tok.getLocation(), DiagId) << Hint1 << Hint2;
852  }
853 
854  // Strip the initial '>' from the token.
855  Token PrevTok = Tok;
856  if (RemainingToken == tok::equal && Next.is(tok::equal) &&
857  areTokensAdjacent(Tok, Next)) {
858  // Join two adjacent '=' tokens into one, for cases like:
859  // void (*p)() = f<int>;
860  // return f<int>==p;
861  ConsumeToken();
862  Tok.setKind(tok::equalequal);
863  Tok.setLength(Tok.getLength() + 1);
864  } else {
865  Tok.setKind(RemainingToken);
866  Tok.setLength(Tok.getLength() - 1);
867  }
869  PP.getSourceManager(),
870  getLangOpts()));
871 
872  // The advance from '>>' to '>' in a ObjectiveC template argument list needs
873  // to be properly reflected in the token cache to allow correct interaction
874  // between annotation and backtracking.
875  if (ObjCGenericList && PrevTok.getKind() == tok::greatergreater &&
876  RemainingToken == tok::greater && PP.IsPreviousCachedToken(PrevTok)) {
877  PrevTok.setKind(RemainingToken);
878  PrevTok.setLength(1);
879  // Break tok::greatergreater into two tok::greater but only add the second
880  // one in case the client asks to consume the last token.
881  if (ConsumeLastToken)
882  PP.ReplacePreviousCachedToken({PrevTok, Tok});
883  else
884  PP.ReplacePreviousCachedToken({PrevTok});
885  }
886 
887  if (!ConsumeLastToken) {
888  // Since we're not supposed to consume the '>' token, we need to push
889  // this token and revert the current token back to the '>'.
890  PP.EnterToken(Tok);
891  Tok.setKind(tok::greater);
892  Tok.setLength(1);
893  Tok.setLocation(RAngleLoc);
894  }
895  return false;
896 }
897 
898 
899 /// \brief Parses a template-id that after the template name has
900 /// already been parsed.
901 ///
902 /// This routine takes care of parsing the enclosed template argument
903 /// list ('<' template-parameter-list [opt] '>') and placing the
904 /// results into a form that can be transferred to semantic analysis.
905 ///
906 /// \param ConsumeLastToken if true, then we will consume the last
907 /// token that forms the template-id. Otherwise, we will leave the
908 /// last token in the stream (e.g., so that it can be replaced with an
909 /// annotation token).
910 bool
911 Parser::ParseTemplateIdAfterTemplateName(bool ConsumeLastToken,
912  SourceLocation &LAngleLoc,
913  TemplateArgList &TemplateArgs,
914  SourceLocation &RAngleLoc) {
915  assert(Tok.is(tok::less) && "Must have already parsed the template-name");
916 
917  // Consume the '<'.
918  LAngleLoc = ConsumeToken();
919 
920  // Parse the optional template-argument-list.
921  bool Invalid = false;
922  {
923  GreaterThanIsOperatorScope G(GreaterThanIsOperator, false);
924  if (Tok.isNot(tok::greater) && Tok.isNot(tok::greatergreater))
925  Invalid = ParseTemplateArgumentList(TemplateArgs);
926 
927  if (Invalid) {
928  // Try to find the closing '>'.
929  if (ConsumeLastToken)
930  SkipUntil(tok::greater, StopAtSemi);
931  else
932  SkipUntil(tok::greater, StopAtSemi | StopBeforeMatch);
933  return true;
934  }
935  }
936 
937  return ParseGreaterThanInTemplateList(RAngleLoc, ConsumeLastToken,
938  /*ObjCGenericList=*/false);
939 }
940 
941 /// \brief Replace the tokens that form a simple-template-id with an
942 /// annotation token containing the complete template-id.
943 ///
944 /// The first token in the stream must be the name of a template that
945 /// is followed by a '<'. This routine will parse the complete
946 /// simple-template-id and replace the tokens with a single annotation
947 /// token with one of two different kinds: if the template-id names a
948 /// type (and \p AllowTypeAnnotation is true), the annotation token is
949 /// a type annotation that includes the optional nested-name-specifier
950 /// (\p SS). Otherwise, the annotation token is a template-id
951 /// annotation that does not include the optional
952 /// nested-name-specifier.
953 ///
954 /// \param Template the declaration of the template named by the first
955 /// token (an identifier), as returned from \c Action::isTemplateName().
956 ///
957 /// \param TNK the kind of template that \p Template
958 /// refers to, as returned from \c Action::isTemplateName().
959 ///
960 /// \param SS if non-NULL, the nested-name-specifier that precedes
961 /// this template name.
962 ///
963 /// \param TemplateKWLoc if valid, specifies that this template-id
964 /// annotation was preceded by the 'template' keyword and gives the
965 /// location of that keyword. If invalid (the default), then this
966 /// template-id was not preceded by a 'template' keyword.
967 ///
968 /// \param AllowTypeAnnotation if true (the default), then a
969 /// simple-template-id that refers to a class template, template
970 /// template parameter, or other template that produces a type will be
971 /// replaced with a type annotation token. Otherwise, the
972 /// simple-template-id is always replaced with a template-id
973 /// annotation token.
974 ///
975 /// If an unrecoverable parse error occurs and no annotation token can be
976 /// formed, this function returns true.
977 ///
978 bool Parser::AnnotateTemplateIdToken(TemplateTy Template, TemplateNameKind TNK,
979  CXXScopeSpec &SS,
980  SourceLocation TemplateKWLoc,
982  bool AllowTypeAnnotation) {
983  assert(getLangOpts().CPlusPlus && "Can only annotate template-ids in C++");
984  assert(Template && Tok.is(tok::less) &&
985  "Parser isn't at the beginning of a template-id");
986 
987  // Consume the template-name.
988  SourceLocation TemplateNameLoc = TemplateName.getSourceRange().getBegin();
989 
990  // Parse the enclosed template argument list.
991  SourceLocation LAngleLoc, RAngleLoc;
992  TemplateArgList TemplateArgs;
993  bool Invalid = ParseTemplateIdAfterTemplateName(false, LAngleLoc,
994  TemplateArgs,
995  RAngleLoc);
996 
997  if (Invalid) {
998  // If we failed to parse the template ID but skipped ahead to a >, we're not
999  // going to be able to form a token annotation. Eat the '>' if present.
1000  TryConsumeToken(tok::greater);
1001  return true;
1002  }
1003 
1004  ASTTemplateArgsPtr TemplateArgsPtr(TemplateArgs);
1005 
1006  // Build the annotation token.
1007  if (TNK == TNK_Type_template && AllowTypeAnnotation) {
1009  SS, TemplateKWLoc, Template, TemplateName.Identifier,
1010  TemplateNameLoc, LAngleLoc, TemplateArgsPtr, RAngleLoc);
1011  if (Type.isInvalid()) {
1012  // If we failed to parse the template ID but skipped ahead to a >, we're
1013  // not going to be able to form a token annotation. Eat the '>' if
1014  // present.
1015  TryConsumeToken(tok::greater);
1016  return true;
1017  }
1018 
1019  Tok.setKind(tok::annot_typename);
1020  setTypeAnnotation(Tok, Type.get());
1021  if (SS.isNotEmpty())
1022  Tok.setLocation(SS.getBeginLoc());
1023  else if (TemplateKWLoc.isValid())
1024  Tok.setLocation(TemplateKWLoc);
1025  else
1026  Tok.setLocation(TemplateNameLoc);
1027  } else {
1028  // Build a template-id annotation token that can be processed
1029  // later.
1030  Tok.setKind(tok::annot_template_id);
1031 
1032  IdentifierInfo *TemplateII =
1033  TemplateName.getKind() == UnqualifiedIdKind::IK_Identifier
1034  ? TemplateName.Identifier
1035  : nullptr;
1036 
1037  OverloadedOperatorKind OpKind =
1038  TemplateName.getKind() == UnqualifiedIdKind::IK_Identifier
1039  ? OO_None
1040  : TemplateName.OperatorFunctionId.Operator;
1041 
1043  SS, TemplateKWLoc, TemplateNameLoc, TemplateII, OpKind, Template, TNK,
1044  LAngleLoc, RAngleLoc, TemplateArgs, TemplateIds);
1045 
1046  Tok.setAnnotationValue(TemplateId);
1047  if (TemplateKWLoc.isValid())
1048  Tok.setLocation(TemplateKWLoc);
1049  else
1050  Tok.setLocation(TemplateNameLoc);
1051  }
1052 
1053  // Common fields for the annotation token
1054  Tok.setAnnotationEndLoc(RAngleLoc);
1055 
1056  // In case the tokens were cached, have Preprocessor replace them with the
1057  // annotation token.
1058  PP.AnnotateCachedTokens(Tok);
1059  return false;
1060 }
1061 
1062 /// \brief Replaces a template-id annotation token with a type
1063 /// annotation token.
1064 ///
1065 /// If there was a failure when forming the type from the template-id,
1066 /// a type annotation token will still be created, but will have a
1067 /// NULL type pointer to signify an error.
1068 ///
1069 /// \param IsClassName Is this template-id appearing in a context where we
1070 /// know it names a class, such as in an elaborated-type-specifier or
1071 /// base-specifier? ('typename' and 'template' are unneeded and disallowed
1072 /// in those contexts.)
1073 void Parser::AnnotateTemplateIdTokenAsType(bool IsClassName) {
1074  assert(Tok.is(tok::annot_template_id) && "Requires template-id tokens");
1075 
1076  TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
1077  assert((TemplateId->Kind == TNK_Type_template ||
1078  TemplateId->Kind == TNK_Dependent_template_name) &&
1079  "Only works for type and dependent templates");
1080 
1081  ASTTemplateArgsPtr TemplateArgsPtr(TemplateId->getTemplateArgs(),
1082  TemplateId->NumArgs);
1083 
1084  TypeResult Type
1085  = Actions.ActOnTemplateIdType(TemplateId->SS,
1086  TemplateId->TemplateKWLoc,
1087  TemplateId->Template,
1088  TemplateId->Name,
1089  TemplateId->TemplateNameLoc,
1090  TemplateId->LAngleLoc,
1091  TemplateArgsPtr,
1092  TemplateId->RAngleLoc,
1093  /*IsCtorOrDtorName*/false,
1094  IsClassName);
1095  // Create the new "type" annotation token.
1096  Tok.setKind(tok::annot_typename);
1097  setTypeAnnotation(Tok, Type.isInvalid() ? nullptr : Type.get());
1098  if (TemplateId->SS.isNotEmpty()) // it was a C++ qualified type name.
1099  Tok.setLocation(TemplateId->SS.getBeginLoc());
1100  // End location stays the same
1101 
1102  // Replace the template-id annotation token, and possible the scope-specifier
1103  // that precedes it, with the typename annotation token.
1104  PP.AnnotateCachedTokens(Tok);
1105 }
1106 
1107 /// \brief Determine whether the given token can end a template argument.
1108 static bool isEndOfTemplateArgument(Token Tok) {
1109  return Tok.isOneOf(tok::comma, tok::greater, tok::greatergreater);
1110 }
1111 
1112 /// \brief Parse a C++ template template argument.
1113 ParsedTemplateArgument Parser::ParseTemplateTemplateArgument() {
1114  if (!Tok.is(tok::identifier) && !Tok.is(tok::coloncolon) &&
1115  !Tok.is(tok::annot_cxxscope))
1116  return ParsedTemplateArgument();
1117 
1118  // C++0x [temp.arg.template]p1:
1119  // A template-argument for a template template-parameter shall be the name
1120  // of a class template or an alias template, expressed as id-expression.
1121  //
1122  // We parse an id-expression that refers to a class template or alias
1123  // template. The grammar we parse is:
1124  //
1125  // nested-name-specifier[opt] template[opt] identifier ...[opt]
1126  //
1127  // followed by a token that terminates a template argument, such as ',',
1128  // '>', or (in some cases) '>>'.
1129  CXXScopeSpec SS; // nested-name-specifier, if present
1130  ParseOptionalCXXScopeSpecifier(SS, nullptr,
1131  /*EnteringContext=*/false);
1132 
1134  SourceLocation EllipsisLoc;
1135  if (SS.isSet() && Tok.is(tok::kw_template)) {
1136  // Parse the optional 'template' keyword following the
1137  // nested-name-specifier.
1138  SourceLocation TemplateKWLoc = ConsumeToken();
1139 
1140  if (Tok.is(tok::identifier)) {
1141  // We appear to have a dependent template name.
1142  UnqualifiedId Name;
1143  Name.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
1144  ConsumeToken(); // the identifier
1145 
1146  TryConsumeToken(tok::ellipsis, EllipsisLoc);
1147 
1148  // If the next token signals the end of a template argument,
1149  // then we have a dependent template name that could be a template
1150  // template argument.
1151  TemplateTy Template;
1152  if (isEndOfTemplateArgument(Tok) &&
1154  getCurScope(), SS, TemplateKWLoc, Name,
1155  /*ObjectType=*/nullptr,
1156  /*EnteringContext=*/false, Template))
1157  Result = ParsedTemplateArgument(SS, Template, Name.StartLocation);
1158  }
1159  } else if (Tok.is(tok::identifier)) {
1160  // We may have a (non-dependent) template name.
1161  TemplateTy Template;
1162  UnqualifiedId Name;
1163  Name.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
1164  ConsumeToken(); // the identifier
1165 
1166  TryConsumeToken(tok::ellipsis, EllipsisLoc);
1167 
1168  if (isEndOfTemplateArgument(Tok)) {
1169  bool MemberOfUnknownSpecialization;
1170  TemplateNameKind TNK = Actions.isTemplateName(
1171  getCurScope(), SS,
1172  /*hasTemplateKeyword=*/false, Name,
1173  /*ObjectType=*/nullptr,
1174  /*EnteringContext=*/false, Template, MemberOfUnknownSpecialization);
1175  if (TNK == TNK_Dependent_template_name || TNK == TNK_Type_template) {
1176  // We have an id-expression that refers to a class template or
1177  // (C++0x) alias template.
1178  Result = ParsedTemplateArgument(SS, Template, Name.StartLocation);
1179  }
1180  }
1181  }
1182 
1183  // If this is a pack expansion, build it as such.
1184  if (EllipsisLoc.isValid() && !Result.isInvalid())
1185  Result = Actions.ActOnPackExpansion(Result, EllipsisLoc);
1186 
1187  return Result;
1188 }
1189 
1190 /// ParseTemplateArgument - Parse a C++ template argument (C++ [temp.names]).
1191 ///
1192 /// template-argument: [C++ 14.2]
1193 /// constant-expression
1194 /// type-id
1195 /// id-expression
1196 ParsedTemplateArgument Parser::ParseTemplateArgument() {
1197  // C++ [temp.arg]p2:
1198  // In a template-argument, an ambiguity between a type-id and an
1199  // expression is resolved to a type-id, regardless of the form of
1200  // the corresponding template-parameter.
1201  //
1202  // Therefore, we initially try to parse a type-id - and isCXXTypeId might look
1203  // up and annotate an identifier as an id-expression during disambiguation,
1204  // so enter the appropriate context for a constant expression template
1205  // argument before trying to disambiguate.
1206 
1207  EnterExpressionEvaluationContext EnterConstantEvaluated(
1209  if (isCXXTypeId(TypeIdAsTemplateArgument)) {
1210  TypeResult TypeArg = ParseTypeName(
1211  /*Range=*/nullptr, DeclaratorContext::TemplateArgContext);
1212  return Actions.ActOnTemplateTypeArgument(TypeArg);
1213  }
1214 
1215  // Try to parse a template template argument.
1216  {
1217  TentativeParsingAction TPA(*this);
1218 
1219  ParsedTemplateArgument TemplateTemplateArgument
1220  = ParseTemplateTemplateArgument();
1221  if (!TemplateTemplateArgument.isInvalid()) {
1222  TPA.Commit();
1223  return TemplateTemplateArgument;
1224  }
1225 
1226  // Revert this tentative parse to parse a non-type template argument.
1227  TPA.Revert();
1228  }
1229 
1230  // Parse a non-type template argument.
1231  SourceLocation Loc = Tok.getLocation();
1233  if (ExprArg.isInvalid() || !ExprArg.get())
1234  return ParsedTemplateArgument();
1235 
1237  ExprArg.get(), Loc);
1238 }
1239 
1240 /// \brief Determine whether the current tokens can only be parsed as a
1241 /// template argument list (starting with the '<') and never as a '<'
1242 /// expression.
1243 bool Parser::IsTemplateArgumentList(unsigned Skip) {
1244  struct AlwaysRevertAction : TentativeParsingAction {
1245  AlwaysRevertAction(Parser &P) : TentativeParsingAction(P) { }
1246  ~AlwaysRevertAction() { Revert(); }
1247  } Tentative(*this);
1248 
1249  while (Skip) {
1250  ConsumeAnyToken();
1251  --Skip;
1252  }
1253 
1254  // '<'
1255  if (!TryConsumeToken(tok::less))
1256  return false;
1257 
1258  // An empty template argument list.
1259  if (Tok.is(tok::greater))
1260  return true;
1261 
1262  // See whether we have declaration specifiers, which indicate a type.
1263  while (isCXXDeclarationSpecifier() == TPResult::True)
1264  ConsumeAnyToken();
1265 
1266  // If we have a '>' or a ',' then this is a template argument list.
1267  return Tok.isOneOf(tok::greater, tok::comma);
1268 }
1269 
1270 /// ParseTemplateArgumentList - Parse a C++ template-argument-list
1271 /// (C++ [temp.names]). Returns true if there was an error.
1272 ///
1273 /// template-argument-list: [C++ 14.2]
1274 /// template-argument
1275 /// template-argument-list ',' template-argument
1276 bool
1277 Parser::ParseTemplateArgumentList(TemplateArgList &TemplateArgs) {
1278 
1279  ColonProtectionRAIIObject ColonProtection(*this, false);
1280 
1281  do {
1282  ParsedTemplateArgument Arg = ParseTemplateArgument();
1283  SourceLocation EllipsisLoc;
1284  if (TryConsumeToken(tok::ellipsis, EllipsisLoc))
1285  Arg = Actions.ActOnPackExpansion(Arg, EllipsisLoc);
1286 
1287  if (Arg.isInvalid()) {
1288  SkipUntil(tok::comma, tok::greater, StopAtSemi | StopBeforeMatch);
1289  return true;
1290  }
1291 
1292  // Save this template argument.
1293  TemplateArgs.push_back(Arg);
1294 
1295  // If the next token is a comma, consume it and keep reading
1296  // arguments.
1297  } while (TryConsumeToken(tok::comma));
1298 
1299  return false;
1300 }
1301 
1302 /// \brief Parse a C++ explicit template instantiation
1303 /// (C++ [temp.explicit]).
1304 ///
1305 /// explicit-instantiation:
1306 /// 'extern' [opt] 'template' declaration
1307 ///
1308 /// Note that the 'extern' is a GNU extension and C++11 feature.
1309 Decl *Parser::ParseExplicitInstantiation(DeclaratorContext Context,
1310  SourceLocation ExternLoc,
1311  SourceLocation TemplateLoc,
1312  SourceLocation &DeclEnd,
1313  AccessSpecifier AS) {
1314  // This isn't really required here.
1316  ParsingTemplateParams(*this, ParsingDeclRAIIObject::NoParent);
1317 
1318  return ParseSingleDeclarationAfterTemplate(Context,
1319  ParsedTemplateInfo(ExternLoc,
1320  TemplateLoc),
1321  ParsingTemplateParams,
1322  DeclEnd, AS);
1323 }
1324 
1326  if (TemplateParams)
1327  return getTemplateParamsRange(TemplateParams->data(),
1328  TemplateParams->size());
1329 
1330  SourceRange R(TemplateLoc);
1331  if (ExternLoc.isValid())
1332  R.setBegin(ExternLoc);
1333  return R;
1334 }
1335 
1336 void Parser::LateTemplateParserCallback(void *P, LateParsedTemplate &LPT) {
1337  ((Parser *)P)->ParseLateTemplatedFuncDef(LPT);
1338 }
1339 
1340 /// \brief Late parse a C++ function template in Microsoft mode.
1341 void Parser::ParseLateTemplatedFuncDef(LateParsedTemplate &LPT) {
1342  if (!LPT.D)
1343  return;
1344 
1345  // Get the FunctionDecl.
1346  FunctionDecl *FunD = LPT.D->getAsFunction();
1347  // Track template parameter depth.
1348  TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
1349 
1350  // To restore the context after late parsing.
1351  Sema::ContextRAII GlobalSavedContext(
1352  Actions, Actions.Context.getTranslationUnitDecl());
1353 
1354  SmallVector<ParseScope*, 4> TemplateParamScopeStack;
1355 
1356  // Get the list of DeclContexts to reenter.
1357  SmallVector<DeclContext*, 4> DeclContextsToReenter;
1358  DeclContext *DD = FunD;
1359  while (DD && !DD->isTranslationUnit()) {
1360  DeclContextsToReenter.push_back(DD);
1361  DD = DD->getLexicalParent();
1362  }
1363 
1364  // Reenter template scopes from outermost to innermost.
1366  DeclContextsToReenter.rbegin();
1367  for (; II != DeclContextsToReenter.rend(); ++II) {
1368  TemplateParamScopeStack.push_back(new ParseScope(this,
1370  unsigned NumParamLists =
1371  Actions.ActOnReenterTemplateScope(getCurScope(), cast<Decl>(*II));
1372  CurTemplateDepthTracker.addDepth(NumParamLists);
1373  if (*II != FunD) {
1374  TemplateParamScopeStack.push_back(new ParseScope(this, Scope::DeclScope));
1375  Actions.PushDeclContext(Actions.getCurScope(), *II);
1376  }
1377  }
1378 
1379  assert(!LPT.Toks.empty() && "Empty body!");
1380 
1381  // Append the current token at the end of the new token stream so that it
1382  // doesn't get lost.
1383  LPT.Toks.push_back(Tok);
1384  PP.EnterTokenStream(LPT.Toks, true);
1385 
1386  // Consume the previously pushed token.
1387  ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true);
1388  assert(Tok.isOneOf(tok::l_brace, tok::colon, tok::kw_try) &&
1389  "Inline method not starting with '{', ':' or 'try'");
1390 
1391  // Parse the method body. Function body parsing code is similar enough
1392  // to be re-used for method bodies as well.
1393  ParseScope FnScope(this, Scope::FnScope | Scope::DeclScope |
1395 
1396  // Recreate the containing function DeclContext.
1397  Sema::ContextRAII FunctionSavedContext(Actions,
1398  Actions.getContainingDC(FunD));
1399 
1400  Actions.ActOnStartOfFunctionDef(getCurScope(), FunD);
1401 
1402  if (Tok.is(tok::kw_try)) {
1403  ParseFunctionTryBlock(LPT.D, FnScope);
1404  } else {
1405  if (Tok.is(tok::colon))
1406  ParseConstructorInitializer(LPT.D);
1407  else
1408  Actions.ActOnDefaultCtorInitializers(LPT.D);
1409 
1410  if (Tok.is(tok::l_brace)) {
1411  assert((!isa<FunctionTemplateDecl>(LPT.D) ||
1412  cast<FunctionTemplateDecl>(LPT.D)
1413  ->getTemplateParameters()
1414  ->getDepth() == TemplateParameterDepth - 1) &&
1415  "TemplateParameterDepth should be greater than the depth of "
1416  "current template being instantiated!");
1417  ParseFunctionStatementBody(LPT.D, FnScope);
1418  Actions.UnmarkAsLateParsedTemplate(FunD);
1419  } else
1420  Actions.ActOnFinishFunctionBody(LPT.D, nullptr);
1421  }
1422 
1423  // Exit scopes.
1424  FnScope.Exit();
1426  TemplateParamScopeStack.rbegin();
1427  for (; I != TemplateParamScopeStack.rend(); ++I)
1428  delete *I;
1429 }
1430 
1431 /// \brief Lex a delayed template function for late parsing.
1432 void Parser::LexTemplateFunctionForLateParsing(CachedTokens &Toks) {
1433  tok::TokenKind kind = Tok.getKind();
1434  if (!ConsumeAndStoreFunctionPrologue(Toks)) {
1435  // Consume everything up to (and including) the matching right brace.
1436  ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false);
1437  }
1438 
1439  // If we're in a function-try-block, we need to store all the catch blocks.
1440  if (kind == tok::kw_try) {
1441  while (Tok.is(tok::kw_catch)) {
1442  ConsumeAndStoreUntil(tok::l_brace, Toks, /*StopAtSemi=*/false);
1443  ConsumeAndStoreUntil(tok::r_brace, Toks, /*StopAtSemi=*/false);
1444  }
1445  }
1446 }
Defines the clang::ASTContext interface.
void ReplacePreviousCachedToken(ArrayRef< Token > NewToks)
Replace token in CachedLexPos - 1 in CachedTokens by the tokens in NewToks.
Definition: PPCaching.cpp:170
Represents a function declaration or definition.
Definition: Decl.h:1709
SourceLocation getLocWithOffset(int Offset) const
Return a source location with the specified offset from this SourceLocation.
SourceRange getSourceRange() const LLVM_READONLY
Return the source range that covers this unqualified-id.
Definition: DeclSpec.h:1111
SourceLocation StartLocation
The location of the first token that describes this unqualified-id, which will be the location of the...
Definition: DeclSpec.h:969
IdentifierInfo * Identifier
When Kind == IK_Identifier, the parsed identifier, or when Kind == IK_UserLiteralId, the identifier suffix.
Definition: DeclSpec.h:939
bool is(tok::TokenKind K) const
is/isNot - Predicates to check if this token is a specific kind, as in "if (Tok.is(tok::l_brace)) {...
Definition: Token.h:95
The name refers to a dependent template name:
Definition: TemplateKinds.h:46
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:86
RAII object used to inform the actions that we&#39;re currently parsing a declaration.
Defines the C++ template declaration subclasses.
StringRef P
The base class of the type hierarchy.
Definition: Type.h:1419
This indicates that the scope corresponds to a function, which means that labels are set here...
Definition: Scope.h:47
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Definition: Specifiers.h:95
Parser - This implements a parser for the C family of languages.
Definition: Parser.h:57
static TemplateIdAnnotation * Create(CXXScopeSpec SS, SourceLocation TemplateKWLoc, SourceLocation TemplateNameLoc, IdentifierInfo *Name, OverloadedOperatorKind OperatorKind, ParsedTemplateTy OpaqueTemplateName, TemplateNameKind TemplateKind, SourceLocation LAngleLoc, SourceLocation RAngleLoc, ArrayRef< ParsedTemplateArgument > TemplateArgs, SmallVectorImpl< TemplateIdAnnotation *> &CleanupList)
Creates a new TemplateIdAnnotation with NumArgs arguments and appends it to List. ...
RAII object that enters a new expression evaluation context.
Definition: Sema.h:10692
void EnterToken(const Token &Tok)
Enters a token in the token stream to be lexed next.
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1755
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:68
friend class ObjCDeclContextSwitch
Definition: Parser.h:61
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed...
tok::TokenKind getKind() const
Definition: Token.h:90
bool SkipUntil(tok::TokenKind T, SkipUntilFlags Flags=static_cast< SkipUntilFlags >(0))
SkipUntil - Read tokens until we get to the specified token, then consume it (unless StopBeforeMatch ...
Definition: Parser.h:949
Information about a template-id annotation token.
Represents a struct/union/class.
Definition: Decl.h:3543
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
Definition: Parser.h:617
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
bool TryConsumeToken(tok::TokenKind Expected)
Definition: Parser.h:328
One of these records is kept for each identifier that is lexed.
OverloadedOperatorKind Operator
The kind of overloaded operator.
Definition: DeclSpec.h:922
struct OFI OperatorFunctionId
When Kind == IK_OperatorFunctionId, the overloaded operator that we parsed.
Definition: DeclSpec.h:943
CachedTokens Toks
Definition: Sema.h:10747
Token - This structure provides full information about a lexed token.
Definition: Token.h:35
A non-type template parameter, stored as an expression.
void setKind(tok::TokenKind K)
Definition: Token.h:91
NamedDecl * ActOnTemplateTemplateParameter(Scope *S, SourceLocation TmpLoc, TemplateParameterList *Params, SourceLocation EllipsisLoc, IdentifierInfo *ParamName, SourceLocation ParamNameLoc, unsigned Depth, unsigned Position, SourceLocation EqualLoc, ParsedTemplateArgument DefaultArg)
ActOnTemplateTemplateParameter - Called when a C++ template template parameter (e.g.
Represents a C++ unqualified-id that has been parsed.
Definition: DeclSpec.h:911
PtrTy get() const
Definition: Ownership.h:174
ExprResult CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl=nullptr, llvm::function_ref< ExprResult(Expr *)> Filter=[](Expr *E) -> ExprResult { return E;})
Process any TypoExprs in the given Expr and its children, generating diagnostics as appropriate and r...
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
bool IsPreviousCachedToken(const Token &Tok) const
Whether Tok is the most recent token (CachedLexPos - 1) in CachedTokens.
Definition: PPCaching.cpp:152
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:63
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type...
Definition: Parser.h:348
static SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, unsigned Character, const SourceManager &SM, const LangOptions &LangOpts)
AdvanceToTokenCharacter - If the current SourceLocation specifies a location at the start of a token...
Definition: Lexer.cpp:713
The current context is "potentially evaluated" in C++11 terms, but the expression is evaluated at com...
unsigned getFlags() const
getFlags - Return the flags for this scope.
Definition: Scope.h:217
bool isOneOf(A K1, B K2) const
Definition: FormatToken.h:313
A class for parsing a declarator.
TemplateParameterList * ActOnTemplateParameterList(unsigned Depth, SourceLocation ExportLoc, SourceLocation TemplateLoc, SourceLocation LAngleLoc, ArrayRef< NamedDecl *> Params, SourceLocation RAngleLoc, Expr *RequiresClause)
ActOnTemplateParameterList - Builds a TemplateParameterList, optionally constrained by RequiresClause...
DeclContext * getLexicalParent()
getLexicalParent - Returns the containing lexical DeclContext.
Definition: DeclBase.h:1352
void setAnnotationValue(void *val)
Definition: Token.h:228
Decl * ParsedFreeStandingDeclSpec(Scope *S, AccessSpecifier AS, DeclSpec &DS, RecordDecl *&AnonRecord)
ParsedFreeStandingDeclSpec - This method is invoked when a declspec with no declarator (e...
Definition: SemaDecl.cpp:4095
Represents a character-granular source range.
void AnnotateCachedTokens(const Token &Tok)
We notify the Preprocessor that if it is caching tokens (because backtrack is enabled) it should repl...
This file defines the classes used to store parsed information about declaration-specifiers and decla...
void SkipMalformedDecl()
SkipMalformedDecl - Read tokens until we get to some likely good stopping point for skipping past a s...
Definition: ParseDecl.cpp:1842
OpaquePtr< TemplateName > TemplateTy
Definition: Parser.h:292
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file. ...
Definition: Token.h:124
SourceLocation getBeginLoc() const
Definition: DeclSpec.h:72
static bool isEndOfTemplateArgument(Token Tok)
Determine whether the given token can end a template argument.
Represents a C++ template name within the type system.
Definition: TemplateName.h:178
This is a compound statement scope.
Definition: Scope.h:130
int Depth
Definition: ASTDiff.cpp:191
UnqualifiedIdKind getKind() const
Determine what kind of name we have.
Definition: DeclSpec.h:993
TemplateNameKind
Specifies the kind of template name that an identifier refers to.
Definition: TemplateKinds.h:21
DeclaratorContext
Definition: DeclSpec.h:1713
void setEllipsisLoc(SourceLocation EL)
Definition: DeclSpec.h:2440
TemplateNameKind ActOnDependentTemplateName(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, UnqualifiedId &Name, ParsedType ObjectType, bool EnteringContext, TemplateTy &Template, bool AllowInjectedClassName=false)
Form a dependent template name.
bool isInvalid() const
Definition: Ownership.h:170
TemplateNameKind isTemplateName(Scope *S, CXXScopeSpec &SS, bool hasTemplateKeyword, UnqualifiedId &Name, ParsedType ObjectType, bool EnteringContext, TemplateTy &Template, bool &MemberOfUnknownSpecialization)
bool isUsable() const
Definition: Ownership.h:171
The result type of a method or function.
ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, SourceLocation EllipsisLoc)
Invoked when parsing a template argument followed by an ellipsis, which creates a pack expansion...
RAII object that makes &#39;>&#39; behave either as an operator or as the closing angle bracket for a templat...
const LangOptions & getLangOpts() const
Definition: Parser.h:275
static CharSourceRange getCharRange(SourceRange R)
SourceManager & getSourceManager() const
Definition: Preprocessor.h:819
A class for parsing a DeclSpec.
Stop skipping at semicolon.
Definition: Parser.h:929
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc...
Definition: Ownership.h:157
Represents the parsed form of a C++ template argument.
FunctionDecl * getAsFunction() LLVM_READONLY
Returns the function itself, or the templated function if this is a function template.
Definition: DeclBase.cpp:218
bool hasName() const
hasName - Whether this declarator has a name, which might be an identifier (accessible via getIdentif...
Definition: DeclSpec.h:2107
Encodes a location in the source.
void setLength(unsigned Len)
Definition: Token.h:133
bool is(tok::TokenKind Kind) const
Definition: FormatToken.h:304
IdentifierInfo * getIdentifierInfo() const
Definition: Token.h:177
void setAnnotationEndLoc(SourceLocation L)
Definition: Token.h:142
NamedDecl * ActOnNonTypeTemplateParameter(Scope *S, Declarator &D, unsigned Depth, unsigned Position, SourceLocation EqualLoc, Expr *DefaultArg)
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
Scope * getCurScope() const
Definition: Parser.h:282
ExprResult ParseConstantExpressionInExprEvalContext(TypeCastState isTypeCast=NotTypeCast)
Definition: ParseExpr.cpp:200
bool isNot(tok::TokenKind K) const
Definition: Token.h:96
Dataflow Directional Tag Classes.
bool isValid() const
Return true if this is a valid SourceLocation object.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1257
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:22
SourceRange getSourceRange(const SourceRange &Range)
Returns the SourceRange of a SourceRange.
Definition: FixIt.h:34
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
Definition: Diagnostic.h:118
This is a scope that corresponds to the template parameters of a C++ template.
Definition: Scope.h:77
ExprResult ParseConstraintExpression()
Parse a constraint-expression.
Definition: ParseExpr.cpp:226
bool isInvalid() const
Determine whether the given template argument is invalid.
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
Definition: Token.h:97
The name refers to a template whose specialization produces a type.
Definition: TemplateKinds.h:30
static const TST TST_unspecified
Definition: DeclSpec.h:272
unsigned getLength() const
Definition: Token.h:127
NamedDecl * ActOnTypeParameter(Scope *S, bool Typename, SourceLocation EllipsisLoc, SourceLocation KeyLoc, IdentifierInfo *ParamName, SourceLocation ParamNameLoc, unsigned Depth, unsigned Position, SourceLocation EqualLoc, ParsedType DefaultArg)
ActOnTypeParameter - Called when a C++ template type parameter (e.g., "typename T") has been parsed...
Not an overloaded operator.
Definition: OperatorKinds.h:23
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Definition: Parser.cpp:72
ParsedTemplateArgument ActOnTemplateTypeArgument(TypeResult ParsedType)
Convert a parsed type into a parsed template argument.
SourceRange getTemplateParamsRange(TemplateParameterList const *const *Params, unsigned NumParams)
Retrieves the range of the given template parameter lists.
ExprResult ParseAssignmentExpression(TypeCastState isTypeCast=NotTypeCast)
Parse an expr that doesn&#39;t include (top-level) commas.
Definition: ParseExpr.cpp:160
static FixItHint CreateInsertion(SourceLocation InsertionLoc, StringRef Code, bool BeforePreviousInsertions=false)
Create a code modification hint that inserts the given code string at a specific location.
Definition: Diagnostic.h:92
SmallVector< TemplateParameterList *, 4 > TemplateParameterLists
Definition: Parser.h:294
This is a scope that can contain a declaration.
Definition: Scope.h:59
SourceLocation getIdentifierLoc() const
Definition: DeclSpec.h:2123
bool isSet() const
Deprecated.
Definition: DeclSpec.h:209
TypeResult ActOnTemplateIdType(CXXScopeSpec &SS, SourceLocation TemplateKWLoc, TemplateTy Template, IdentifierInfo *TemplateII, SourceLocation TemplateIILoc, SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs, SourceLocation RAngleLoc, bool IsCtorOrDtorName=false, bool IsClassName=false)
Captures information about "declaration specifiers".
Definition: DeclSpec.h:228
SourceLocation ConsumeToken()
ConsumeToken - Consume the current &#39;peek token&#39; and lex the next one.
Definition: Parser.h:320
SourceLocation getEllipsisLoc() const
Definition: DeclSpec.h:2439
Decl * D
The template function declaration to be late parsed.
Definition: Sema.h:10749
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
Definition: DeclSpec.h:191
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Definition: DiagnosticIDs.h:61
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
Definition: Diagnostic.h:129
A template-id, e.g., f<int>.
Contains a late templated function.
Definition: Sema.h:10746
Annotates a diagnostic with some code that should be inserted, removed, or replaced to fix the proble...
Definition: Diagnostic.h:66
void setLocation(SourceLocation L)
Definition: Token.h:132
A trivial tuple used to represent a source range.
This represents a decl that may have a name.
Definition: Decl.h:248
void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Specify that this unqualified-id was parsed as an identifier.
Definition: DeclSpec.h:1000
bool isTranslationUnit() const
Definition: DeclBase.h:1406
SourceLocation getBegin() const
TypeResult ParseTypeName(SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeNameContext, AccessSpecifier AS=AS_none, Decl **OwnedType=nullptr, ParsedAttributes *Attrs=nullptr)
ParseTypeName type-name: [C99 6.7.6] specifier-qualifier-list abstract-declarator[opt].
Definition: ParseDecl.cpp:45
AttributeList - Represents a syntactic attribute.
Stop skipping at specified token, but don&#39;t skip the token itself.
Definition: Parser.h:931
A RAII object to temporarily push a declaration context.
Definition: Sema.h:703
SourceLocation getEndLoc() const
Definition: Token.h:151