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