clang  15.0.0git
ParseExprCXX.cpp
Go to the documentation of this file.
1 //===--- ParseExprCXX.cpp - C++ Expression Parsing ------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the Expression parsing implementation for C++.
10 //
11 //===----------------------------------------------------------------------===//
12 #include "clang/AST/ASTContext.h"
13 #include "clang/AST/Decl.h"
14 #include "clang/AST/DeclTemplate.h"
15 #include "clang/AST/ExprCXX.h"
19 #include "clang/Parse/Parser.h"
21 #include "clang/Sema/DeclSpec.h"
23 #include "clang/Sema/Scope.h"
24 #include "llvm/Support/ErrorHandling.h"
25 #include <numeric>
26 
27 using namespace clang;
28 
30  switch (Kind) {
31  // template name
32  case tok::unknown: return 0;
33  // casts
34  case tok::kw_addrspace_cast: return 1;
35  case tok::kw_const_cast: return 2;
36  case tok::kw_dynamic_cast: return 3;
37  case tok::kw_reinterpret_cast: return 4;
38  case tok::kw_static_cast: return 5;
39  default:
40  llvm_unreachable("Unknown type for digraph error message.");
41  }
42 }
43 
44 // Are the two tokens adjacent in the same source file?
45 bool Parser::areTokensAdjacent(const Token &First, const Token &Second) {
47  SourceLocation FirstLoc = SM.getSpellingLoc(First.getLocation());
48  SourceLocation FirstEnd = FirstLoc.getLocWithOffset(First.getLength());
49  return FirstEnd == SM.getSpellingLoc(Second.getLocation());
50 }
51 
52 // Suggest fixit for "<::" after a cast.
53 static void FixDigraph(Parser &P, Preprocessor &PP, Token &DigraphToken,
54  Token &ColonToken, tok::TokenKind Kind, bool AtDigraph) {
55  // Pull '<:' and ':' off token stream.
56  if (!AtDigraph)
57  PP.Lex(DigraphToken);
58  PP.Lex(ColonToken);
59 
60  SourceRange Range;
61  Range.setBegin(DigraphToken.getLocation());
62  Range.setEnd(ColonToken.getLocation());
63  P.Diag(DigraphToken.getLocation(), diag::err_missing_whitespace_digraph)
65  << FixItHint::CreateReplacement(Range, "< ::");
66 
67  // Update token information to reflect their change in token type.
68  ColonToken.setKind(tok::coloncolon);
69  ColonToken.setLocation(ColonToken.getLocation().getLocWithOffset(-1));
70  ColonToken.setLength(2);
71  DigraphToken.setKind(tok::less);
72  DigraphToken.setLength(1);
73 
74  // Push new tokens back to token stream.
75  PP.EnterToken(ColonToken, /*IsReinject*/ true);
76  if (!AtDigraph)
77  PP.EnterToken(DigraphToken, /*IsReinject*/ true);
78 }
79 
80 // Check for '<::' which should be '< ::' instead of '[:' when following
81 // a template name.
82 void Parser::CheckForTemplateAndDigraph(Token &Next, ParsedType ObjectType,
83  bool EnteringContext,
84  IdentifierInfo &II, CXXScopeSpec &SS) {
85  if (!Next.is(tok::l_square) || Next.getLength() != 2)
86  return;
87 
88  Token SecondToken = GetLookAheadToken(2);
89  if (!SecondToken.is(tok::colon) || !areTokensAdjacent(Next, SecondToken))
90  return;
91 
92  TemplateTy Template;
94  TemplateName.setIdentifier(&II, Tok.getLocation());
95  bool MemberOfUnknownSpecialization;
96  if (!Actions.isTemplateName(getCurScope(), SS, /*hasTemplateKeyword=*/false,
97  TemplateName, ObjectType, EnteringContext,
98  Template, MemberOfUnknownSpecialization))
99  return;
100 
101  FixDigraph(*this, PP, Next, SecondToken, tok::unknown,
102  /*AtDigraph*/false);
103 }
104 
105 /// Parse global scope or nested-name-specifier if present.
106 ///
107 /// Parses a C++ global scope specifier ('::') or nested-name-specifier (which
108 /// may be preceded by '::'). Note that this routine will not parse ::new or
109 /// ::delete; it will just leave them in the token stream.
110 ///
111 /// '::'[opt] nested-name-specifier
112 /// '::'
113 ///
114 /// nested-name-specifier:
115 /// type-name '::'
116 /// namespace-name '::'
117 /// nested-name-specifier identifier '::'
118 /// nested-name-specifier 'template'[opt] simple-template-id '::'
119 ///
120 ///
121 /// \param SS the scope specifier that will be set to the parsed
122 /// nested-name-specifier (or empty)
123 ///
124 /// \param ObjectType if this nested-name-specifier is being parsed following
125 /// the "." or "->" of a member access expression, this parameter provides the
126 /// type of the object whose members are being accessed.
127 ///
128 /// \param ObjectHadErrors if this unqualified-id occurs within a member access
129 /// expression, indicates whether the original subexpressions had any errors.
130 /// When true, diagnostics for missing 'template' keyword will be supressed.
131 ///
132 /// \param EnteringContext whether we will be entering into the context of
133 /// the nested-name-specifier after parsing it.
134 ///
135 /// \param MayBePseudoDestructor When non-NULL, points to a flag that
136 /// indicates whether this nested-name-specifier may be part of a
137 /// pseudo-destructor name. In this case, the flag will be set false
138 /// if we don't actually end up parsing a destructor name. Moreover,
139 /// if we do end up determining that we are parsing a destructor name,
140 /// the last component of the nested-name-specifier is not parsed as
141 /// part of the scope specifier.
142 ///
143 /// \param IsTypename If \c true, this nested-name-specifier is known to be
144 /// part of a type name. This is used to improve error recovery.
145 ///
146 /// \param LastII When non-NULL, points to an IdentifierInfo* that will be
147 /// filled in with the leading identifier in the last component of the
148 /// nested-name-specifier, if any.
149 ///
150 /// \param OnlyNamespace If true, only considers namespaces in lookup.
151 ///
152 ///
153 /// \returns true if there was an error parsing a scope specifier
154 bool Parser::ParseOptionalCXXScopeSpecifier(
155  CXXScopeSpec &SS, ParsedType ObjectType, bool ObjectHadErrors,
156  bool EnteringContext, bool *MayBePseudoDestructor, bool IsTypename,
157  IdentifierInfo **LastII, bool OnlyNamespace, bool InUsingDeclaration) {
158  assert(getLangOpts().CPlusPlus &&
159  "Call sites of this function should be guarded by checking for C++");
160 
161  if (Tok.is(tok::annot_cxxscope)) {
162  assert(!LastII && "want last identifier but have already annotated scope");
163  assert(!MayBePseudoDestructor && "unexpected annot_cxxscope");
165  Tok.getAnnotationRange(),
166  SS);
167  ConsumeAnnotationToken();
168  return false;
169  }
170 
171  // Has to happen before any "return false"s in this function.
172  bool CheckForDestructor = false;
173  if (MayBePseudoDestructor && *MayBePseudoDestructor) {
174  CheckForDestructor = true;
175  *MayBePseudoDestructor = false;
176  }
177 
178  if (LastII)
179  *LastII = nullptr;
180 
181  bool HasScopeSpecifier = false;
182 
183  if (Tok.is(tok::coloncolon)) {
184  // ::new and ::delete aren't nested-name-specifiers.
185  tok::TokenKind NextKind = NextToken().getKind();
186  if (NextKind == tok::kw_new || NextKind == tok::kw_delete)
187  return false;
188 
189  if (NextKind == tok::l_brace) {
190  // It is invalid to have :: {, consume the scope qualifier and pretend
191  // like we never saw it.
192  Diag(ConsumeToken(), diag::err_expected) << tok::identifier;
193  } else {
194  // '::' - Global scope qualifier.
195  if (Actions.ActOnCXXGlobalScopeSpecifier(ConsumeToken(), SS))
196  return true;
197 
198  HasScopeSpecifier = true;
199  }
200  }
201 
202  if (Tok.is(tok::kw___super)) {
203  SourceLocation SuperLoc = ConsumeToken();
204  if (!Tok.is(tok::coloncolon)) {
205  Diag(Tok.getLocation(), diag::err_expected_coloncolon_after_super);
206  return true;
207  }
208 
209  return Actions.ActOnSuperScopeSpecifier(SuperLoc, ConsumeToken(), SS);
210  }
211 
212  if (!HasScopeSpecifier &&
213  Tok.isOneOf(tok::kw_decltype, tok::annot_decltype)) {
214  DeclSpec DS(AttrFactory);
215  SourceLocation DeclLoc = Tok.getLocation();
216  SourceLocation EndLoc = ParseDecltypeSpecifier(DS);
217 
218  SourceLocation CCLoc;
219  // Work around a standard defect: 'decltype(auto)::' is not a
220  // nested-name-specifier.
221  if (DS.getTypeSpecType() == DeclSpec::TST_decltype_auto ||
222  !TryConsumeToken(tok::coloncolon, CCLoc)) {
223  AnnotateExistingDecltypeSpecifier(DS, DeclLoc, EndLoc);
224  return false;
225  }
226 
227  if (Actions.ActOnCXXNestedNameSpecifierDecltype(SS, DS, CCLoc))
228  SS.SetInvalid(SourceRange(DeclLoc, CCLoc));
229 
230  HasScopeSpecifier = true;
231  }
232 
233  // Preferred type might change when parsing qualifiers, we need the original.
234  auto SavedType = PreferredType;
235  while (true) {
236  if (HasScopeSpecifier) {
237  if (Tok.is(tok::code_completion)) {
238  cutOffParsing();
239  // Code completion for a nested-name-specifier, where the code
240  // completion token follows the '::'.
241  Actions.CodeCompleteQualifiedId(getCurScope(), SS, EnteringContext,
242  InUsingDeclaration, ObjectType.get(),
243  SavedType.get(SS.getBeginLoc()));
244  // Include code completion token into the range of the scope otherwise
245  // when we try to annotate the scope tokens the dangling code completion
246  // token will cause assertion in
247  // Preprocessor::AnnotatePreviousCachedTokens.
248  SS.setEndLoc(Tok.getLocation());
249  return true;
250  }
251 
252  // C++ [basic.lookup.classref]p5:
253  // If the qualified-id has the form
254  //
255  // ::class-name-or-namespace-name::...
256  //
257  // the class-name-or-namespace-name is looked up in global scope as a
258  // class-name or namespace-name.
259  //
260  // To implement this, we clear out the object type as soon as we've
261  // seen a leading '::' or part of a nested-name-specifier.
262  ObjectType = nullptr;
263  }
264 
265  // nested-name-specifier:
266  // nested-name-specifier 'template'[opt] simple-template-id '::'
267 
268  // Parse the optional 'template' keyword, then make sure we have
269  // 'identifier <' after it.
270  if (Tok.is(tok::kw_template)) {
271  // If we don't have a scope specifier or an object type, this isn't a
272  // nested-name-specifier, since they aren't allowed to start with
273  // 'template'.
274  if (!HasScopeSpecifier && !ObjectType)
275  break;
276 
277  TentativeParsingAction TPA(*this);
278  SourceLocation TemplateKWLoc = ConsumeToken();
279 
281  if (Tok.is(tok::identifier)) {
282  // Consume the identifier.
283  TemplateName.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
284  ConsumeToken();
285  } else if (Tok.is(tok::kw_operator)) {
286  // We don't need to actually parse the unqualified-id in this case,
287  // because a simple-template-id cannot start with 'operator', but
288  // go ahead and parse it anyway for consistency with the case where
289  // we already annotated the template-id.
290  if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
291  TemplateName)) {
292  TPA.Commit();
293  break;
294  }
295 
298  Diag(TemplateName.getSourceRange().getBegin(),
299  diag::err_id_after_template_in_nested_name_spec)
300  << TemplateName.getSourceRange();
301  TPA.Commit();
302  break;
303  }
304  } else {
305  TPA.Revert();
306  break;
307  }
308 
309  // If the next token is not '<', we have a qualified-id that refers
310  // to a template name, such as T::template apply, but is not a
311  // template-id.
312  if (Tok.isNot(tok::less)) {
313  TPA.Revert();
314  break;
315  }
316 
317  // Commit to parsing the template-id.
318  TPA.Commit();
319  TemplateTy Template;
320  TemplateNameKind TNK = Actions.ActOnTemplateName(
321  getCurScope(), SS, TemplateKWLoc, TemplateName, ObjectType,
322  EnteringContext, Template, /*AllowInjectedClassName*/ true);
323  if (AnnotateTemplateIdToken(Template, TNK, SS, TemplateKWLoc,
324  TemplateName, false))
325  return true;
326 
327  continue;
328  }
329 
330  if (Tok.is(tok::annot_template_id) && NextToken().is(tok::coloncolon)) {
331  // We have
332  //
333  // template-id '::'
334  //
335  // So we need to check whether the template-id is a simple-template-id of
336  // the right kind (it should name a type or be dependent), and then
337  // convert it into a type within the nested-name-specifier.
338  TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
339  if (CheckForDestructor && GetLookAheadToken(2).is(tok::tilde)) {
340  *MayBePseudoDestructor = true;
341  return false;
342  }
343 
344  if (LastII)
345  *LastII = TemplateId->Name;
346 
347  // Consume the template-id token.
348  ConsumeAnnotationToken();
349 
350  assert(Tok.is(tok::coloncolon) && "NextToken() not working properly!");
351  SourceLocation CCLoc = ConsumeToken();
352 
353  HasScopeSpecifier = true;
354 
355  ASTTemplateArgsPtr TemplateArgsPtr(TemplateId->getTemplateArgs(),
356  TemplateId->NumArgs);
357 
358  if (TemplateId->isInvalid() ||
360  SS,
361  TemplateId->TemplateKWLoc,
362  TemplateId->Template,
363  TemplateId->TemplateNameLoc,
364  TemplateId->LAngleLoc,
365  TemplateArgsPtr,
366  TemplateId->RAngleLoc,
367  CCLoc,
368  EnteringContext)) {
369  SourceLocation StartLoc
370  = SS.getBeginLoc().isValid()? SS.getBeginLoc()
371  : TemplateId->TemplateNameLoc;
372  SS.SetInvalid(SourceRange(StartLoc, CCLoc));
373  }
374 
375  continue;
376  }
377 
378  // The rest of the nested-name-specifier possibilities start with
379  // tok::identifier.
380  if (Tok.isNot(tok::identifier))
381  break;
382 
383  IdentifierInfo &II = *Tok.getIdentifierInfo();
384 
385  // nested-name-specifier:
386  // type-name '::'
387  // namespace-name '::'
388  // nested-name-specifier identifier '::'
389  Token Next = NextToken();
390  Sema::NestedNameSpecInfo IdInfo(&II, Tok.getLocation(), Next.getLocation(),
391  ObjectType);
392 
393  // If we get foo:bar, this is almost certainly a typo for foo::bar. Recover
394  // and emit a fixit hint for it.
395  if (Next.is(tok::colon) && !ColonIsSacred) {
396  if (Actions.IsInvalidUnlessNestedName(getCurScope(), SS, IdInfo,
397  EnteringContext) &&
398  // If the token after the colon isn't an identifier, it's still an
399  // error, but they probably meant something else strange so don't
400  // recover like this.
401  PP.LookAhead(1).is(tok::identifier)) {
402  Diag(Next, diag::err_unexpected_colon_in_nested_name_spec)
403  << FixItHint::CreateReplacement(Next.getLocation(), "::");
404  // Recover as if the user wrote '::'.
405  Next.setKind(tok::coloncolon);
406  }
407  }
408 
409  if (Next.is(tok::coloncolon) && GetLookAheadToken(2).is(tok::l_brace)) {
410  // It is invalid to have :: {, consume the scope qualifier and pretend
411  // like we never saw it.
412  Token Identifier = Tok; // Stash away the identifier.
413  ConsumeToken(); // Eat the identifier, current token is now '::'.
414  Diag(PP.getLocForEndOfToken(ConsumeToken()), diag::err_expected)
415  << tok::identifier;
416  UnconsumeToken(Identifier); // Stick the identifier back.
417  Next = NextToken(); // Point Next at the '{' token.
418  }
419 
420  if (Next.is(tok::coloncolon)) {
421  if (CheckForDestructor && GetLookAheadToken(2).is(tok::tilde)) {
422  *MayBePseudoDestructor = true;
423  return false;
424  }
425 
426  if (ColonIsSacred) {
427  const Token &Next2 = GetLookAheadToken(2);
428  if (Next2.is(tok::kw_private) || Next2.is(tok::kw_protected) ||
429  Next2.is(tok::kw_public) || Next2.is(tok::kw_virtual)) {
430  Diag(Next2, diag::err_unexpected_token_in_nested_name_spec)
431  << Next2.getName()
432  << FixItHint::CreateReplacement(Next.getLocation(), ":");
433  Token ColonColon;
434  PP.Lex(ColonColon);
435  ColonColon.setKind(tok::colon);
436  PP.EnterToken(ColonColon, /*IsReinject*/ true);
437  break;
438  }
439  }
440 
441  if (LastII)
442  *LastII = &II;
443 
444  // We have an identifier followed by a '::'. Lookup this name
445  // as the name in a nested-name-specifier.
446  Token Identifier = Tok;
447  SourceLocation IdLoc = ConsumeToken();
448  assert(Tok.isOneOf(tok::coloncolon, tok::colon) &&
449  "NextToken() not working properly!");
450  Token ColonColon = Tok;
451  SourceLocation CCLoc = ConsumeToken();
452 
453  bool IsCorrectedToColon = false;
454  bool *CorrectionFlagPtr = ColonIsSacred ? &IsCorrectedToColon : nullptr;
455  if (Actions.ActOnCXXNestedNameSpecifier(
456  getCurScope(), IdInfo, EnteringContext, SS, false,
457  CorrectionFlagPtr, OnlyNamespace)) {
458  // Identifier is not recognized as a nested name, but we can have
459  // mistyped '::' instead of ':'.
460  if (CorrectionFlagPtr && IsCorrectedToColon) {
461  ColonColon.setKind(tok::colon);
462  PP.EnterToken(Tok, /*IsReinject*/ true);
463  PP.EnterToken(ColonColon, /*IsReinject*/ true);
464  Tok = Identifier;
465  break;
466  }
467  SS.SetInvalid(SourceRange(IdLoc, CCLoc));
468  }
469  HasScopeSpecifier = true;
470  continue;
471  }
472 
473  CheckForTemplateAndDigraph(Next, ObjectType, EnteringContext, II, SS);
474 
475  // nested-name-specifier:
476  // type-name '<'
477  if (Next.is(tok::less)) {
478 
479  TemplateTy Template;
481  TemplateName.setIdentifier(&II, Tok.getLocation());
482  bool MemberOfUnknownSpecialization;
483  if (TemplateNameKind TNK = Actions.isTemplateName(getCurScope(), SS,
484  /*hasTemplateKeyword=*/false,
485  TemplateName,
486  ObjectType,
487  EnteringContext,
488  Template,
489  MemberOfUnknownSpecialization)) {
490  // If lookup didn't find anything, we treat the name as a template-name
491  // anyway. C++20 requires this, and in prior language modes it improves
492  // error recovery. But before we commit to this, check that we actually
493  // have something that looks like a template-argument-list next.
494  if (!IsTypename && TNK == TNK_Undeclared_template &&
495  isTemplateArgumentList(1) == TPResult::False)
496  break;
497 
498  // We have found a template name, so annotate this token
499  // with a template-id annotation. We do not permit the
500  // template-id to be translated into a type annotation,
501  // because some clients (e.g., the parsing of class template
502  // specializations) still want to see the original template-id
503  // token, and it might not be a type at all (e.g. a concept name in a
504  // type-constraint).
505  ConsumeToken();
506  if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(),
507  TemplateName, false))
508  return true;
509  continue;
510  }
511 
512  if (MemberOfUnknownSpecialization && (ObjectType || SS.isSet()) &&
513  (IsTypename || isTemplateArgumentList(1) == TPResult::True)) {
514  // If we had errors before, ObjectType can be dependent even without any
515  // templates. Do not report missing template keyword in that case.
516  if (!ObjectHadErrors) {
517  // We have something like t::getAs<T>, where getAs is a
518  // member of an unknown specialization. However, this will only
519  // parse correctly as a template, so suggest the keyword 'template'
520  // before 'getAs' and treat this as a dependent template name.
521  unsigned DiagID = diag::err_missing_dependent_template_keyword;
522  if (getLangOpts().MicrosoftExt)
523  DiagID = diag::warn_missing_dependent_template_keyword;
524 
525  Diag(Tok.getLocation(), DiagID)
526  << II.getName()
527  << FixItHint::CreateInsertion(Tok.getLocation(), "template ");
528  }
529 
530  SourceLocation TemplateNameLoc = ConsumeToken();
531 
532  TemplateNameKind TNK = Actions.ActOnTemplateName(
533  getCurScope(), SS, TemplateNameLoc, TemplateName, ObjectType,
534  EnteringContext, Template, /*AllowInjectedClassName*/ true);
535  if (AnnotateTemplateIdToken(Template, TNK, SS, SourceLocation(),
536  TemplateName, false))
537  return true;
538 
539  continue;
540  }
541  }
542 
543  // We don't have any tokens that form the beginning of a
544  // nested-name-specifier, so we're done.
545  break;
546  }
547 
548  // Even if we didn't see any pieces of a nested-name-specifier, we
549  // still check whether there is a tilde in this position, which
550  // indicates a potential pseudo-destructor.
551  if (CheckForDestructor && !HasScopeSpecifier && Tok.is(tok::tilde))
552  *MayBePseudoDestructor = true;
553 
554  return false;
555 }
556 
557 ExprResult Parser::tryParseCXXIdExpression(CXXScopeSpec &SS,
558  bool isAddressOfOperand,
559  Token &Replacement) {
560  ExprResult E;
561 
562  // We may have already annotated this id-expression.
563  switch (Tok.getKind()) {
564  case tok::annot_non_type: {
565  NamedDecl *ND = getNonTypeAnnotation(Tok);
566  SourceLocation Loc = ConsumeAnnotationToken();
567  E = Actions.ActOnNameClassifiedAsNonType(getCurScope(), SS, ND, Loc, Tok);
568  break;
569  }
570 
571  case tok::annot_non_type_dependent: {
572  IdentifierInfo *II = getIdentifierAnnotation(Tok);
573  SourceLocation Loc = ConsumeAnnotationToken();
574 
575  // This is only the direct operand of an & operator if it is not
576  // followed by a postfix-expression suffix.
577  if (isAddressOfOperand && isPostfixExpressionSuffixStart())
578  isAddressOfOperand = false;
579 
580  E = Actions.ActOnNameClassifiedAsDependentNonType(SS, II, Loc,
581  isAddressOfOperand);
582  break;
583  }
584 
585  case tok::annot_non_type_undeclared: {
586  assert(SS.isEmpty() &&
587  "undeclared non-type annotation should be unqualified");
588  IdentifierInfo *II = getIdentifierAnnotation(Tok);
589  SourceLocation Loc = ConsumeAnnotationToken();
590  E = Actions.ActOnNameClassifiedAsUndeclaredNonType(II, Loc);
591  break;
592  }
593 
594  default:
595  SourceLocation TemplateKWLoc;
596  UnqualifiedId Name;
597  if (ParseUnqualifiedId(SS, /*ObjectType=*/nullptr,
598  /*ObjectHadErrors=*/false,
599  /*EnteringContext=*/false,
600  /*AllowDestructorName=*/false,
601  /*AllowConstructorName=*/false,
602  /*AllowDeductionGuide=*/false, &TemplateKWLoc, Name))
603  return ExprError();
604 
605  // This is only the direct operand of an & operator if it is not
606  // followed by a postfix-expression suffix.
607  if (isAddressOfOperand && isPostfixExpressionSuffixStart())
608  isAddressOfOperand = false;
609 
610  E = Actions.ActOnIdExpression(
611  getCurScope(), SS, TemplateKWLoc, Name, Tok.is(tok::l_paren),
612  isAddressOfOperand, /*CCC=*/nullptr, /*IsInlineAsmIdentifier=*/false,
613  &Replacement);
614  break;
615  }
616 
617  if (!E.isInvalid() && !E.isUnset() && Tok.is(tok::less))
618  checkPotentialAngleBracket(E);
619  return E;
620 }
621 
622 /// ParseCXXIdExpression - Handle id-expression.
623 ///
624 /// id-expression:
625 /// unqualified-id
626 /// qualified-id
627 ///
628 /// qualified-id:
629 /// '::'[opt] nested-name-specifier 'template'[opt] unqualified-id
630 /// '::' identifier
631 /// '::' operator-function-id
632 /// '::' template-id
633 ///
634 /// NOTE: The standard specifies that, for qualified-id, the parser does not
635 /// expect:
636 ///
637 /// '::' conversion-function-id
638 /// '::' '~' class-name
639 ///
640 /// This may cause a slight inconsistency on diagnostics:
641 ///
642 /// class C {};
643 /// namespace A {}
644 /// void f() {
645 /// :: A :: ~ C(); // Some Sema error about using destructor with a
646 /// // namespace.
647 /// :: ~ C(); // Some Parser error like 'unexpected ~'.
648 /// }
649 ///
650 /// We simplify the parser a bit and make it work like:
651 ///
652 /// qualified-id:
653 /// '::'[opt] nested-name-specifier 'template'[opt] unqualified-id
654 /// '::' unqualified-id
655 ///
656 /// That way Sema can handle and report similar errors for namespaces and the
657 /// global scope.
658 ///
659 /// The isAddressOfOperand parameter indicates that this id-expression is a
660 /// direct operand of the address-of operator. This is, besides member contexts,
661 /// the only place where a qualified-id naming a non-static class member may
662 /// appear.
663 ///
664 ExprResult Parser::ParseCXXIdExpression(bool isAddressOfOperand) {
665  // qualified-id:
666  // '::'[opt] nested-name-specifier 'template'[opt] unqualified-id
667  // '::' unqualified-id
668  //
669  CXXScopeSpec SS;
670  ParseOptionalCXXScopeSpecifier(SS, /*ObjectType=*/nullptr,
671  /*ObjectHasErrors=*/false,
672  /*EnteringContext=*/false);
673 
674  Token Replacement;
675  ExprResult Result =
676  tryParseCXXIdExpression(SS, isAddressOfOperand, Replacement);
677  if (Result.isUnset()) {
678  // If the ExprResult is valid but null, then typo correction suggested a
679  // keyword replacement that needs to be reparsed.
680  UnconsumeToken(Replacement);
681  Result = tryParseCXXIdExpression(SS, isAddressOfOperand, Replacement);
682  }
683  assert(!Result.isUnset() && "Typo correction suggested a keyword replacement "
684  "for a previous keyword suggestion");
685  return Result;
686 }
687 
688 /// ParseLambdaExpression - Parse a C++11 lambda expression.
689 ///
690 /// lambda-expression:
691 /// lambda-introducer lambda-declarator compound-statement
692 /// lambda-introducer '<' template-parameter-list '>'
693 /// requires-clause[opt] lambda-declarator compound-statement
694 ///
695 /// lambda-introducer:
696 /// '[' lambda-capture[opt] ']'
697 ///
698 /// lambda-capture:
699 /// capture-default
700 /// capture-list
701 /// capture-default ',' capture-list
702 ///
703 /// capture-default:
704 /// '&'
705 /// '='
706 ///
707 /// capture-list:
708 /// capture
709 /// capture-list ',' capture
710 ///
711 /// capture:
712 /// simple-capture
713 /// init-capture [C++1y]
714 ///
715 /// simple-capture:
716 /// identifier
717 /// '&' identifier
718 /// 'this'
719 ///
720 /// init-capture: [C++1y]
721 /// identifier initializer
722 /// '&' identifier initializer
723 ///
724 /// lambda-declarator:
725 /// lambda-specifiers [C++2b]
726 /// '(' parameter-declaration-clause ')' lambda-specifiers
727 /// requires-clause[opt]
728 ///
729 /// lambda-specifiers:
730 /// decl-specifier-seq[opt] noexcept-specifier[opt]
731 /// attribute-specifier-seq[opt] trailing-return-type[opt]
732 ///
733 ExprResult Parser::ParseLambdaExpression() {
734  // Parse lambda-introducer.
735  LambdaIntroducer Intro;
736  if (ParseLambdaIntroducer(Intro)) {
737  SkipUntil(tok::r_square, StopAtSemi);
738  SkipUntil(tok::l_brace, StopAtSemi);
739  SkipUntil(tok::r_brace, StopAtSemi);
740  return ExprError();
741  }
742 
743  return ParseLambdaExpressionAfterIntroducer(Intro);
744 }
745 
746 /// Use lookahead and potentially tentative parsing to determine if we are
747 /// looking at a C++11 lambda expression, and parse it if we are.
748 ///
749 /// If we are not looking at a lambda expression, returns ExprError().
750 ExprResult Parser::TryParseLambdaExpression() {
751  assert(getLangOpts().CPlusPlus11
752  && Tok.is(tok::l_square)
753  && "Not at the start of a possible lambda expression.");
754 
755  const Token Next = NextToken();
756  if (Next.is(tok::eof)) // Nothing else to lookup here...
757  return ExprEmpty();
758 
759  const Token After = GetLookAheadToken(2);
760  // If lookahead indicates this is a lambda...
761  if (Next.is(tok::r_square) || // []
762  Next.is(tok::equal) || // [=
763  (Next.is(tok::amp) && // [&] or [&,
764  After.isOneOf(tok::r_square, tok::comma)) ||
765  (Next.is(tok::identifier) && // [identifier]
766  After.is(tok::r_square)) ||
767  Next.is(tok::ellipsis)) { // [...
768  return ParseLambdaExpression();
769  }
770 
771  // If lookahead indicates an ObjC message send...
772  // [identifier identifier
773  if (Next.is(tok::identifier) && After.is(tok::identifier))
774  return ExprEmpty();
775 
776  // Here, we're stuck: lambda introducers and Objective-C message sends are
777  // unambiguous, but it requires arbitrary lookhead. [a,b,c,d,e,f,g] is a
778  // lambda, and [a,b,c,d,e,f,g h] is a Objective-C message send. Instead of
779  // writing two routines to parse a lambda introducer, just try to parse
780  // a lambda introducer first, and fall back if that fails.
781  LambdaIntroducer Intro;
782  {
783  TentativeParsingAction TPA(*this);
784  LambdaIntroducerTentativeParse Tentative;
785  if (ParseLambdaIntroducer(Intro, &Tentative)) {
786  TPA.Commit();
787  return ExprError();
788  }
789 
790  switch (Tentative) {
791  case LambdaIntroducerTentativeParse::Success:
792  TPA.Commit();
793  break;
794 
795  case LambdaIntroducerTentativeParse::Incomplete:
796  // Didn't fully parse the lambda-introducer, try again with a
797  // non-tentative parse.
798  TPA.Revert();
799  Intro = LambdaIntroducer();
800  if (ParseLambdaIntroducer(Intro))
801  return ExprError();
802  break;
803 
804  case LambdaIntroducerTentativeParse::MessageSend:
805  case LambdaIntroducerTentativeParse::Invalid:
806  // Not a lambda-introducer, might be a message send.
807  TPA.Revert();
808  return ExprEmpty();
809  }
810  }
811 
812  return ParseLambdaExpressionAfterIntroducer(Intro);
813 }
814 
815 /// Parse a lambda introducer.
816 /// \param Intro A LambdaIntroducer filled in with information about the
817 /// contents of the lambda-introducer.
818 /// \param Tentative If non-null, we are disambiguating between a
819 /// lambda-introducer and some other construct. In this mode, we do not
820 /// produce any diagnostics or take any other irreversible action unless
821 /// we're sure that this is a lambda-expression.
822 /// \return \c true if parsing (or disambiguation) failed with a diagnostic and
823 /// the caller should bail out / recover.
824 bool Parser::ParseLambdaIntroducer(LambdaIntroducer &Intro,
825  LambdaIntroducerTentativeParse *Tentative) {
826  if (Tentative)
827  *Tentative = LambdaIntroducerTentativeParse::Success;
828 
829  assert(Tok.is(tok::l_square) && "Lambda expressions begin with '['.");
830  BalancedDelimiterTracker T(*this, tok::l_square);
831  T.consumeOpen();
832 
833  Intro.Range.setBegin(T.getOpenLocation());
834 
835  bool First = true;
836 
837  // Produce a diagnostic if we're not tentatively parsing; otherwise track
838  // that our parse has failed.
839  auto Invalid = [&](llvm::function_ref<void()> Action) {
840  if (Tentative) {
841  *Tentative = LambdaIntroducerTentativeParse::Invalid;
842  return false;
843  }
844  Action();
845  return true;
846  };
847 
848  // Perform some irreversible action if this is a non-tentative parse;
849  // otherwise note that our actions were incomplete.
850  auto NonTentativeAction = [&](llvm::function_ref<void()> Action) {
851  if (Tentative)
852  *Tentative = LambdaIntroducerTentativeParse::Incomplete;
853  else
854  Action();
855  };
856 
857  // Parse capture-default.
858  if (Tok.is(tok::amp) &&
859  (NextToken().is(tok::comma) || NextToken().is(tok::r_square))) {
860  Intro.Default = LCD_ByRef;
861  Intro.DefaultLoc = ConsumeToken();
862  First = false;
863  if (!Tok.getIdentifierInfo()) {
864  // This can only be a lambda; no need for tentative parsing any more.
865  // '[[and]]' can still be an attribute, though.
866  Tentative = nullptr;
867  }
868  } else if (Tok.is(tok::equal)) {
869  Intro.Default = LCD_ByCopy;
870  Intro.DefaultLoc = ConsumeToken();
871  First = false;
872  Tentative = nullptr;
873  }
874 
875  while (Tok.isNot(tok::r_square)) {
876  if (!First) {
877  if (Tok.isNot(tok::comma)) {
878  // Provide a completion for a lambda introducer here. Except
879  // in Objective-C, where this is Almost Surely meant to be a message
880  // send. In that case, fail here and let the ObjC message
881  // expression parser perform the completion.
882  if (Tok.is(tok::code_completion) &&
883  !(getLangOpts().ObjC && Tentative)) {
884  cutOffParsing();
885  Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro,
886  /*AfterAmpersand=*/false);
887  break;
888  }
889 
890  return Invalid([&] {
891  Diag(Tok.getLocation(), diag::err_expected_comma_or_rsquare);
892  });
893  }
894  ConsumeToken();
895  }
896 
897  if (Tok.is(tok::code_completion)) {
898  cutOffParsing();
899  // If we're in Objective-C++ and we have a bare '[', then this is more
900  // likely to be a message receiver.
901  if (getLangOpts().ObjC && Tentative && First)
903  else
904  Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro,
905  /*AfterAmpersand=*/false);
906  break;
907  }
908 
909  First = false;
910 
911  // Parse capture.
914  SourceLocation Loc;
915  IdentifierInfo *Id = nullptr;
916  SourceLocation EllipsisLocs[4];
917  ExprResult Init;
918  SourceLocation LocStart = Tok.getLocation();
919 
920  if (Tok.is(tok::star)) {
921  Loc = ConsumeToken();
922  if (Tok.is(tok::kw_this)) {
923  ConsumeToken();
924  Kind = LCK_StarThis;
925  } else {
926  return Invalid([&] {
927  Diag(Tok.getLocation(), diag::err_expected_star_this_capture);
928  });
929  }
930  } else if (Tok.is(tok::kw_this)) {
931  Kind = LCK_This;
932  Loc = ConsumeToken();
933  } else if (Tok.isOneOf(tok::amp, tok::equal) &&
934  NextToken().isOneOf(tok::comma, tok::r_square) &&
935  Intro.Default == LCD_None) {
936  // We have a lone "&" or "=" which is either a misplaced capture-default
937  // or the start of a capture (in the "&" case) with the rest of the
938  // capture missing. Both are an error but a misplaced capture-default
939  // is more likely if we don't already have a capture default.
940  return Invalid(
941  [&] { Diag(Tok.getLocation(), diag::err_capture_default_first); });
942  } else {
943  TryConsumeToken(tok::ellipsis, EllipsisLocs[0]);
944 
945  if (Tok.is(tok::amp)) {
946  Kind = LCK_ByRef;
947  ConsumeToken();
948 
949  if (Tok.is(tok::code_completion)) {
950  cutOffParsing();
951  Actions.CodeCompleteLambdaIntroducer(getCurScope(), Intro,
952  /*AfterAmpersand=*/true);
953  break;
954  }
955  }
956 
957  TryConsumeToken(tok::ellipsis, EllipsisLocs[1]);
958 
959  if (Tok.is(tok::identifier)) {
960  Id = Tok.getIdentifierInfo();
961  Loc = ConsumeToken();
962  } else if (Tok.is(tok::kw_this)) {
963  return Invalid([&] {
964  // FIXME: Suggest a fixit here.
965  Diag(Tok.getLocation(), diag::err_this_captured_by_reference);
966  });
967  } else {
968  return Invalid([&] {
969  Diag(Tok.getLocation(), diag::err_expected_capture);
970  });
971  }
972 
973  TryConsumeToken(tok::ellipsis, EllipsisLocs[2]);
974 
975  if (Tok.is(tok::l_paren)) {
976  BalancedDelimiterTracker Parens(*this, tok::l_paren);
977  Parens.consumeOpen();
978 
980 
981  ExprVector Exprs;
982  CommaLocsTy Commas;
983  if (Tentative) {
984  Parens.skipToEnd();
985  *Tentative = LambdaIntroducerTentativeParse::Incomplete;
986  } else if (ParseExpressionList(Exprs, Commas)) {
987  Parens.skipToEnd();
988  Init = ExprError();
989  } else {
990  Parens.consumeClose();
991  Init = Actions.ActOnParenListExpr(Parens.getOpenLocation(),
992  Parens.getCloseLocation(),
993  Exprs);
994  }
995  } else if (Tok.isOneOf(tok::l_brace, tok::equal)) {
996  // Each lambda init-capture forms its own full expression, which clears
997  // Actions.MaybeODRUseExprs. So create an expression evaluation context
998  // to save the necessary state, and restore it later.
1001 
1002  if (TryConsumeToken(tok::equal))
1004  else
1006 
1007  if (!Tentative) {
1008  Init = ParseInitializer();
1009  } else if (Tok.is(tok::l_brace)) {
1010  BalancedDelimiterTracker Braces(*this, tok::l_brace);
1011  Braces.consumeOpen();
1012  Braces.skipToEnd();
1013  *Tentative = LambdaIntroducerTentativeParse::Incomplete;
1014  } else {
1015  // We're disambiguating this:
1016  //
1017  // [..., x = expr
1018  //
1019  // We need to find the end of the following expression in order to
1020  // determine whether this is an Obj-C message send's receiver, a
1021  // C99 designator, or a lambda init-capture.
1022  //
1023  // Parse the expression to find where it ends, and annotate it back
1024  // onto the tokens. We would have parsed this expression the same way
1025  // in either case: both the RHS of an init-capture and the RHS of an
1026  // assignment expression are parsed as an initializer-clause, and in
1027  // neither case can anything be added to the scope between the '[' and
1028  // here.
1029  //
1030  // FIXME: This is horrible. Adding a mechanism to skip an expression
1031  // would be much cleaner.
1032  // FIXME: If there is a ',' before the next ']' or ':', we can skip to
1033  // that instead. (And if we see a ':' with no matching '?', we can
1034  // classify this as an Obj-C message send.)
1035  SourceLocation StartLoc = Tok.getLocation();
1036  InMessageExpressionRAIIObject MaybeInMessageExpression(*this, true);
1037  Init = ParseInitializer();
1038  if (!Init.isInvalid())
1039  Init = Actions.CorrectDelayedTyposInExpr(Init.get());
1040 
1041  if (Tok.getLocation() != StartLoc) {
1042  // Back out the lexing of the token after the initializer.
1043  PP.RevertCachedTokens(1);
1044 
1045  // Replace the consumed tokens with an appropriate annotation.
1046  Tok.setLocation(StartLoc);
1047  Tok.setKind(tok::annot_primary_expr);
1048  setExprAnnotation(Tok, Init);
1050  PP.AnnotateCachedTokens(Tok);
1051 
1052  // Consume the annotated initializer.
1053  ConsumeAnnotationToken();
1054  }
1055  }
1056  }
1057 
1058  TryConsumeToken(tok::ellipsis, EllipsisLocs[3]);
1059  }
1060 
1061  // Check if this is a message send before we act on a possible init-capture.
1062  if (Tentative && Tok.is(tok::identifier) &&
1063  NextToken().isOneOf(tok::colon, tok::r_square)) {
1064  // This can only be a message send. We're done with disambiguation.
1065  *Tentative = LambdaIntroducerTentativeParse::MessageSend;
1066  return false;
1067  }
1068 
1069  // Ensure that any ellipsis was in the right place.
1070  SourceLocation EllipsisLoc;
1071  if (llvm::any_of(EllipsisLocs,
1072  [](SourceLocation Loc) { return Loc.isValid(); })) {
1073  // The '...' should appear before the identifier in an init-capture, and
1074  // after the identifier otherwise.
1075  bool InitCapture = InitKind != LambdaCaptureInitKind::NoInit;
1076  SourceLocation *ExpectedEllipsisLoc =
1077  !InitCapture ? &EllipsisLocs[2] :
1078  Kind == LCK_ByRef ? &EllipsisLocs[1] :
1079  &EllipsisLocs[0];
1080  EllipsisLoc = *ExpectedEllipsisLoc;
1081 
1082  unsigned DiagID = 0;
1083  if (EllipsisLoc.isInvalid()) {
1084  DiagID = diag::err_lambda_capture_misplaced_ellipsis;
1085  for (SourceLocation Loc : EllipsisLocs) {
1086  if (Loc.isValid())
1087  EllipsisLoc = Loc;
1088  }
1089  } else {
1090  unsigned NumEllipses = std::accumulate(
1091  std::begin(EllipsisLocs), std::end(EllipsisLocs), 0,
1092  [](int N, SourceLocation Loc) { return N + Loc.isValid(); });
1093  if (NumEllipses > 1)
1094  DiagID = diag::err_lambda_capture_multiple_ellipses;
1095  }
1096  if (DiagID) {
1097  NonTentativeAction([&] {
1098  // Point the diagnostic at the first misplaced ellipsis.
1099  SourceLocation DiagLoc;
1100  for (SourceLocation &Loc : EllipsisLocs) {
1101  if (&Loc != ExpectedEllipsisLoc && Loc.isValid()) {
1102  DiagLoc = Loc;
1103  break;
1104  }
1105  }
1106  assert(DiagLoc.isValid() && "no location for diagnostic");
1107 
1108  // Issue the diagnostic and produce fixits showing where the ellipsis
1109  // should have been written.
1110  auto &&D = Diag(DiagLoc, DiagID);
1111  if (DiagID == diag::err_lambda_capture_misplaced_ellipsis) {
1112  SourceLocation ExpectedLoc =
1113  InitCapture ? Loc
1115  Loc, 0, PP.getSourceManager(), getLangOpts());
1116  D << InitCapture << FixItHint::CreateInsertion(ExpectedLoc, "...");
1117  }
1118  for (SourceLocation &Loc : EllipsisLocs) {
1119  if (&Loc != ExpectedEllipsisLoc && Loc.isValid())
1120  D << FixItHint::CreateRemoval(Loc);
1121  }
1122  });
1123  }
1124  }
1125 
1126  // Process the init-capture initializers now rather than delaying until we
1127  // form the lambda-expression so that they can be handled in the context
1128  // enclosing the lambda-expression, rather than in the context of the
1129  // lambda-expression itself.
1130  ParsedType InitCaptureType;
1131  if (Init.isUsable())
1132  Init = Actions.CorrectDelayedTyposInExpr(Init.get());
1133  if (Init.isUsable()) {
1134  NonTentativeAction([&] {
1135  // Get the pointer and store it in an lvalue, so we can use it as an
1136  // out argument.
1137  Expr *InitExpr = Init.get();
1138  // This performs any lvalue-to-rvalue conversions if necessary, which
1139  // can affect what gets captured in the containing decl-context.
1140  InitCaptureType = Actions.actOnLambdaInitCaptureInitialization(
1141  Loc, Kind == LCK_ByRef, EllipsisLoc, Id, InitKind, InitExpr);
1142  Init = InitExpr;
1143  });
1144  }
1145 
1146  SourceLocation LocEnd = PrevTokLocation;
1147 
1148  Intro.addCapture(Kind, Loc, Id, EllipsisLoc, InitKind, Init,
1149  InitCaptureType, SourceRange(LocStart, LocEnd));
1150  }
1151 
1152  T.consumeClose();
1153  Intro.Range.setEnd(T.getCloseLocation());
1154  return false;
1155 }
1156 
1158  SourceLocation &MutableLoc,
1159  SourceLocation &ConstexprLoc,
1160  SourceLocation &ConstevalLoc,
1161  SourceLocation &DeclEndLoc) {
1162  assert(MutableLoc.isInvalid());
1163  assert(ConstexprLoc.isInvalid());
1164  // Consume constexpr-opt mutable-opt in any sequence, and set the DeclEndLoc
1165  // to the final of those locations. Emit an error if we have multiple
1166  // copies of those keywords and recover.
1167 
1168  while (true) {
1169  switch (P.getCurToken().getKind()) {
1170  case tok::kw_mutable: {
1171  if (MutableLoc.isValid()) {
1172  P.Diag(P.getCurToken().getLocation(),
1173  diag::err_lambda_decl_specifier_repeated)
1174  << 0 << FixItHint::CreateRemoval(P.getCurToken().getLocation());
1175  }
1176  MutableLoc = P.ConsumeToken();
1177  DeclEndLoc = MutableLoc;
1178  break /*switch*/;
1179  }
1180  case tok::kw_constexpr:
1181  if (ConstexprLoc.isValid()) {
1182  P.Diag(P.getCurToken().getLocation(),
1183  diag::err_lambda_decl_specifier_repeated)
1184  << 1 << FixItHint::CreateRemoval(P.getCurToken().getLocation());
1185  }
1186  ConstexprLoc = P.ConsumeToken();
1187  DeclEndLoc = ConstexprLoc;
1188  break /*switch*/;
1189  case tok::kw_consteval:
1190  if (ConstevalLoc.isValid()) {
1191  P.Diag(P.getCurToken().getLocation(),
1192  diag::err_lambda_decl_specifier_repeated)
1193  << 2 << FixItHint::CreateRemoval(P.getCurToken().getLocation());
1194  }
1195  ConstevalLoc = P.ConsumeToken();
1196  DeclEndLoc = ConstevalLoc;
1197  break /*switch*/;
1198  default:
1199  return;
1200  }
1201  }
1202 }
1203 
1204 static void
1206  DeclSpec &DS) {
1207  if (ConstexprLoc.isValid()) {
1208  P.Diag(ConstexprLoc, !P.getLangOpts().CPlusPlus17
1209  ? diag::ext_constexpr_on_lambda_cxx17
1210  : diag::warn_cxx14_compat_constexpr_on_lambda);
1211  const char *PrevSpec = nullptr;
1212  unsigned DiagID = 0;
1213  DS.SetConstexprSpec(ConstexprSpecKind::Constexpr, ConstexprLoc, PrevSpec,
1214  DiagID);
1215  assert(PrevSpec == nullptr && DiagID == 0 &&
1216  "Constexpr cannot have been set previously!");
1217  }
1218 }
1219 
1221  SourceLocation ConstevalLoc,
1222  DeclSpec &DS) {
1223  if (ConstevalLoc.isValid()) {
1224  P.Diag(ConstevalLoc, diag::warn_cxx20_compat_consteval);
1225  const char *PrevSpec = nullptr;
1226  unsigned DiagID = 0;
1227  DS.SetConstexprSpec(ConstexprSpecKind::Consteval, ConstevalLoc, PrevSpec,
1228  DiagID);
1229  if (DiagID != 0)
1230  P.Diag(ConstevalLoc, DiagID) << PrevSpec;
1231  }
1232 }
1233 
1234 /// ParseLambdaExpressionAfterIntroducer - Parse the rest of a lambda
1235 /// expression.
1236 ExprResult Parser::ParseLambdaExpressionAfterIntroducer(
1237  LambdaIntroducer &Intro) {
1238  SourceLocation LambdaBeginLoc = Intro.Range.getBegin();
1239  Diag(LambdaBeginLoc, diag::warn_cxx98_compat_lambda);
1240 
1241  PrettyStackTraceLoc CrashInfo(PP.getSourceManager(), LambdaBeginLoc,
1242  "lambda expression parsing");
1243 
1244 
1245 
1246  // FIXME: Call into Actions to add any init-capture declarations to the
1247  // scope while parsing the lambda-declarator and compound-statement.
1248 
1249  // Parse lambda-declarator[opt].
1250  DeclSpec DS(AttrFactory);
1252  TemplateParameterDepthRAII CurTemplateDepthTracker(TemplateParameterDepth);
1253  Actions.PushLambdaScope();
1254 
1255  ParsedAttributes Attr(AttrFactory);
1256  if (getLangOpts().CUDA) {
1257  // In CUDA code, GNU attributes are allowed to appear immediately after the
1258  // "[...]", even if there is no "(...)" before the lambda body.
1259  MaybeParseGNUAttributes(D);
1260  }
1261 
1262  // Helper to emit a warning if we see a CUDA host/device/global attribute
1263  // after '(...)'. nvcc doesn't accept this.
1264  auto WarnIfHasCUDATargetAttr = [&] {
1265  if (getLangOpts().CUDA)
1266  for (const ParsedAttr &A : Attr)
1267  if (A.getKind() == ParsedAttr::AT_CUDADevice ||
1268  A.getKind() == ParsedAttr::AT_CUDAHost ||
1269  A.getKind() == ParsedAttr::AT_CUDAGlobal)
1270  Diag(A.getLoc(), diag::warn_cuda_attr_lambda_position)
1271  << A.getAttrName()->getName();
1272  };
1273 
1274  MultiParseScope TemplateParamScope(*this);
1275  if (Tok.is(tok::less)) {
1277  ? diag::warn_cxx17_compat_lambda_template_parameter_list
1278  : diag::ext_lambda_template_parameter_list);
1279 
1280  SmallVector<NamedDecl*, 4> TemplateParams;
1281  SourceLocation LAngleLoc, RAngleLoc;
1282  if (ParseTemplateParameters(TemplateParamScope,
1283  CurTemplateDepthTracker.getDepth(),
1284  TemplateParams, LAngleLoc, RAngleLoc)) {
1285  Actions.ActOnLambdaError(LambdaBeginLoc, getCurScope());
1286  return ExprError();
1287  }
1288 
1289  if (TemplateParams.empty()) {
1290  Diag(RAngleLoc,
1291  diag::err_lambda_template_parameter_list_empty);
1292  } else {
1293  ExprResult RequiresClause;
1294  if (TryConsumeToken(tok::kw_requires)) {
1295  RequiresClause =
1297  /*IsTrailingRequiresClause=*/false));
1298  if (RequiresClause.isInvalid())
1299  SkipUntil({tok::l_brace, tok::l_paren}, StopAtSemi | StopBeforeMatch);
1300  }
1301 
1303  LAngleLoc, TemplateParams, RAngleLoc, RequiresClause);
1304  ++CurTemplateDepthTracker;
1305  }
1306  }
1307 
1308  // Implement WG21 P2173, which allows attributes immediately before the
1309  // lambda declarator and applies them to the corresponding function operator
1310  // or operator template declaration. We accept this as a conforming extension
1311  // in all language modes that support lambdas.
1312  if (isCXX11AttributeSpecifier()) {
1314  ? diag::warn_cxx20_compat_decl_attrs_on_lambda
1315  : diag::ext_decl_attrs_on_lambda);
1316  MaybeParseCXX11Attributes(D);
1317  }
1318 
1319  TypeResult TrailingReturnType;
1320  SourceLocation TrailingReturnTypeLoc;
1321 
1322  auto ParseLambdaSpecifiers =
1323  [&](SourceLocation LParenLoc, SourceLocation RParenLoc,
1325  SourceLocation EllipsisLoc) {
1326  SourceLocation DeclEndLoc = RParenLoc;
1327 
1328  // GNU-style attributes must be parsed before the mutable specifier to
1329  // be compatible with GCC. MSVC-style attributes must be parsed before
1330  // the mutable specifier to be compatible with MSVC.
1331  MaybeParseAttributes(PAKM_GNU | PAKM_Declspec, Attr);
1332 
1333  // Parse mutable-opt and/or constexpr-opt or consteval-opt, and update
1334  // the DeclEndLoc.
1335  SourceLocation MutableLoc;
1336  SourceLocation ConstexprLoc;
1337  SourceLocation ConstevalLoc;
1338  tryConsumeLambdaSpecifierToken(*this, MutableLoc, ConstexprLoc,
1339  ConstevalLoc, DeclEndLoc);
1340 
1341  addConstexprToLambdaDeclSpecifier(*this, ConstexprLoc, DS);
1342  addConstevalToLambdaDeclSpecifier(*this, ConstevalLoc, DS);
1343  // Parse exception-specification[opt].
1345  SourceRange ESpecRange;
1346  SmallVector<ParsedType, 2> DynamicExceptions;
1347  SmallVector<SourceRange, 2> DynamicExceptionRanges;
1348  ExprResult NoexceptExpr;
1349  CachedTokens *ExceptionSpecTokens;
1350  ESpecType = tryParseExceptionSpecification(
1351  /*Delayed=*/false, ESpecRange, DynamicExceptions,
1352  DynamicExceptionRanges, NoexceptExpr, ExceptionSpecTokens);
1353 
1354  if (ESpecType != EST_None)
1355  DeclEndLoc = ESpecRange.getEnd();
1356 
1357  // Parse attribute-specifier[opt].
1358  if (MaybeParseCXX11Attributes(Attr))
1359  DeclEndLoc = Attr.Range.getEnd();
1360 
1361  // Parse OpenCL addr space attribute.
1362  if (Tok.isOneOf(tok::kw___private, tok::kw___global, tok::kw___local,
1363  tok::kw___constant, tok::kw___generic)) {
1364  ParseOpenCLQualifiers(DS.getAttributes());
1365  ConsumeToken();
1366  }
1367 
1368  SourceLocation FunLocalRangeEnd = DeclEndLoc;
1369 
1370  // Parse trailing-return-type[opt].
1371  if (Tok.is(tok::arrow)) {
1372  FunLocalRangeEnd = Tok.getLocation();
1374  TrailingReturnType = ParseTrailingReturnType(
1375  Range, /*MayBeFollowedByDirectInit*/ false);
1376  TrailingReturnTypeLoc = Range.getBegin();
1377  if (Range.getEnd().isValid())
1378  DeclEndLoc = Range.getEnd();
1379  }
1380 
1381  SourceLocation NoLoc;
1382  D.AddTypeInfo(
1384  /*HasProto=*/true,
1385  /*IsAmbiguous=*/false, LParenLoc, ParamInfo.data(),
1386  ParamInfo.size(), EllipsisLoc, RParenLoc,
1387  /*RefQualifierIsLvalueRef=*/true,
1388  /*RefQualifierLoc=*/NoLoc, MutableLoc, ESpecType, ESpecRange,
1389  DynamicExceptions.data(), DynamicExceptionRanges.data(),
1390  DynamicExceptions.size(),
1391  NoexceptExpr.isUsable() ? NoexceptExpr.get() : nullptr,
1392  /*ExceptionSpecTokens*/ nullptr,
1393  /*DeclsInPrototype=*/None, LParenLoc, FunLocalRangeEnd, D,
1394  TrailingReturnType, TrailingReturnTypeLoc, &DS),
1395  std::move(Attr), DeclEndLoc);
1396  };
1397 
1398  if (Tok.is(tok::l_paren)) {
1399  ParseScope PrototypeScope(this, Scope::FunctionPrototypeScope |
1402 
1403  BalancedDelimiterTracker T(*this, tok::l_paren);
1404  T.consumeOpen();
1405  SourceLocation LParenLoc = T.getOpenLocation();
1406 
1407  // Parse parameter-declaration-clause.
1409  SourceLocation EllipsisLoc;
1410 
1411  if (Tok.isNot(tok::r_paren)) {
1413  CurTemplateDepthTracker.getOriginalDepth());
1414 
1415  ParseParameterDeclarationClause(D.getContext(), Attr, ParamInfo,
1416  EllipsisLoc);
1417  // For a generic lambda, each 'auto' within the parameter declaration
1418  // clause creates a template type parameter, so increment the depth.
1419  // If we've parsed any explicit template parameters, then the depth will
1420  // have already been incremented. So we make sure that at most a single
1421  // depth level is added.
1422  if (Actions.getCurGenericLambda())
1423  CurTemplateDepthTracker.setAddedDepth(1);
1424  }
1425 
1426  T.consumeClose();
1427 
1428  // Parse lambda-specifiers.
1429  ParseLambdaSpecifiers(LParenLoc, /*DeclEndLoc=*/T.getCloseLocation(),
1430  ParamInfo, EllipsisLoc);
1431 
1432  // Parse requires-clause[opt].
1433  if (Tok.is(tok::kw_requires))
1434  ParseTrailingRequiresClause(D);
1435  } else if (Tok.isOneOf(tok::kw_mutable, tok::arrow, tok::kw___attribute,
1436  tok::kw_constexpr, tok::kw_consteval,
1437  tok::kw___private, tok::kw___global, tok::kw___local,
1438  tok::kw___constant, tok::kw___generic,
1439  tok::kw_requires, tok::kw_noexcept) ||
1440  (Tok.is(tok::l_square) && NextToken().is(tok::l_square))) {
1441  if (!getLangOpts().CPlusPlus2b)
1442  // It's common to forget that one needs '()' before 'mutable', an
1443  // attribute specifier, the result type, or the requires clause. Deal with
1444  // this.
1445  Diag(Tok, diag::ext_lambda_missing_parens)
1446  << FixItHint::CreateInsertion(Tok.getLocation(), "() ");
1447 
1448  SourceLocation NoLoc;
1449  // Parse lambda-specifiers.
1450  std::vector<DeclaratorChunk::ParamInfo> EmptyParamInfo;
1451  ParseLambdaSpecifiers(/*LParenLoc=*/NoLoc, /*RParenLoc=*/NoLoc,
1452  EmptyParamInfo, /*EllipsisLoc=*/NoLoc);
1453  }
1454 
1455  WarnIfHasCUDATargetAttr();
1456 
1457  // FIXME: Rename BlockScope -> ClosureScope if we decide to continue using
1458  // it.
1459  unsigned ScopeFlags = Scope::BlockScope | Scope::FnScope | Scope::DeclScope |
1461  ParseScope BodyScope(this, ScopeFlags);
1462 
1463  Actions.ActOnStartOfLambdaDefinition(Intro, D, getCurScope());
1464 
1465  // Parse compound-statement.
1466  if (!Tok.is(tok::l_brace)) {
1467  Diag(Tok, diag::err_expected_lambda_body);
1468  Actions.ActOnLambdaError(LambdaBeginLoc, getCurScope());
1469  return ExprError();
1470  }
1471 
1472  StmtResult Stmt(ParseCompoundStatementBody());
1473  BodyScope.Exit();
1474  TemplateParamScope.Exit();
1475 
1476  if (!Stmt.isInvalid() && !TrailingReturnType.isInvalid())
1477  return Actions.ActOnLambdaExpr(LambdaBeginLoc, Stmt.get(), getCurScope());
1478 
1479  Actions.ActOnLambdaError(LambdaBeginLoc, getCurScope());
1480  return ExprError();
1481 }
1482 
1483 /// ParseCXXCasts - This handles the various ways to cast expressions to another
1484 /// type.
1485 ///
1486 /// postfix-expression: [C++ 5.2p1]
1487 /// 'dynamic_cast' '<' type-name '>' '(' expression ')'
1488 /// 'static_cast' '<' type-name '>' '(' expression ')'
1489 /// 'reinterpret_cast' '<' type-name '>' '(' expression ')'
1490 /// 'const_cast' '<' type-name '>' '(' expression ')'
1491 ///
1492 /// C++ for OpenCL s2.3.1 adds:
1493 /// 'addrspace_cast' '<' type-name '>' '(' expression ')'
1494 ExprResult Parser::ParseCXXCasts() {
1495  tok::TokenKind Kind = Tok.getKind();
1496  const char *CastName = nullptr; // For error messages
1497 
1498  switch (Kind) {
1499  default: llvm_unreachable("Unknown C++ cast!");
1500  case tok::kw_addrspace_cast: CastName = "addrspace_cast"; break;
1501  case tok::kw_const_cast: CastName = "const_cast"; break;
1502  case tok::kw_dynamic_cast: CastName = "dynamic_cast"; break;
1503  case tok::kw_reinterpret_cast: CastName = "reinterpret_cast"; break;
1504  case tok::kw_static_cast: CastName = "static_cast"; break;
1505  }
1506 
1507  SourceLocation OpLoc = ConsumeToken();
1508  SourceLocation LAngleBracketLoc = Tok.getLocation();
1509 
1510  // Check for "<::" which is parsed as "[:". If found, fix token stream,
1511  // diagnose error, suggest fix, and recover parsing.
1512  if (Tok.is(tok::l_square) && Tok.getLength() == 2) {
1513  Token Next = NextToken();
1514  if (Next.is(tok::colon) && areTokensAdjacent(Tok, Next))
1515  FixDigraph(*this, PP, Tok, Next, Kind, /*AtDigraph*/true);
1516  }
1517 
1518  if (ExpectAndConsume(tok::less, diag::err_expected_less_after, CastName))
1519  return ExprError();
1520 
1521  // Parse the common declaration-specifiers piece.
1522  DeclSpec DS(AttrFactory);
1523  ParseSpecifierQualifierList(DS);
1524 
1525  // Parse the abstract-declarator, if present.
1526  Declarator DeclaratorInfo(DS, DeclaratorContext::TypeName);
1527  ParseDeclarator(DeclaratorInfo);
1528 
1529  SourceLocation RAngleBracketLoc = Tok.getLocation();
1530 
1531  if (ExpectAndConsume(tok::greater))
1532  return ExprError(Diag(LAngleBracketLoc, diag::note_matching) << tok::less);
1533 
1534  BalancedDelimiterTracker T(*this, tok::l_paren);
1535 
1536  if (T.expectAndConsume(diag::err_expected_lparen_after, CastName))
1537  return ExprError();
1538 
1539  ExprResult Result = ParseExpression();
1540 
1541  // Match the ')'.
1542  T.consumeClose();
1543 
1544  if (!Result.isInvalid() && !DeclaratorInfo.isInvalidType())
1545  Result = Actions.ActOnCXXNamedCast(OpLoc, Kind,
1546  LAngleBracketLoc, DeclaratorInfo,
1547  RAngleBracketLoc,
1548  T.getOpenLocation(), Result.get(),
1549  T.getCloseLocation());
1550 
1551  return Result;
1552 }
1553 
1554 /// ParseCXXTypeid - This handles the C++ typeid expression.
1555 ///
1556 /// postfix-expression: [C++ 5.2p1]
1557 /// 'typeid' '(' expression ')'
1558 /// 'typeid' '(' type-id ')'
1559 ///
1560 ExprResult Parser::ParseCXXTypeid() {
1561  assert(Tok.is(tok::kw_typeid) && "Not 'typeid'!");
1562 
1563  SourceLocation OpLoc = ConsumeToken();
1564  SourceLocation LParenLoc, RParenLoc;
1565  BalancedDelimiterTracker T(*this, tok::l_paren);
1566 
1567  // typeid expressions are always parenthesized.
1568  if (T.expectAndConsume(diag::err_expected_lparen_after, "typeid"))
1569  return ExprError();
1570  LParenLoc = T.getOpenLocation();
1571 
1572  ExprResult Result;
1573 
1574  // C++0x [expr.typeid]p3:
1575  // When typeid is applied to an expression other than an lvalue of a
1576  // polymorphic class type [...] The expression is an unevaluated
1577  // operand (Clause 5).
1578  //
1579  // Note that we can't tell whether the expression is an lvalue of a
1580  // polymorphic class type until after we've parsed the expression; we
1581  // speculatively assume the subexpression is unevaluated, and fix it up
1582  // later.
1583  //
1584  // We enter the unevaluated context before trying to determine whether we
1585  // have a type-id, because the tentative parse logic will try to resolve
1586  // names, and must treat them as unevaluated.
1590 
1591  if (isTypeIdInParens()) {
1592  TypeResult Ty = ParseTypeName();
1593 
1594  // Match the ')'.
1595  T.consumeClose();
1596  RParenLoc = T.getCloseLocation();
1597  if (Ty.isInvalid() || RParenLoc.isInvalid())
1598  return ExprError();
1599 
1600  Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc, /*isType=*/true,
1601  Ty.get().getAsOpaquePtr(), RParenLoc);
1602  } else {
1603  Result = ParseExpression();
1604 
1605  // Match the ')'.
1606  if (Result.isInvalid())
1607  SkipUntil(tok::r_paren, StopAtSemi);
1608  else {
1609  T.consumeClose();
1610  RParenLoc = T.getCloseLocation();
1611  if (RParenLoc.isInvalid())
1612  return ExprError();
1613 
1614  Result = Actions.ActOnCXXTypeid(OpLoc, LParenLoc, /*isType=*/false,
1615  Result.get(), RParenLoc);
1616  }
1617  }
1618 
1619  return Result;
1620 }
1621 
1622 /// ParseCXXUuidof - This handles the Microsoft C++ __uuidof expression.
1623 ///
1624 /// '__uuidof' '(' expression ')'
1625 /// '__uuidof' '(' type-id ')'
1626 ///
1627 ExprResult Parser::ParseCXXUuidof() {
1628  assert(Tok.is(tok::kw___uuidof) && "Not '__uuidof'!");
1629 
1630  SourceLocation OpLoc = ConsumeToken();
1631  BalancedDelimiterTracker T(*this, tok::l_paren);
1632 
1633  // __uuidof expressions are always parenthesized.
1634  if (T.expectAndConsume(diag::err_expected_lparen_after, "__uuidof"))
1635  return ExprError();
1636 
1637  ExprResult Result;
1638 
1639  if (isTypeIdInParens()) {
1640  TypeResult Ty = ParseTypeName();
1641 
1642  // Match the ')'.
1643  T.consumeClose();
1644 
1645  if (Ty.isInvalid())
1646  return ExprError();
1647 
1648  Result = Actions.ActOnCXXUuidof(OpLoc, T.getOpenLocation(), /*isType=*/true,
1649  Ty.get().getAsOpaquePtr(),
1650  T.getCloseLocation());
1651  } else {
1654  Result = ParseExpression();
1655 
1656  // Match the ')'.
1657  if (Result.isInvalid())
1658  SkipUntil(tok::r_paren, StopAtSemi);
1659  else {
1660  T.consumeClose();
1661 
1662  Result = Actions.ActOnCXXUuidof(OpLoc, T.getOpenLocation(),
1663  /*isType=*/false,
1664  Result.get(), T.getCloseLocation());
1665  }
1666  }
1667 
1668  return Result;
1669 }
1670 
1671 /// Parse a C++ pseudo-destructor expression after the base,
1672 /// . or -> operator, and nested-name-specifier have already been
1673 /// parsed. We're handling this fragment of the grammar:
1674 ///
1675 /// postfix-expression: [C++2a expr.post]
1676 /// postfix-expression . template[opt] id-expression
1677 /// postfix-expression -> template[opt] id-expression
1678 ///
1679 /// id-expression:
1680 /// qualified-id
1681 /// unqualified-id
1682 ///
1683 /// qualified-id:
1684 /// nested-name-specifier template[opt] unqualified-id
1685 ///
1686 /// nested-name-specifier:
1687 /// type-name ::
1688 /// decltype-specifier :: FIXME: not implemented, but probably only
1689 /// allowed in C++ grammar by accident
1690 /// nested-name-specifier identifier ::
1691 /// nested-name-specifier template[opt] simple-template-id ::
1692 /// [...]
1693 ///
1694 /// unqualified-id:
1695 /// ~ type-name
1696 /// ~ decltype-specifier
1697 /// [...]
1698 ///
1699 /// ... where the all but the last component of the nested-name-specifier
1700 /// has already been parsed, and the base expression is not of a non-dependent
1701 /// class type.
1702 ExprResult
1703 Parser::ParseCXXPseudoDestructor(Expr *Base, SourceLocation OpLoc,
1704  tok::TokenKind OpKind,
1705  CXXScopeSpec &SS,
1706  ParsedType ObjectType) {
1707  // If the last component of the (optional) nested-name-specifier is
1708  // template[opt] simple-template-id, it has already been annotated.
1709  UnqualifiedId FirstTypeName;
1710  SourceLocation CCLoc;
1711  if (Tok.is(tok::identifier)) {
1712  FirstTypeName.setIdentifier(Tok.getIdentifierInfo(), Tok.getLocation());
1713  ConsumeToken();
1714  assert(Tok.is(tok::coloncolon) &&"ParseOptionalCXXScopeSpecifier fail");
1715  CCLoc = ConsumeToken();
1716  } else if (Tok.is(tok::annot_template_id)) {
1717  TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
1718  // FIXME: Carry on and build an AST representation for tooling.
1719  if (TemplateId->isInvalid())
1720  return ExprError();
1721  FirstTypeName.setTemplateId(TemplateId);
1722  ConsumeAnnotationToken();
1723  assert(Tok.is(tok::coloncolon) &&"ParseOptionalCXXScopeSpecifier fail");
1724  CCLoc = ConsumeToken();
1725  } else {
1726  assert(SS.isEmpty() && "missing last component of nested name specifier");
1727  FirstTypeName.setIdentifier(nullptr, SourceLocation());
1728  }
1729 
1730  // Parse the tilde.
1731  assert(Tok.is(tok::tilde) && "ParseOptionalCXXScopeSpecifier fail");
1732  SourceLocation TildeLoc = ConsumeToken();
1733 
1734  if (Tok.is(tok::kw_decltype) && !FirstTypeName.isValid()) {
1735  DeclSpec DS(AttrFactory);
1736  ParseDecltypeSpecifier(DS);
1737  if (DS.getTypeSpecType() == TST_error)
1738  return ExprError();
1739  return Actions.ActOnPseudoDestructorExpr(getCurScope(), Base, OpLoc, OpKind,
1740  TildeLoc, DS);
1741  }
1742 
1743  if (!Tok.is(tok::identifier)) {
1744  Diag(Tok, diag::err_destructor_tilde_identifier);
1745  return ExprError();
1746  }
1747 
1748  // Parse the second type.
1749  UnqualifiedId SecondTypeName;
1750  IdentifierInfo *Name = Tok.getIdentifierInfo();
1751  SourceLocation NameLoc = ConsumeToken();
1752  SecondTypeName.setIdentifier(Name, NameLoc);
1753 
1754  // If there is a '<', the second type name is a template-id. Parse
1755  // it as such.
1756  //
1757  // FIXME: This is not a context in which a '<' is assumed to start a template
1758  // argument list. This affects examples such as
1759  // void f(auto *p) { p->~X<int>(); }
1760  // ... but there's no ambiguity, and nowhere to write 'template' in such an
1761  // example, so we accept it anyway.
1762  if (Tok.is(tok::less) &&
1763  ParseUnqualifiedIdTemplateId(
1764  SS, ObjectType, Base && Base->containsErrors(), SourceLocation(),
1765  Name, NameLoc, false, SecondTypeName,
1766  /*AssumeTemplateId=*/true))
1767  return ExprError();
1768 
1769  return Actions.ActOnPseudoDestructorExpr(getCurScope(), Base, OpLoc, OpKind,
1770  SS, FirstTypeName, CCLoc, TildeLoc,
1771  SecondTypeName);
1772 }
1773 
1774 /// ParseCXXBoolLiteral - This handles the C++ Boolean literals.
1775 ///
1776 /// boolean-literal: [C++ 2.13.5]
1777 /// 'true'
1778 /// 'false'
1779 ExprResult Parser::ParseCXXBoolLiteral() {
1780  tok::TokenKind Kind = Tok.getKind();
1781  return Actions.ActOnCXXBoolLiteral(ConsumeToken(), Kind);
1782 }
1783 
1784 /// ParseThrowExpression - This handles the C++ throw expression.
1785 ///
1786 /// throw-expression: [C++ 15]
1787 /// 'throw' assignment-expression[opt]
1788 ExprResult Parser::ParseThrowExpression() {
1789  assert(Tok.is(tok::kw_throw) && "Not throw!");
1790  SourceLocation ThrowLoc = ConsumeToken(); // Eat the throw token.
1791 
1792  // If the current token isn't the start of an assignment-expression,
1793  // then the expression is not present. This handles things like:
1794  // "C ? throw : (void)42", which is crazy but legal.
1795  switch (Tok.getKind()) { // FIXME: move this predicate somewhere common.
1796  case tok::semi:
1797  case tok::r_paren:
1798  case tok::r_square:
1799  case tok::r_brace:
1800  case tok::colon:
1801  case tok::comma:
1802  return Actions.ActOnCXXThrow(getCurScope(), ThrowLoc, nullptr);
1803 
1804  default:
1806  if (Expr.isInvalid()) return Expr;
1807  return Actions.ActOnCXXThrow(getCurScope(), ThrowLoc, Expr.get());
1808  }
1809 }
1810 
1811 /// Parse the C++ Coroutines co_yield expression.
1812 ///
1813 /// co_yield-expression:
1814 /// 'co_yield' assignment-expression[opt]
1815 ExprResult Parser::ParseCoyieldExpression() {
1816  assert(Tok.is(tok::kw_co_yield) && "Not co_yield!");
1817 
1818  SourceLocation Loc = ConsumeToken();
1819  ExprResult Expr = Tok.is(tok::l_brace) ? ParseBraceInitializer()
1821  if (!Expr.isInvalid())
1822  Expr = Actions.ActOnCoyieldExpr(getCurScope(), Loc, Expr.get());
1823  return Expr;
1824 }
1825 
1826 /// ParseCXXThis - This handles the C++ 'this' pointer.
1827 ///
1828 /// C++ 9.3.2: In the body of a non-static member function, the keyword this is
1829 /// a non-lvalue expression whose value is the address of the object for which
1830 /// the function is called.
1831 ExprResult Parser::ParseCXXThis() {
1832  assert(Tok.is(tok::kw_this) && "Not 'this'!");
1833  SourceLocation ThisLoc = ConsumeToken();
1834  return Actions.ActOnCXXThis(ThisLoc);
1835 }
1836 
1837 /// ParseCXXTypeConstructExpression - Parse construction of a specified type.
1838 /// Can be interpreted either as function-style casting ("int(x)")
1839 /// or class type construction ("ClassType(x,y,z)")
1840 /// or creation of a value-initialized type ("int()").
1841 /// See [C++ 5.2.3].
1842 ///
1843 /// postfix-expression: [C++ 5.2p1]
1844 /// simple-type-specifier '(' expression-list[opt] ')'
1845 /// [C++0x] simple-type-specifier braced-init-list
1846 /// typename-specifier '(' expression-list[opt] ')'
1847 /// [C++0x] typename-specifier braced-init-list
1848 ///
1849 /// In C++1z onwards, the type specifier can also be a template-name.
1850 ExprResult
1851 Parser::ParseCXXTypeConstructExpression(const DeclSpec &DS) {
1852  Declarator DeclaratorInfo(DS, DeclaratorContext::FunctionalCast);
1853  ParsedType TypeRep = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo).get();
1854 
1855  assert((Tok.is(tok::l_paren) ||
1856  (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)))
1857  && "Expected '(' or '{'!");
1858 
1859  if (Tok.is(tok::l_brace)) {
1860  PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.get());
1861  ExprResult Init = ParseBraceInitializer();
1862  if (Init.isInvalid())
1863  return Init;
1864  Expr *InitList = Init.get();
1865  return Actions.ActOnCXXTypeConstructExpr(
1866  TypeRep, InitList->getBeginLoc(), MultiExprArg(&InitList, 1),
1867  InitList->getEndLoc(), /*ListInitialization=*/true);
1868  } else {
1869  BalancedDelimiterTracker T(*this, tok::l_paren);
1870  T.consumeOpen();
1871 
1872  PreferredType.enterTypeCast(Tok.getLocation(), TypeRep.get());
1873 
1874  ExprVector Exprs;
1875  CommaLocsTy CommaLocs;
1876 
1877  auto RunSignatureHelp = [&]() {
1878  QualType PreferredType;
1879  if (TypeRep)
1880  PreferredType = Actions.ProduceConstructorSignatureHelp(
1881  TypeRep.get()->getCanonicalTypeInternal(), DS.getEndLoc(), Exprs,
1882  T.getOpenLocation(), /*Braced=*/false);
1883  CalledSignatureHelp = true;
1884  return PreferredType;
1885  };
1886 
1887  if (Tok.isNot(tok::r_paren)) {
1888  if (ParseExpressionList(Exprs, CommaLocs, [&] {
1889  PreferredType.enterFunctionArgument(Tok.getLocation(),
1890  RunSignatureHelp);
1891  })) {
1892  if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
1893  RunSignatureHelp();
1894  SkipUntil(tok::r_paren, StopAtSemi);
1895  return ExprError();
1896  }
1897  }
1898 
1899  // Match the ')'.
1900  T.consumeClose();
1901 
1902  // TypeRep could be null, if it references an invalid typedef.
1903  if (!TypeRep)
1904  return ExprError();
1905 
1906  assert((Exprs.size() == 0 || Exprs.size()-1 == CommaLocs.size())&&
1907  "Unexpected number of commas!");
1908  return Actions.ActOnCXXTypeConstructExpr(TypeRep, T.getOpenLocation(),
1909  Exprs, T.getCloseLocation(),
1910  /*ListInitialization=*/false);
1911  }
1912 }
1913 
1915 Parser::ParseAliasDeclarationInInitStatement(DeclaratorContext Context,
1916  ParsedAttributes &Attrs) {
1917  assert(Tok.is(tok::kw_using) && "Expected using");
1918  assert((Context == DeclaratorContext::ForInit ||
1919  Context == DeclaratorContext::SelectionInit) &&
1920  "Unexpected Declarator Context");
1921  DeclGroupPtrTy DG;
1922  SourceLocation DeclStart = ConsumeToken(), DeclEnd;
1923 
1924  DG = ParseUsingDeclaration(Context, {}, DeclStart, DeclEnd, Attrs, AS_none);
1925  if (!DG)
1926  return DG;
1927 
1928  Diag(DeclStart, !getLangOpts().CPlusPlus2b
1929  ? diag::ext_alias_in_init_statement
1930  : diag::warn_cxx20_alias_in_init_statement)
1931  << SourceRange(DeclStart, DeclEnd);
1932 
1933  return DG;
1934 }
1935 
1936 /// ParseCXXCondition - if/switch/while condition expression.
1937 ///
1938 /// condition:
1939 /// expression
1940 /// type-specifier-seq declarator '=' assignment-expression
1941 /// [C++11] type-specifier-seq declarator '=' initializer-clause
1942 /// [C++11] type-specifier-seq declarator braced-init-list
1943 /// [Clang] type-specifier-seq ref-qualifier[opt] '[' identifier-list ']'
1944 /// brace-or-equal-initializer
1945 /// [GNU] type-specifier-seq declarator simple-asm-expr[opt] attributes[opt]
1946 /// '=' assignment-expression
1947 ///
1948 /// In C++1z, a condition may in some contexts be preceded by an
1949 /// optional init-statement. This function will parse that too.
1950 ///
1951 /// \param InitStmt If non-null, an init-statement is permitted, and if present
1952 /// will be parsed and stored here.
1953 ///
1954 /// \param Loc The location of the start of the statement that requires this
1955 /// condition, e.g., the "for" in a for loop.
1956 ///
1957 /// \param MissingOK Whether an empty condition is acceptable here. Otherwise
1958 /// it is considered an error to be recovered from.
1959 ///
1960 /// \param FRI If non-null, a for range declaration is permitted, and if
1961 /// present will be parsed and stored here, and a null result will be returned.
1962 ///
1963 /// \param EnterForConditionScope If true, enter a continue/break scope at the
1964 /// appropriate moment for a 'for' loop.
1965 ///
1966 /// \returns The parsed condition.
1968 Parser::ParseCXXCondition(StmtResult *InitStmt, SourceLocation Loc,
1969  Sema::ConditionKind CK, bool MissingOK,
1970  ForRangeInfo *FRI, bool EnterForConditionScope) {
1971  // Helper to ensure we always enter a continue/break scope if requested.
1972  struct ForConditionScopeRAII {
1973  Scope *S;
1974  void enter(bool IsConditionVariable) {
1975  if (S) {
1976  S->AddFlags(Scope::BreakScope | Scope::ContinueScope);
1977  S->setIsConditionVarScope(IsConditionVariable);
1978  }
1979  }
1980  ~ForConditionScopeRAII() {
1981  if (S)
1982  S->setIsConditionVarScope(false);
1983  }
1984  } ForConditionScope{EnterForConditionScope ? getCurScope() : nullptr};
1985 
1986  ParenBraceBracketBalancer BalancerRAIIObj(*this);
1987  PreferredType.enterCondition(Actions, Tok.getLocation());
1988 
1989  if (Tok.is(tok::code_completion)) {
1990  cutOffParsing();
1992  return Sema::ConditionError();
1993  }
1994 
1995  ParsedAttributes attrs(AttrFactory);
1996  MaybeParseCXX11Attributes(attrs);
1997 
1998  const auto WarnOnInit = [this, &CK] {
2000  ? diag::warn_cxx14_compat_init_statement
2001  : diag::ext_init_statement)
2002  << (CK == Sema::ConditionKind::Switch);
2003  };
2004 
2005  // Determine what kind of thing we have.
2006  switch (isCXXConditionDeclarationOrInitStatement(InitStmt, FRI)) {
2007  case ConditionOrInitStatement::Expression: {
2008  // If this is a for loop, we're entering its condition.
2009  ForConditionScope.enter(/*IsConditionVariable=*/false);
2010 
2011  ProhibitAttributes(attrs);
2012 
2013  // We can have an empty expression here.
2014  // if (; true);
2015  if (InitStmt && Tok.is(tok::semi)) {
2016  WarnOnInit();
2017  SourceLocation SemiLoc = Tok.getLocation();
2018  if (!Tok.hasLeadingEmptyMacro() && !SemiLoc.isMacroID()) {
2019  Diag(SemiLoc, diag::warn_empty_init_statement)
2020  << (CK == Sema::ConditionKind::Switch)
2021  << FixItHint::CreateRemoval(SemiLoc);
2022  }
2023  ConsumeToken();
2024  *InitStmt = Actions.ActOnNullStmt(SemiLoc);
2025  return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
2026  }
2027 
2028  // Parse the expression.
2029  ExprResult Expr = ParseExpression(); // expression
2030  if (Expr.isInvalid())
2031  return Sema::ConditionError();
2032 
2033  if (InitStmt && Tok.is(tok::semi)) {
2034  WarnOnInit();
2035  *InitStmt = Actions.ActOnExprStmt(Expr.get());
2036  ConsumeToken();
2037  return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
2038  }
2039 
2040  return Actions.ActOnCondition(getCurScope(), Loc, Expr.get(), CK,
2041  MissingOK);
2042  }
2043 
2044  case ConditionOrInitStatement::InitStmtDecl: {
2045  WarnOnInit();
2046  DeclGroupPtrTy DG;
2047  SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
2048  if (Tok.is(tok::kw_using))
2049  DG = ParseAliasDeclarationInInitStatement(
2051  else
2052  DG = ParseSimpleDeclaration(DeclaratorContext::SelectionInit, DeclEnd,
2053  attrs, /*RequireSemi=*/true);
2054  *InitStmt = Actions.ActOnDeclStmt(DG, DeclStart, DeclEnd);
2055  return ParseCXXCondition(nullptr, Loc, CK, MissingOK);
2056  }
2057 
2058  case ConditionOrInitStatement::ForRangeDecl: {
2059  // This is 'for (init-stmt; for-range-decl : range-expr)'.
2060  // We're not actually in a for loop yet, so 'break' and 'continue' aren't
2061  // permitted here.
2062  assert(FRI && "should not parse a for range declaration here");
2063  SourceLocation DeclStart = Tok.getLocation(), DeclEnd;
2064  DeclGroupPtrTy DG = ParseSimpleDeclaration(DeclaratorContext::ForInit,
2065  DeclEnd, attrs, false, FRI);
2066  FRI->LoopVar = Actions.ActOnDeclStmt(DG, DeclStart, Tok.getLocation());
2067  assert((FRI->ColonLoc.isValid() || !DG) &&
2068  "cannot find for range declaration");
2069  return Sema::ConditionResult();
2070  }
2071 
2072  case ConditionOrInitStatement::ConditionDecl:
2073  case ConditionOrInitStatement::Error:
2074  break;
2075  }
2076 
2077  // If this is a for loop, we're entering its condition.
2078  ForConditionScope.enter(/*IsConditionVariable=*/true);
2079 
2080  // type-specifier-seq
2081  DeclSpec DS(AttrFactory);
2082  DS.takeAttributesFrom(attrs);
2083  ParseSpecifierQualifierList(DS, AS_none, DeclSpecContext::DSC_condition);
2084 
2085  // declarator
2086  Declarator DeclaratorInfo(DS, DeclaratorContext::Condition);
2087  ParseDeclarator(DeclaratorInfo);
2088 
2089  // simple-asm-expr[opt]
2090  if (Tok.is(tok::kw_asm)) {
2091  SourceLocation Loc;
2092  ExprResult AsmLabel(ParseSimpleAsm(/*ForAsmLabel*/ true, &Loc));
2093  if (AsmLabel.isInvalid()) {
2094  SkipUntil(tok::semi, StopAtSemi);
2095  return Sema::ConditionError();
2096  }
2097  DeclaratorInfo.setAsmLabel(AsmLabel.get());
2098  DeclaratorInfo.SetRangeEnd(Loc);
2099  }
2100 
2101  // If attributes are present, parse them.
2102  MaybeParseGNUAttributes(DeclaratorInfo);
2103 
2104  // Type-check the declaration itself.
2106  DeclaratorInfo);
2107  if (Dcl.isInvalid())
2108  return Sema::ConditionError();
2109  Decl *DeclOut = Dcl.get();
2110 
2111  // '=' assignment-expression
2112  // If a '==' or '+=' is found, suggest a fixit to '='.
2113  bool CopyInitialization = isTokenEqualOrEqualTypo();
2114  if (CopyInitialization)
2115  ConsumeToken();
2116 
2117  ExprResult InitExpr = ExprError();
2118  if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) {
2119  Diag(Tok.getLocation(),
2120  diag::warn_cxx98_compat_generalized_initializer_lists);
2121  InitExpr = ParseBraceInitializer();
2122  } else if (CopyInitialization) {
2123  PreferredType.enterVariableInit(Tok.getLocation(), DeclOut);
2124  InitExpr = ParseAssignmentExpression();
2125  } else if (Tok.is(tok::l_paren)) {
2126  // This was probably an attempt to initialize the variable.
2127  SourceLocation LParen = ConsumeParen(), RParen = LParen;
2128  if (SkipUntil(tok::r_paren, StopAtSemi | StopBeforeMatch))
2129  RParen = ConsumeParen();
2130  Diag(DeclOut->getLocation(),
2131  diag::err_expected_init_in_condition_lparen)
2132  << SourceRange(LParen, RParen);
2133  } else {
2134  Diag(DeclOut->getLocation(), diag::err_expected_init_in_condition);
2135  }
2136 
2137  if (!InitExpr.isInvalid())
2138  Actions.AddInitializerToDecl(DeclOut, InitExpr.get(), !CopyInitialization);
2139  else
2140  Actions.ActOnInitializerError(DeclOut);
2141 
2142  Actions.FinalizeDeclaration(DeclOut);
2143  return Actions.ActOnConditionVariable(DeclOut, Loc, CK);
2144 }
2145 
2146 /// ParseCXXSimpleTypeSpecifier - [C++ 7.1.5.2] Simple type specifiers.
2147 /// This should only be called when the current token is known to be part of
2148 /// simple-type-specifier.
2149 ///
2150 /// simple-type-specifier:
2151 /// '::'[opt] nested-name-specifier[opt] type-name
2152 /// '::'[opt] nested-name-specifier 'template' simple-template-id [TODO]
2153 /// char
2154 /// wchar_t
2155 /// bool
2156 /// short
2157 /// int
2158 /// long
2159 /// signed
2160 /// unsigned
2161 /// float
2162 /// double
2163 /// void
2164 /// [GNU] typeof-specifier
2165 /// [C++0x] auto [TODO]
2166 ///
2167 /// type-name:
2168 /// class-name
2169 /// enum-name
2170 /// typedef-name
2171 ///
2172 void Parser::ParseCXXSimpleTypeSpecifier(DeclSpec &DS) {
2173  DS.SetRangeStart(Tok.getLocation());
2174  const char *PrevSpec;
2175  unsigned DiagID;
2176  SourceLocation Loc = Tok.getLocation();
2177  const clang::PrintingPolicy &Policy =
2178  Actions.getASTContext().getPrintingPolicy();
2179 
2180  switch (Tok.getKind()) {
2181  case tok::identifier: // foo::bar
2182  case tok::coloncolon: // ::foo::bar
2183  llvm_unreachable("Annotation token should already be formed!");
2184  default:
2185  llvm_unreachable("Not a simple-type-specifier token!");
2186 
2187  // type-name
2188  case tok::annot_typename: {
2189  DS.SetTypeSpecType(DeclSpec::TST_typename, Loc, PrevSpec, DiagID,
2190  getTypeAnnotation(Tok), Policy);
2191  DS.SetRangeEnd(Tok.getAnnotationEndLoc());
2192  ConsumeAnnotationToken();
2193 
2194  DS.Finish(Actions, Policy);
2195  return;
2196  }
2197 
2198  case tok::kw__ExtInt:
2199  case tok::kw__BitInt: {
2200  DiagnoseBitIntUse(Tok);
2201  ExprResult ER = ParseExtIntegerArgument();
2202  if (ER.isInvalid())
2203  DS.SetTypeSpecError();
2204  else
2205  DS.SetBitIntType(Loc, ER.get(), PrevSpec, DiagID, Policy);
2206 
2207  // Do this here because we have already consumed the close paren.
2208  DS.SetRangeEnd(PrevTokLocation);
2209  DS.Finish(Actions, Policy);
2210  return;
2211  }
2212 
2213  // builtin types
2214  case tok::kw_short:
2215  DS.SetTypeSpecWidth(TypeSpecifierWidth::Short, Loc, PrevSpec, DiagID,
2216  Policy);
2217  break;
2218  case tok::kw_long:
2219  DS.SetTypeSpecWidth(TypeSpecifierWidth::Long, Loc, PrevSpec, DiagID,
2220  Policy);
2221  break;
2222  case tok::kw___int64:
2223  DS.SetTypeSpecWidth(TypeSpecifierWidth::LongLong, Loc, PrevSpec, DiagID,
2224  Policy);
2225  break;
2226  case tok::kw_signed:
2227  DS.SetTypeSpecSign(TypeSpecifierSign::Signed, Loc, PrevSpec, DiagID);
2228  break;
2229  case tok::kw_unsigned:
2230  DS.SetTypeSpecSign(TypeSpecifierSign::Unsigned, Loc, PrevSpec, DiagID);
2231  break;
2232  case tok::kw_void:
2233  DS.SetTypeSpecType(DeclSpec::TST_void, Loc, PrevSpec, DiagID, Policy);
2234  break;
2235  case tok::kw_auto:
2236  DS.SetTypeSpecType(DeclSpec::TST_auto, Loc, PrevSpec, DiagID, Policy);
2237  break;
2238  case tok::kw_char:
2239  DS.SetTypeSpecType(DeclSpec::TST_char, Loc, PrevSpec, DiagID, Policy);
2240  break;
2241  case tok::kw_int:
2242  DS.SetTypeSpecType(DeclSpec::TST_int, Loc, PrevSpec, DiagID, Policy);
2243  break;
2244  case tok::kw___int128:
2245  DS.SetTypeSpecType(DeclSpec::TST_int128, Loc, PrevSpec, DiagID, Policy);
2246  break;
2247  case tok::kw___bf16:
2248  DS.SetTypeSpecType(DeclSpec::TST_BFloat16, Loc, PrevSpec, DiagID, Policy);
2249  break;
2250  case tok::kw_half:
2251  DS.SetTypeSpecType(DeclSpec::TST_half, Loc, PrevSpec, DiagID, Policy);
2252  break;
2253  case tok::kw_float:
2254  DS.SetTypeSpecType(DeclSpec::TST_float, Loc, PrevSpec, DiagID, Policy);
2255  break;
2256  case tok::kw_double:
2257  DS.SetTypeSpecType(DeclSpec::TST_double, Loc, PrevSpec, DiagID, Policy);
2258  break;
2259  case tok::kw__Float16:
2260  DS.SetTypeSpecType(DeclSpec::TST_float16, Loc, PrevSpec, DiagID, Policy);
2261  break;
2262  case tok::kw___float128:
2263  DS.SetTypeSpecType(DeclSpec::TST_float128, Loc, PrevSpec, DiagID, Policy);
2264  break;
2265  case tok::kw___ibm128:
2266  DS.SetTypeSpecType(DeclSpec::TST_ibm128, Loc, PrevSpec, DiagID, Policy);
2267  break;
2268  case tok::kw_wchar_t:
2269  DS.SetTypeSpecType(DeclSpec::TST_wchar, Loc, PrevSpec, DiagID, Policy);
2270  break;
2271  case tok::kw_char8_t:
2272  DS.SetTypeSpecType(DeclSpec::TST_char8, Loc, PrevSpec, DiagID, Policy);
2273  break;
2274  case tok::kw_char16_t:
2275  DS.SetTypeSpecType(DeclSpec::TST_char16, Loc, PrevSpec, DiagID, Policy);
2276  break;
2277  case tok::kw_char32_t:
2278  DS.SetTypeSpecType(DeclSpec::TST_char32, Loc, PrevSpec, DiagID, Policy);
2279  break;
2280  case tok::kw_bool:
2281  DS.SetTypeSpecType(DeclSpec::TST_bool, Loc, PrevSpec, DiagID, Policy);
2282  break;
2283 #define GENERIC_IMAGE_TYPE(ImgType, Id) \
2284  case tok::kw_##ImgType##_t: \
2285  DS.SetTypeSpecType(DeclSpec::TST_##ImgType##_t, Loc, PrevSpec, DiagID, \
2286  Policy); \
2287  break;
2288 #include "clang/Basic/OpenCLImageTypes.def"
2289 
2290  case tok::annot_decltype:
2291  case tok::kw_decltype:
2292  DS.SetRangeEnd(ParseDecltypeSpecifier(DS));
2293  return DS.Finish(Actions, Policy);
2294 
2295  // GNU typeof support.
2296  case tok::kw_typeof:
2297  ParseTypeofSpecifier(DS);
2298  DS.Finish(Actions, Policy);
2299  return;
2300  }
2301  ConsumeAnyToken();
2302  DS.SetRangeEnd(PrevTokLocation);
2303  DS.Finish(Actions, Policy);
2304 }
2305 
2306 /// ParseCXXTypeSpecifierSeq - Parse a C++ type-specifier-seq (C++
2307 /// [dcl.name]), which is a non-empty sequence of type-specifiers,
2308 /// e.g., "const short int". Note that the DeclSpec is *not* finished
2309 /// by parsing the type-specifier-seq, because these sequences are
2310 /// typically followed by some form of declarator. Returns true and
2311 /// emits diagnostics if this is not a type-specifier-seq, false
2312 /// otherwise.
2313 ///
2314 /// type-specifier-seq: [C++ 8.1]
2315 /// type-specifier type-specifier-seq[opt]
2316 ///
2317 bool Parser::ParseCXXTypeSpecifierSeq(DeclSpec &DS) {
2318  ParseSpecifierQualifierList(DS, AS_none, DeclSpecContext::DSC_type_specifier);
2319  DS.Finish(Actions, Actions.getASTContext().getPrintingPolicy());
2320  return false;
2321 }
2322 
2323 /// Finish parsing a C++ unqualified-id that is a template-id of
2324 /// some form.
2325 ///
2326 /// This routine is invoked when a '<' is encountered after an identifier or
2327 /// operator-function-id is parsed by \c ParseUnqualifiedId() to determine
2328 /// whether the unqualified-id is actually a template-id. This routine will
2329 /// then parse the template arguments and form the appropriate template-id to
2330 /// return to the caller.
2331 ///
2332 /// \param SS the nested-name-specifier that precedes this template-id, if
2333 /// we're actually parsing a qualified-id.
2334 ///
2335 /// \param ObjectType if this unqualified-id occurs within a member access
2336 /// expression, the type of the base object whose member is being accessed.
2337 ///
2338 /// \param ObjectHadErrors this unqualified-id occurs within a member access
2339 /// expression, indicates whether the original subexpressions had any errors.
2340 ///
2341 /// \param Name for constructor and destructor names, this is the actual
2342 /// identifier that may be a template-name.
2343 ///
2344 /// \param NameLoc the location of the class-name in a constructor or
2345 /// destructor.
2346 ///
2347 /// \param EnteringContext whether we're entering the scope of the
2348 /// nested-name-specifier.
2349 ///
2350 /// \param Id as input, describes the template-name or operator-function-id
2351 /// that precedes the '<'. If template arguments were parsed successfully,
2352 /// will be updated with the template-id.
2353 ///
2354 /// \param AssumeTemplateId When true, this routine will assume that the name
2355 /// refers to a template without performing name lookup to verify.
2356 ///
2357 /// \returns true if a parse error occurred, false otherwise.
2358 bool Parser::ParseUnqualifiedIdTemplateId(
2359  CXXScopeSpec &SS, ParsedType ObjectType, bool ObjectHadErrors,
2360  SourceLocation TemplateKWLoc, IdentifierInfo *Name, SourceLocation NameLoc,
2361  bool EnteringContext, UnqualifiedId &Id, bool AssumeTemplateId) {
2362  assert(Tok.is(tok::less) && "Expected '<' to finish parsing a template-id");
2363 
2364  TemplateTy Template;
2366  switch (Id.getKind()) {
2370  if (AssumeTemplateId) {
2371  // We defer the injected-class-name checks until we've found whether
2372  // this template-id is used to form a nested-name-specifier or not.
2373  TNK = Actions.ActOnTemplateName(getCurScope(), SS, TemplateKWLoc, Id,
2374  ObjectType, EnteringContext, Template,
2375  /*AllowInjectedClassName*/ true);
2376  } else {
2377  bool MemberOfUnknownSpecialization;
2378  TNK = Actions.isTemplateName(getCurScope(), SS,
2379  TemplateKWLoc.isValid(), Id,
2380  ObjectType, EnteringContext, Template,
2381  MemberOfUnknownSpecialization);
2382  // If lookup found nothing but we're assuming that this is a template
2383  // name, double-check that makes sense syntactically before committing
2384  // to it.
2385  if (TNK == TNK_Undeclared_template &&
2386  isTemplateArgumentList(0) == TPResult::False)
2387  return false;
2388 
2389  if (TNK == TNK_Non_template && MemberOfUnknownSpecialization &&
2390  ObjectType && isTemplateArgumentList(0) == TPResult::True) {
2391  // If we had errors before, ObjectType can be dependent even without any
2392  // templates, do not report missing template keyword in that case.
2393  if (!ObjectHadErrors) {
2394  // We have something like t->getAs<T>(), where getAs is a
2395  // member of an unknown specialization. However, this will only
2396  // parse correctly as a template, so suggest the keyword 'template'
2397  // before 'getAs' and treat this as a dependent template name.
2398  std::string Name;
2399  if (Id.getKind() == UnqualifiedIdKind::IK_Identifier)
2400  Name = std::string(Id.Identifier->getName());
2401  else {
2402  Name = "operator ";
2404  Name += getOperatorSpelling(Id.OperatorFunctionId.Operator);
2405  else
2406  Name += Id.Identifier->getName();
2407  }
2408  Diag(Id.StartLocation, diag::err_missing_dependent_template_keyword)
2409  << Name
2410  << FixItHint::CreateInsertion(Id.StartLocation, "template ");
2411  }
2412  TNK = Actions.ActOnTemplateName(
2413  getCurScope(), SS, TemplateKWLoc, Id, ObjectType, EnteringContext,
2414  Template, /*AllowInjectedClassName*/ true);
2415  } else if (TNK == TNK_Non_template) {
2416  return false;
2417  }
2418  }
2419  break;
2420 
2423  bool MemberOfUnknownSpecialization;
2424  TemplateName.setIdentifier(Name, NameLoc);
2425  TNK = Actions.isTemplateName(getCurScope(), SS, TemplateKWLoc.isValid(),
2426  TemplateName, ObjectType,
2427  EnteringContext, Template,
2428  MemberOfUnknownSpecialization);
2429  if (TNK == TNK_Non_template)
2430  return false;
2431  break;
2432  }
2433 
2436  bool MemberOfUnknownSpecialization;
2437  TemplateName.setIdentifier(Name, NameLoc);
2438  if (ObjectType) {
2439  TNK = Actions.ActOnTemplateName(
2440  getCurScope(), SS, TemplateKWLoc, TemplateName, ObjectType,
2441  EnteringContext, Template, /*AllowInjectedClassName*/ true);
2442  } else {
2443  TNK = Actions.isTemplateName(getCurScope(), SS, TemplateKWLoc.isValid(),
2444  TemplateName, ObjectType,
2445  EnteringContext, Template,
2446  MemberOfUnknownSpecialization);
2447 
2448  if (TNK == TNK_Non_template && !Id.DestructorName.get()) {
2449  Diag(NameLoc, diag::err_destructor_template_id)
2450  << Name << SS.getRange();
2451  // Carry on to parse the template arguments before bailing out.
2452  }
2453  }
2454  break;
2455  }
2456 
2457  default:
2458  return false;
2459  }
2460 
2461  // Parse the enclosed template argument list.
2462  SourceLocation LAngleLoc, RAngleLoc;
2463  TemplateArgList TemplateArgs;
2464  if (ParseTemplateIdAfterTemplateName(true, LAngleLoc, TemplateArgs, RAngleLoc,
2465  Template))
2466  return true;
2467 
2468  // If this is a non-template, we already issued a diagnostic.
2469  if (TNK == TNK_Non_template)
2470  return true;
2471 
2472  if (Id.getKind() == UnqualifiedIdKind::IK_Identifier ||
2475  // Form a parsed representation of the template-id to be stored in the
2476  // UnqualifiedId.
2477 
2478  // FIXME: Store name for literal operator too.
2479  IdentifierInfo *TemplateII =
2480  Id.getKind() == UnqualifiedIdKind::IK_Identifier ? Id.Identifier
2481  : nullptr;
2482  OverloadedOperatorKind OpKind =
2484  ? OO_None
2485  : Id.OperatorFunctionId.Operator;
2486 
2488  TemplateKWLoc, Id.StartLocation, TemplateII, OpKind, Template, TNK,
2489  LAngleLoc, RAngleLoc, TemplateArgs, /*ArgsInvalid*/false, TemplateIds);
2490 
2491  Id.setTemplateId(TemplateId);
2492  return false;
2493  }
2494 
2495  // Bundle the template arguments together.
2496  ASTTemplateArgsPtr TemplateArgsPtr(TemplateArgs);
2497 
2498  // Constructor and destructor names.
2500  getCurScope(), SS, TemplateKWLoc, Template, Name, NameLoc, LAngleLoc,
2501  TemplateArgsPtr, RAngleLoc, /*IsCtorOrDtorName=*/true);
2502  if (Type.isInvalid())
2503  return true;
2504 
2505  if (Id.getKind() == UnqualifiedIdKind::IK_ConstructorName)
2506  Id.setConstructorName(Type.get(), NameLoc, RAngleLoc);
2507  else
2508  Id.setDestructorName(Id.StartLocation, Type.get(), RAngleLoc);
2509 
2510  return false;
2511 }
2512 
2513 /// Parse an operator-function-id or conversion-function-id as part
2514 /// of a C++ unqualified-id.
2515 ///
2516 /// This routine is responsible only for parsing the operator-function-id or
2517 /// conversion-function-id; it does not handle template arguments in any way.
2518 ///
2519 /// \code
2520 /// operator-function-id: [C++ 13.5]
2521 /// 'operator' operator
2522 ///
2523 /// operator: one of
2524 /// new delete new[] delete[]
2525 /// + - * / % ^ & | ~
2526 /// ! = < > += -= *= /= %=
2527 /// ^= &= |= << >> >>= <<= == !=
2528 /// <= >= && || ++ -- , ->* ->
2529 /// () [] <=>
2530 ///
2531 /// conversion-function-id: [C++ 12.3.2]
2532 /// operator conversion-type-id
2533 ///
2534 /// conversion-type-id:
2535 /// type-specifier-seq conversion-declarator[opt]
2536 ///
2537 /// conversion-declarator:
2538 /// ptr-operator conversion-declarator[opt]
2539 /// \endcode
2540 ///
2541 /// \param SS The nested-name-specifier that preceded this unqualified-id. If
2542 /// non-empty, then we are parsing the unqualified-id of a qualified-id.
2543 ///
2544 /// \param EnteringContext whether we are entering the scope of the
2545 /// nested-name-specifier.
2546 ///
2547 /// \param ObjectType if this unqualified-id occurs within a member access
2548 /// expression, the type of the base object whose member is being accessed.
2549 ///
2550 /// \param Result on a successful parse, contains the parsed unqualified-id.
2551 ///
2552 /// \returns true if parsing fails, false otherwise.
2553 bool Parser::ParseUnqualifiedIdOperator(CXXScopeSpec &SS, bool EnteringContext,
2554  ParsedType ObjectType,
2555  UnqualifiedId &Result) {
2556  assert(Tok.is(tok::kw_operator) && "Expected 'operator' keyword");
2557 
2558  // Consume the 'operator' keyword.
2559  SourceLocation KeywordLoc = ConsumeToken();
2560 
2561  // Determine what kind of operator name we have.
2562  unsigned SymbolIdx = 0;
2563  SourceLocation SymbolLocations[3];
2565  switch (Tok.getKind()) {
2566  case tok::kw_new:
2567  case tok::kw_delete: {
2568  bool isNew = Tok.getKind() == tok::kw_new;
2569  // Consume the 'new' or 'delete'.
2570  SymbolLocations[SymbolIdx++] = ConsumeToken();
2571  // Check for array new/delete.
2572  if (Tok.is(tok::l_square) &&
2573  (!getLangOpts().CPlusPlus11 || NextToken().isNot(tok::l_square))) {
2574  // Consume the '[' and ']'.
2575  BalancedDelimiterTracker T(*this, tok::l_square);
2576  T.consumeOpen();
2577  T.consumeClose();
2578  if (T.getCloseLocation().isInvalid())
2579  return true;
2580 
2581  SymbolLocations[SymbolIdx++] = T.getOpenLocation();
2582  SymbolLocations[SymbolIdx++] = T.getCloseLocation();
2583  Op = isNew? OO_Array_New : OO_Array_Delete;
2584  } else {
2585  Op = isNew? OO_New : OO_Delete;
2586  }
2587  break;
2588  }
2589 
2590 #define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
2591  case tok::Token: \
2592  SymbolLocations[SymbolIdx++] = ConsumeToken(); \
2593  Op = OO_##Name; \
2594  break;
2595 #define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
2596 #include "clang/Basic/OperatorKinds.def"
2597 
2598  case tok::l_paren: {
2599  // Consume the '(' and ')'.
2600  BalancedDelimiterTracker T(*this, tok::l_paren);
2601  T.consumeOpen();
2602  T.consumeClose();
2603  if (T.getCloseLocation().isInvalid())
2604  return true;
2605 
2606  SymbolLocations[SymbolIdx++] = T.getOpenLocation();
2607  SymbolLocations[SymbolIdx++] = T.getCloseLocation();
2608  Op = OO_Call;
2609  break;
2610  }
2611 
2612  case tok::l_square: {
2613  // Consume the '[' and ']'.
2614  BalancedDelimiterTracker T(*this, tok::l_square);
2615  T.consumeOpen();
2616  T.consumeClose();
2617  if (T.getCloseLocation().isInvalid())
2618  return true;
2619 
2620  SymbolLocations[SymbolIdx++] = T.getOpenLocation();
2621  SymbolLocations[SymbolIdx++] = T.getCloseLocation();
2622  Op = OO_Subscript;
2623  break;
2624  }
2625 
2626  case tok::code_completion: {
2627  // Don't try to parse any further.
2628  cutOffParsing();
2629  // Code completion for the operator name.
2631  return true;
2632  }
2633 
2634  default:
2635  break;
2636  }
2637 
2638  if (Op != OO_None) {
2639  // We have parsed an operator-function-id.
2640  Result.setOperatorFunctionId(KeywordLoc, Op, SymbolLocations);
2641  return false;
2642  }
2643 
2644  // Parse a literal-operator-id.
2645  //
2646  // literal-operator-id: C++11 [over.literal]
2647  // operator string-literal identifier
2648  // operator user-defined-string-literal
2649 
2650  if (getLangOpts().CPlusPlus11 && isTokenStringLiteral()) {
2651  Diag(Tok.getLocation(), diag::warn_cxx98_compat_literal_operator);
2652 
2653  SourceLocation DiagLoc;
2654  unsigned DiagId = 0;
2655 
2656  // We're past translation phase 6, so perform string literal concatenation
2657  // before checking for "".
2658  SmallVector<Token, 4> Toks;
2660  while (isTokenStringLiteral()) {
2661  if (!Tok.is(tok::string_literal) && !DiagId) {
2662  // C++11 [over.literal]p1:
2663  // The string-literal or user-defined-string-literal in a
2664  // literal-operator-id shall have no encoding-prefix [...].
2665  DiagLoc = Tok.getLocation();
2666  DiagId = diag::err_literal_operator_string_prefix;
2667  }
2668  Toks.push_back(Tok);
2669  TokLocs.push_back(ConsumeStringToken());
2670  }
2671 
2672  StringLiteralParser Literal(Toks, PP);
2673  if (Literal.hadError)
2674  return true;
2675 
2676  // Grab the literal operator's suffix, which will be either the next token
2677  // or a ud-suffix from the string literal.
2678  bool IsUDSuffix = !Literal.getUDSuffix().empty();
2679  IdentifierInfo *II = nullptr;
2680  SourceLocation SuffixLoc;
2681  if (IsUDSuffix) {
2682  II = &PP.getIdentifierTable().get(Literal.getUDSuffix());
2683  SuffixLoc =
2684  Lexer::AdvanceToTokenCharacter(TokLocs[Literal.getUDSuffixToken()],
2685  Literal.getUDSuffixOffset(),
2686  PP.getSourceManager(), getLangOpts());
2687  } else if (Tok.is(tok::identifier)) {
2688  II = Tok.getIdentifierInfo();
2689  SuffixLoc = ConsumeToken();
2690  TokLocs.push_back(SuffixLoc);
2691  } else {
2692  Diag(Tok.getLocation(), diag::err_expected) << tok::identifier;
2693  return true;
2694  }
2695 
2696  // The string literal must be empty.
2697  if (!Literal.GetString().empty() || Literal.Pascal) {
2698  // C++11 [over.literal]p1:
2699  // The string-literal or user-defined-string-literal in a
2700  // literal-operator-id shall [...] contain no characters
2701  // other than the implicit terminating '\0'.
2702  DiagLoc = TokLocs.front();
2703  DiagId = diag::err_literal_operator_string_not_empty;
2704  }
2705 
2706  if (DiagId) {
2707  // This isn't a valid literal-operator-id, but we think we know
2708  // what the user meant. Tell them what they should have written.
2709  SmallString<32> Str;
2710  Str += "\"\"";
2711  Str += II->getName();
2712  Diag(DiagLoc, DiagId) << FixItHint::CreateReplacement(
2713  SourceRange(TokLocs.front(), TokLocs.back()), Str);
2714  }
2715 
2716  Result.setLiteralOperatorId(II, KeywordLoc, SuffixLoc);
2717 
2718  return Actions.checkLiteralOperatorId(SS, Result, IsUDSuffix);
2719  }
2720 
2721  // Parse a conversion-function-id.
2722  //
2723  // conversion-function-id: [C++ 12.3.2]
2724  // operator conversion-type-id
2725  //
2726  // conversion-type-id:
2727  // type-specifier-seq conversion-declarator[opt]
2728  //
2729  // conversion-declarator:
2730  // ptr-operator conversion-declarator[opt]
2731 
2732  // Parse the type-specifier-seq.
2733  DeclSpec DS(AttrFactory);
2734  if (ParseCXXTypeSpecifierSeq(DS)) // FIXME: ObjectType?
2735  return true;
2736 
2737  // Parse the conversion-declarator, which is merely a sequence of
2738  // ptr-operators.
2740  ParseDeclaratorInternal(D, /*DirectDeclParser=*/nullptr);
2741 
2742  // Finish up the type.
2743  TypeResult Ty = Actions.ActOnTypeName(getCurScope(), D);
2744  if (Ty.isInvalid())
2745  return true;
2746 
2747  // Note that this is a conversion-function-id.
2748  Result.setConversionFunctionId(KeywordLoc, Ty.get(),
2749  D.getSourceRange().getEnd());
2750  return false;
2751 }
2752 
2753 /// Parse a C++ unqualified-id (or a C identifier), which describes the
2754 /// name of an entity.
2755 ///
2756 /// \code
2757 /// unqualified-id: [C++ expr.prim.general]
2758 /// identifier
2759 /// operator-function-id
2760 /// conversion-function-id
2761 /// [C++0x] literal-operator-id [TODO]
2762 /// ~ class-name
2763 /// template-id
2764 ///
2765 /// \endcode
2766 ///
2767 /// \param SS The nested-name-specifier that preceded this unqualified-id. If
2768 /// non-empty, then we are parsing the unqualified-id of a qualified-id.
2769 ///
2770 /// \param ObjectType if this unqualified-id occurs within a member access
2771 /// expression, the type of the base object whose member is being accessed.
2772 ///
2773 /// \param ObjectHadErrors if this unqualified-id occurs within a member access
2774 /// expression, indicates whether the original subexpressions had any errors.
2775 /// When true, diagnostics for missing 'template' keyword will be supressed.
2776 ///
2777 /// \param EnteringContext whether we are entering the scope of the
2778 /// nested-name-specifier.
2779 ///
2780 /// \param AllowDestructorName whether we allow parsing of a destructor name.
2781 ///
2782 /// \param AllowConstructorName whether we allow parsing a constructor name.
2783 ///
2784 /// \param AllowDeductionGuide whether we allow parsing a deduction guide name.
2785 ///
2786 /// \param Result on a successful parse, contains the parsed unqualified-id.
2787 ///
2788 /// \returns true if parsing fails, false otherwise.
2790  bool ObjectHadErrors, bool EnteringContext,
2791  bool AllowDestructorName,
2792  bool AllowConstructorName,
2793  bool AllowDeductionGuide,
2794  SourceLocation *TemplateKWLoc,
2795  UnqualifiedId &Result) {
2796  if (TemplateKWLoc)
2797  *TemplateKWLoc = SourceLocation();
2798 
2799  // Handle 'A::template B'. This is for template-ids which have not
2800  // already been annotated by ParseOptionalCXXScopeSpecifier().
2801  bool TemplateSpecified = false;
2802  if (Tok.is(tok::kw_template)) {
2803  if (TemplateKWLoc && (ObjectType || SS.isSet())) {
2804  TemplateSpecified = true;
2805  *TemplateKWLoc = ConsumeToken();
2806  } else {
2807  SourceLocation TemplateLoc = ConsumeToken();
2808  Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2809  << FixItHint::CreateRemoval(TemplateLoc);
2810  }
2811  }
2812 
2813  // unqualified-id:
2814  // identifier
2815  // template-id (when it hasn't already been annotated)
2816  if (Tok.is(tok::identifier)) {
2817  // Consume the identifier.
2819  SourceLocation IdLoc = ConsumeToken();
2820 
2821  if (!getLangOpts().CPlusPlus) {
2822  // If we're not in C++, only identifiers matter. Record the
2823  // identifier and return.
2824  Result.setIdentifier(Id, IdLoc);
2825  return false;
2826  }
2827 
2829  if (AllowConstructorName &&
2830  Actions.isCurrentClassName(*Id, getCurScope(), &SS)) {
2831  // We have parsed a constructor name.
2832  ParsedType Ty = Actions.getConstructorName(*Id, IdLoc, getCurScope(), SS,
2833  EnteringContext);
2834  if (!Ty)
2835  return true;
2836  Result.setConstructorName(Ty, IdLoc, IdLoc);
2837  } else if (getLangOpts().CPlusPlus17 &&
2838  AllowDeductionGuide && SS.isEmpty() &&
2839  Actions.isDeductionGuideName(getCurScope(), *Id, IdLoc,
2840  &TemplateName)) {
2841  // We have parsed a template-name naming a deduction guide.
2842  Result.setDeductionGuideName(TemplateName, IdLoc);
2843  } else {
2844  // We have parsed an identifier.
2845  Result.setIdentifier(Id, IdLoc);
2846  }
2847 
2848  // If the next token is a '<', we may have a template.
2849  TemplateTy Template;
2850  if (Tok.is(tok::less))
2851  return ParseUnqualifiedIdTemplateId(
2852  SS, ObjectType, ObjectHadErrors,
2853  TemplateKWLoc ? *TemplateKWLoc : SourceLocation(), Id, IdLoc,
2854  EnteringContext, Result, TemplateSpecified);
2855  else if (TemplateSpecified &&
2856  Actions.ActOnTemplateName(
2857  getCurScope(), SS, *TemplateKWLoc, Result, ObjectType,
2858  EnteringContext, Template,
2859  /*AllowInjectedClassName*/ true) == TNK_Non_template)
2860  return true;
2861 
2862  return false;
2863  }
2864 
2865  // unqualified-id:
2866  // template-id (already parsed and annotated)
2867  if (Tok.is(tok::annot_template_id)) {
2868  TemplateIdAnnotation *TemplateId = takeTemplateIdAnnotation(Tok);
2869 
2870  // FIXME: Consider passing invalid template-ids on to callers; they may
2871  // be able to recover better than we can.
2872  if (TemplateId->isInvalid()) {
2873  ConsumeAnnotationToken();
2874  return true;
2875  }
2876 
2877  // If the template-name names the current class, then this is a constructor
2878  if (AllowConstructorName && TemplateId->Name &&
2879  Actions.isCurrentClassName(*TemplateId->Name, getCurScope(), &SS)) {
2880  if (SS.isSet()) {
2881  // C++ [class.qual]p2 specifies that a qualified template-name
2882  // is taken as the constructor name where a constructor can be
2883  // declared. Thus, the template arguments are extraneous, so
2884  // complain about them and remove them entirely.
2885  Diag(TemplateId->TemplateNameLoc,
2886  diag::err_out_of_line_constructor_template_id)
2887  << TemplateId->Name
2889  SourceRange(TemplateId->LAngleLoc, TemplateId->RAngleLoc));
2890  ParsedType Ty = Actions.getConstructorName(
2891  *TemplateId->Name, TemplateId->TemplateNameLoc, getCurScope(), SS,
2892  EnteringContext);
2893  if (!Ty)
2894  return true;
2895  Result.setConstructorName(Ty, TemplateId->TemplateNameLoc,
2896  TemplateId->RAngleLoc);
2897  ConsumeAnnotationToken();
2898  return false;
2899  }
2900 
2901  Result.setConstructorTemplateId(TemplateId);
2902  ConsumeAnnotationToken();
2903  return false;
2904  }
2905 
2906  // We have already parsed a template-id; consume the annotation token as
2907  // our unqualified-id.
2908  Result.setTemplateId(TemplateId);
2909  SourceLocation TemplateLoc = TemplateId->TemplateKWLoc;
2910  if (TemplateLoc.isValid()) {
2911  if (TemplateKWLoc && (ObjectType || SS.isSet()))
2912  *TemplateKWLoc = TemplateLoc;
2913  else
2914  Diag(TemplateLoc, diag::err_unexpected_template_in_unqualified_id)
2915  << FixItHint::CreateRemoval(TemplateLoc);
2916  }
2917  ConsumeAnnotationToken();
2918  return false;
2919  }
2920 
2921  // unqualified-id:
2922  // operator-function-id
2923  // conversion-function-id
2924  if (Tok.is(tok::kw_operator)) {
2925  if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType, Result))
2926  return true;
2927 
2928  // If we have an operator-function-id or a literal-operator-id and the next
2929  // token is a '<', we may have a
2930  //
2931  // template-id:
2932  // operator-function-id < template-argument-list[opt] >
2933  TemplateTy Template;
2936  Tok.is(tok::less))
2937  return ParseUnqualifiedIdTemplateId(
2938  SS, ObjectType, ObjectHadErrors,
2939  TemplateKWLoc ? *TemplateKWLoc : SourceLocation(), nullptr,
2940  SourceLocation(), EnteringContext, Result, TemplateSpecified);
2941  else if (TemplateSpecified &&
2942  Actions.ActOnTemplateName(
2943  getCurScope(), SS, *TemplateKWLoc, Result, ObjectType,
2944  EnteringContext, Template,
2945  /*AllowInjectedClassName*/ true) == TNK_Non_template)
2946  return true;
2947 
2948  return false;
2949  }
2950 
2951  if (getLangOpts().CPlusPlus &&
2952  (AllowDestructorName || SS.isSet()) && Tok.is(tok::tilde)) {
2953  // C++ [expr.unary.op]p10:
2954  // There is an ambiguity in the unary-expression ~X(), where X is a
2955  // class-name. The ambiguity is resolved in favor of treating ~ as a
2956  // unary complement rather than treating ~X as referring to a destructor.
2957 
2958  // Parse the '~'.
2959  SourceLocation TildeLoc = ConsumeToken();
2960 
2961  if (TemplateSpecified) {
2962  // C++ [temp.names]p3:
2963  // A name prefixed by the keyword template shall be a template-id [...]
2964  //
2965  // A template-id cannot begin with a '~' token. This would never work
2966  // anyway: x.~A<int>() would specify that the destructor is a template,
2967  // not that 'A' is a template.
2968  //
2969  // FIXME: Suggest replacing the attempted destructor name with a correct
2970  // destructor name and recover. (This is not trivial if this would become
2971  // a pseudo-destructor name).
2972  Diag(*TemplateKWLoc, diag::err_unexpected_template_in_destructor_name)
2973  << Tok.getLocation();
2974  return true;
2975  }
2976 
2977  if (SS.isEmpty() && Tok.is(tok::kw_decltype)) {
2978  DeclSpec DS(AttrFactory);
2979  SourceLocation EndLoc = ParseDecltypeSpecifier(DS);
2980  if (ParsedType Type =
2981  Actions.getDestructorTypeForDecltype(DS, ObjectType)) {
2982  Result.setDestructorName(TildeLoc, Type, EndLoc);
2983  return false;
2984  }
2985  return true;
2986  }
2987 
2988  // Parse the class-name.
2989  if (Tok.isNot(tok::identifier)) {
2990  Diag(Tok, diag::err_destructor_tilde_identifier);
2991  return true;
2992  }
2993 
2994  // If the user wrote ~T::T, correct it to T::~T.
2995  DeclaratorScopeObj DeclScopeObj(*this, SS);
2996  if (NextToken().is(tok::coloncolon)) {
2997  // Don't let ParseOptionalCXXScopeSpecifier() "correct"
2998  // `int A; struct { ~A::A(); };` to `int A; struct { ~A:A(); };`,
2999  // it will confuse this recovery logic.
3000  ColonProtectionRAIIObject ColonRAII(*this, false);
3001 
3002  if (SS.isSet()) {
3003  AnnotateScopeToken(SS, /*NewAnnotation*/true);
3004  SS.clear();
3005  }
3006  if (ParseOptionalCXXScopeSpecifier(SS, ObjectType, ObjectHadErrors,
3007  EnteringContext))
3008  return true;
3009  if (SS.isNotEmpty())
3010  ObjectType = nullptr;
3011  if (Tok.isNot(tok::identifier) || NextToken().is(tok::coloncolon) ||
3012  !SS.isSet()) {
3013  Diag(TildeLoc, diag::err_destructor_tilde_scope);
3014  return true;
3015  }
3016 
3017  // Recover as if the tilde had been written before the identifier.
3018  Diag(TildeLoc, diag::err_destructor_tilde_scope)
3019  << FixItHint::CreateRemoval(TildeLoc)
3020  << FixItHint::CreateInsertion(Tok.getLocation(), "~");
3021 
3022  // Temporarily enter the scope for the rest of this function.
3023  if (Actions.ShouldEnterDeclaratorScope(getCurScope(), SS))
3024  DeclScopeObj.EnterDeclaratorScope();
3025  }
3026 
3027  // Parse the class-name (or template-name in a simple-template-id).
3028  IdentifierInfo *ClassName = Tok.getIdentifierInfo();
3029  SourceLocation ClassNameLoc = ConsumeToken();
3030 
3031  if (Tok.is(tok::less)) {
3032  Result.setDestructorName(TildeLoc, nullptr, ClassNameLoc);
3033  return ParseUnqualifiedIdTemplateId(
3034  SS, ObjectType, ObjectHadErrors,
3035  TemplateKWLoc ? *TemplateKWLoc : SourceLocation(), ClassName,
3036  ClassNameLoc, EnteringContext, Result, TemplateSpecified);
3037  }
3038 
3039  // Note that this is a destructor name.
3040  ParsedType Ty = Actions.getDestructorName(TildeLoc, *ClassName,
3041  ClassNameLoc, getCurScope(),
3042  SS, ObjectType,
3043  EnteringContext);
3044  if (!Ty)
3045  return true;
3046 
3047  Result.setDestructorName(TildeLoc, Ty, ClassNameLoc);
3048  return false;
3049  }
3050 
3051  Diag(Tok, diag::err_expected_unqualified_id)
3052  << getLangOpts().CPlusPlus;
3053  return true;
3054 }
3055 
3056 /// ParseCXXNewExpression - Parse a C++ new-expression. New is used to allocate
3057 /// memory in a typesafe manner and call constructors.
3058 ///
3059 /// This method is called to parse the new expression after the optional :: has
3060 /// been already parsed. If the :: was present, "UseGlobal" is true and "Start"
3061 /// is its location. Otherwise, "Start" is the location of the 'new' token.
3062 ///
3063 /// new-expression:
3064 /// '::'[opt] 'new' new-placement[opt] new-type-id
3065 /// new-initializer[opt]
3066 /// '::'[opt] 'new' new-placement[opt] '(' type-id ')'
3067 /// new-initializer[opt]
3068 ///
3069 /// new-placement:
3070 /// '(' expression-list ')'
3071 ///
3072 /// new-type-id:
3073 /// type-specifier-seq new-declarator[opt]
3074 /// [GNU] attributes type-specifier-seq new-declarator[opt]
3075 ///
3076 /// new-declarator:
3077 /// ptr-operator new-declarator[opt]
3078 /// direct-new-declarator
3079 ///
3080 /// new-initializer:
3081 /// '(' expression-list[opt] ')'
3082 /// [C++0x] braced-init-list
3083 ///
3084 ExprResult
3085 Parser::ParseCXXNewExpression(bool UseGlobal, SourceLocation Start) {
3086  assert(Tok.is(tok::kw_new) && "expected 'new' token");
3087  ConsumeToken(); // Consume 'new'
3088 
3089  // A '(' now can be a new-placement or the '(' wrapping the type-id in the
3090  // second form of new-expression. It can't be a new-type-id.
3091 
3092  ExprVector PlacementArgs;
3093  SourceLocation PlacementLParen, PlacementRParen;
3094 
3095  SourceRange TypeIdParens;
3096  DeclSpec DS(AttrFactory);
3097  Declarator DeclaratorInfo(DS, DeclaratorContext::CXXNew);
3098  if (Tok.is(tok::l_paren)) {
3099  // If it turns out to be a placement, we change the type location.
3100  BalancedDelimiterTracker T(*this, tok::l_paren);
3101  T.consumeOpen();
3102  PlacementLParen = T.getOpenLocation();
3103  if (ParseExpressionListOrTypeId(PlacementArgs, DeclaratorInfo)) {
3104  SkipUntil(tok::semi, StopAtSemi | StopBeforeMatch);
3105  return ExprError();
3106  }
3107 
3108  T.consumeClose();
3109  PlacementRParen = T.getCloseLocation();
3110  if (PlacementRParen.isInvalid()) {
3111  SkipUntil(tok::semi, StopAtSemi | StopBeforeMatch);
3112  return ExprError();
3113  }
3114 
3115  if (PlacementArgs.empty()) {
3116  // Reset the placement locations. There was no placement.
3117  TypeIdParens = T.getRange();
3118  PlacementLParen = PlacementRParen = SourceLocation();
3119  } else {
3120  // We still need the type.
3121  if (Tok.is(tok::l_paren)) {
3122  BalancedDelimiterTracker T(*this, tok::l_paren);
3123  T.consumeOpen();
3124  MaybeParseGNUAttributes(DeclaratorInfo);
3125  ParseSpecifierQualifierList(DS);
3126  DeclaratorInfo.SetSourceRange(DS.getSourceRange());
3127  ParseDeclarator(DeclaratorInfo);
3128  T.consumeClose();
3129  TypeIdParens = T.getRange();
3130  } else {
3131  MaybeParseGNUAttributes(DeclaratorInfo);
3132  if (ParseCXXTypeSpecifierSeq(DS))
3133  DeclaratorInfo.setInvalidType(true);
3134  else {
3135  DeclaratorInfo.SetSourceRange(DS.getSourceRange());
3136  ParseDeclaratorInternal(DeclaratorInfo,
3137  &Parser::ParseDirectNewDeclarator);
3138  }
3139  }
3140  }
3141  } else {
3142  // A new-type-id is a simplified type-id, where essentially the
3143  // direct-declarator is replaced by a direct-new-declarator.
3144  MaybeParseGNUAttributes(DeclaratorInfo);
3145  if (ParseCXXTypeSpecifierSeq(DS))
3146  DeclaratorInfo.setInvalidType(true);
3147  else {
3148  DeclaratorInfo.SetSourceRange(DS.getSourceRange());
3149  ParseDeclaratorInternal(DeclaratorInfo,
3150  &Parser::ParseDirectNewDeclarator);
3151  }
3152  }
3153  if (DeclaratorInfo.isInvalidType()) {
3154  SkipUntil(tok::semi, StopAtSemi | StopBeforeMatch);
3155  return ExprError();
3156  }
3157 
3159 
3160  if (Tok.is(tok::l_paren)) {
3161  SourceLocation ConstructorLParen, ConstructorRParen;
3162  ExprVector ConstructorArgs;
3163  BalancedDelimiterTracker T(*this, tok::l_paren);
3164  T.consumeOpen();
3165  ConstructorLParen = T.getOpenLocation();
3166  if (Tok.isNot(tok::r_paren)) {
3167  CommaLocsTy CommaLocs;
3168  auto RunSignatureHelp = [&]() {
3169  ParsedType TypeRep =
3170  Actions.ActOnTypeName(getCurScope(), DeclaratorInfo).get();
3171  QualType PreferredType;
3172  // ActOnTypeName might adjust DeclaratorInfo and return a null type even
3173  // the passing DeclaratorInfo is valid, e.g. running SignatureHelp on
3174  // `new decltype(invalid) (^)`.
3175  if (TypeRep)
3176  PreferredType = Actions.ProduceConstructorSignatureHelp(
3177  TypeRep.get()->getCanonicalTypeInternal(),
3178  DeclaratorInfo.getEndLoc(), ConstructorArgs, ConstructorLParen,
3179  /*Braced=*/false);
3180  CalledSignatureHelp = true;
3181  return PreferredType;
3182  };
3183  if (ParseExpressionList(ConstructorArgs, CommaLocs, [&] {
3184  PreferredType.enterFunctionArgument(Tok.getLocation(),
3185  RunSignatureHelp);
3186  })) {
3187  if (PP.isCodeCompletionReached() && !CalledSignatureHelp)
3188  RunSignatureHelp();
3189  SkipUntil(tok::semi, StopAtSemi | StopBeforeMatch);
3190  return ExprError();
3191  }
3192  }
3193  T.consumeClose();
3194  ConstructorRParen = T.getCloseLocation();
3195  if (ConstructorRParen.isInvalid()) {
3196  SkipUntil(tok::semi, StopAtSemi | StopBeforeMatch);
3197  return ExprError();
3198  }
3199  Initializer = Actions.ActOnParenListExpr(ConstructorLParen,
3200  ConstructorRParen,
3201  ConstructorArgs);
3202  } else if (Tok.is(tok::l_brace) && getLangOpts().CPlusPlus11) {
3203  Diag(Tok.getLocation(),
3204  diag::warn_cxx98_compat_generalized_initializer_lists);
3205  Initializer = ParseBraceInitializer();
3206  }
3207  if (Initializer.isInvalid())
3208  return Initializer;
3209 
3210  return Actions.ActOnCXXNew(Start, UseGlobal, PlacementLParen,
3211  PlacementArgs, PlacementRParen,
3212  TypeIdParens, DeclaratorInfo, Initializer.get());
3213 }
3214 
3215 /// ParseDirectNewDeclarator - Parses a direct-new-declarator. Intended to be
3216 /// passed to ParseDeclaratorInternal.
3217 ///
3218 /// direct-new-declarator:
3219 /// '[' expression[opt] ']'
3220 /// direct-new-declarator '[' constant-expression ']'
3221 ///
3222 void Parser::ParseDirectNewDeclarator(Declarator &D) {
3223  // Parse the array dimensions.
3224  bool First = true;
3225  while (Tok.is(tok::l_square)) {
3226  // An array-size expression can't start with a lambda.
3227  if (CheckProhibitedCXX11Attribute())
3228  continue;
3229 
3230  BalancedDelimiterTracker T(*this, tok::l_square);
3231  T.consumeOpen();
3232 
3233  ExprResult Size =
3234  First ? (Tok.is(tok::r_square) ? ExprResult() : ParseExpression())
3236  if (Size.isInvalid()) {
3237  // Recover
3238  SkipUntil(tok::r_square, StopAtSemi);
3239  return;
3240  }
3241  First = false;
3242 
3243  T.consumeClose();
3244 
3245  // Attributes here appertain to the array type. C++11 [expr.new]p5.
3246  ParsedAttributes Attrs(AttrFactory);
3247  MaybeParseCXX11Attributes(Attrs);
3248 
3250  /*isStatic=*/false, /*isStar=*/false,
3251  Size.get(), T.getOpenLocation(),
3252  T.getCloseLocation()),
3253  std::move(Attrs), T.getCloseLocation());
3254 
3255  if (T.getCloseLocation().isInvalid())
3256  return;
3257  }
3258 }
3259 
3260 /// ParseExpressionListOrTypeId - Parse either an expression-list or a type-id.
3261 /// This ambiguity appears in the syntax of the C++ new operator.
3262 ///
3263 /// new-expression:
3264 /// '::'[opt] 'new' new-placement[opt] '(' type-id ')'
3265 /// new-initializer[opt]
3266 ///
3267 /// new-placement:
3268 /// '(' expression-list ')'
3269 ///
3270 bool Parser::ParseExpressionListOrTypeId(
3271  SmallVectorImpl<Expr*> &PlacementArgs,
3272  Declarator &D) {
3273  // The '(' was already consumed.
3274  if (isTypeIdInParens()) {
3275  ParseSpecifierQualifierList(D.getMutableDeclSpec());
3277  ParseDeclarator(D);
3278  return D.isInvalidType();
3279  }
3280 
3281  // It's not a type, it has to be an expression list.
3282  // Discard the comma locations - ActOnCXXNew has enough parameters.
3283  CommaLocsTy CommaLocs;
3284  return ParseExpressionList(PlacementArgs, CommaLocs);
3285 }
3286 
3287 /// ParseCXXDeleteExpression - Parse a C++ delete-expression. Delete is used
3288 /// to free memory allocated by new.
3289 ///
3290 /// This method is called to parse the 'delete' expression after the optional
3291 /// '::' has been already parsed. If the '::' was present, "UseGlobal" is true
3292 /// and "Start" is its location. Otherwise, "Start" is the location of the
3293 /// 'delete' token.
3294 ///
3295 /// delete-expression:
3296 /// '::'[opt] 'delete' cast-expression
3297 /// '::'[opt] 'delete' '[' ']' cast-expression
3298 ExprResult
3299 Parser::ParseCXXDeleteExpression(bool UseGlobal, SourceLocation Start) {
3300  assert(Tok.is(tok::kw_delete) && "Expected 'delete' keyword");
3301  ConsumeToken(); // Consume 'delete'
3302 
3303  // Array delete?
3304  bool ArrayDelete = false;
3305  if (Tok.is(tok::l_square) && NextToken().is(tok::r_square)) {
3306  // C++11 [expr.delete]p1:
3307  // Whenever the delete keyword is followed by empty square brackets, it
3308  // shall be interpreted as [array delete].
3309  // [Footnote: A lambda expression with a lambda-introducer that consists
3310  // of empty square brackets can follow the delete keyword if
3311  // the lambda expression is enclosed in parentheses.]
3312 
3313  const Token Next = GetLookAheadToken(2);
3314 
3315  // Basic lookahead to check if we have a lambda expression.
3316  if (Next.isOneOf(tok::l_brace, tok::less) ||
3317  (Next.is(tok::l_paren) &&
3318  (GetLookAheadToken(3).is(tok::r_paren) ||
3319  (GetLookAheadToken(3).is(tok::identifier) &&
3320  GetLookAheadToken(4).is(tok::identifier))))) {
3321  TentativeParsingAction TPA(*this);
3322  SourceLocation LSquareLoc = Tok.getLocation();
3323  SourceLocation RSquareLoc = NextToken().getLocation();
3324 
3325  // SkipUntil can't skip pairs of </*...*/>; don't emit a FixIt in this
3326  // case.
3327  SkipUntil({tok::l_brace, tok::less}, StopBeforeMatch);
3328  SourceLocation RBraceLoc;
3329  bool EmitFixIt = false;
3330  if (Tok.is(tok::l_brace)) {
3331  ConsumeBrace();
3332  SkipUntil(tok::r_brace, StopBeforeMatch);
3333  RBraceLoc = Tok.getLocation();
3334  EmitFixIt = true;
3335  }
3336 
3337  TPA.Revert();
3338 
3339  if (EmitFixIt)
3340  Diag(Start, diag::err_lambda_after_delete)
3341  << SourceRange(Start, RSquareLoc)
3342  << FixItHint::CreateInsertion(LSquareLoc, "(")
3345  RBraceLoc, 0, Actions.getSourceManager(), getLangOpts()),
3346  ")");
3347  else
3348  Diag(Start, diag::err_lambda_after_delete)
3349  << SourceRange(Start, RSquareLoc);
3350 
3351  // Warn that the non-capturing lambda isn't surrounded by parentheses
3352  // to disambiguate it from 'delete[]'.
3353  ExprResult Lambda = ParseLambdaExpression();
3354  if (Lambda.isInvalid())
3355  return ExprError();
3356 
3357  // Evaluate any postfix expressions used on the lambda.
3358  Lambda = ParsePostfixExpressionSuffix(Lambda);
3359  if (Lambda.isInvalid())
3360  return ExprError();
3361  return Actions.ActOnCXXDelete(Start, UseGlobal, /*ArrayForm=*/false,
3362  Lambda.get());
3363  }
3364 
3365  ArrayDelete = true;
3366  BalancedDelimiterTracker T(*this, tok::l_square);
3367 
3368  T.consumeOpen();
3369  T.consumeClose();
3370  if (T.getCloseLocation().isInvalid())
3371  return ExprError();
3372  }
3373 
3374  ExprResult Operand(ParseCastExpression(AnyCastExpr));
3375  if (Operand.isInvalid())
3376  return Operand;
3377 
3378  return Actions.ActOnCXXDelete(Start, UseGlobal, ArrayDelete, Operand.get());
3379 }
3380 
3381 /// ParseRequiresExpression - Parse a C++2a requires-expression.
3382 /// C++2a [expr.prim.req]p1
3383 /// A requires-expression provides a concise way to express requirements on
3384 /// template arguments. A requirement is one that can be checked by name
3385 /// lookup (6.4) or by checking properties of types and expressions.
3386 ///
3387 /// requires-expression:
3388 /// 'requires' requirement-parameter-list[opt] requirement-body
3389 ///
3390 /// requirement-parameter-list:
3391 /// '(' parameter-declaration-clause[opt] ')'
3392 ///
3393 /// requirement-body:
3394 /// '{' requirement-seq '}'
3395 ///
3396 /// requirement-seq:
3397 /// requirement
3398 /// requirement-seq requirement
3399 ///
3400 /// requirement:
3401 /// simple-requirement
3402 /// type-requirement
3403 /// compound-requirement
3404 /// nested-requirement
3405 ExprResult Parser::ParseRequiresExpression() {
3406  assert(Tok.is(tok::kw_requires) && "Expected 'requires' keyword");
3407  SourceLocation RequiresKWLoc = ConsumeToken(); // Consume 'requires'
3408 
3409  llvm::SmallVector<ParmVarDecl *, 2> LocalParameterDecls;
3410  if (Tok.is(tok::l_paren)) {
3411  // requirement parameter list is present.
3412  ParseScope LocalParametersScope(this, Scope::FunctionPrototypeScope |
3414  BalancedDelimiterTracker Parens(*this, tok::l_paren);
3415  Parens.consumeOpen();
3416  if (!Tok.is(tok::r_paren)) {
3417  ParsedAttributes FirstArgAttrs(getAttrFactory());
3418  SourceLocation EllipsisLoc;
3420  ParseParameterDeclarationClause(DeclaratorContext::RequiresExpr,
3421  FirstArgAttrs, LocalParameters,
3422  EllipsisLoc);
3423  if (EllipsisLoc.isValid())
3424  Diag(EllipsisLoc, diag::err_requires_expr_parameter_list_ellipsis);
3425  for (auto &ParamInfo : LocalParameters)
3426  LocalParameterDecls.push_back(cast<ParmVarDecl>(ParamInfo.Param));
3427  }
3428  Parens.consumeClose();
3429  }
3430 
3431  BalancedDelimiterTracker Braces(*this, tok::l_brace);
3432  if (Braces.expectAndConsume())
3433  return ExprError();
3434 
3435  // Start of requirement list
3437 
3438  // C++2a [expr.prim.req]p2
3439  // Expressions appearing within a requirement-body are unevaluated operands.
3442 
3443  ParseScope BodyScope(this, Scope::DeclScope);
3445  RequiresKWLoc, LocalParameterDecls, getCurScope());
3446 
3447  if (Tok.is(tok::r_brace)) {
3448  // Grammar does not allow an empty body.
3449  // requirement-body:
3450  // { requirement-seq }
3451  // requirement-seq:
3452  // requirement
3453  // requirement-seq requirement
3454  Diag(Tok, diag::err_empty_requires_expr);
3455  // Continue anyway and produce a requires expr with no requirements.
3456  } else {
3457  while (!Tok.is(tok::r_brace)) {
3458  switch (Tok.getKind()) {
3459  case tok::l_brace: {
3460  // Compound requirement
3461  // C++ [expr.prim.req.compound]
3462  // compound-requirement:
3463  // '{' expression '}' 'noexcept'[opt]
3464  // return-type-requirement[opt] ';'
3465  // return-type-requirement:
3466  // trailing-return-type
3467  // '->' cv-qualifier-seq[opt] constrained-parameter
3468  // cv-qualifier-seq[opt] abstract-declarator[opt]
3469  BalancedDelimiterTracker ExprBraces(*this, tok::l_brace);
3470  ExprBraces.consumeOpen();
3473  if (!Expression.isUsable()) {
3474  ExprBraces.skipToEnd();
3475  SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch);
3476  break;
3477  }
3478  if (ExprBraces.consumeClose())
3479  ExprBraces.skipToEnd();
3480 
3481  concepts::Requirement *Req = nullptr;
3482  SourceLocation NoexceptLoc;
3483  TryConsumeToken(tok::kw_noexcept, NoexceptLoc);
3484  if (Tok.is(tok::semi)) {
3485  Req = Actions.ActOnCompoundRequirement(Expression.get(), NoexceptLoc);
3486  if (Req)
3487  Requirements.push_back(Req);
3488  break;
3489  }
3490  if (!TryConsumeToken(tok::arrow))
3491  // User probably forgot the arrow, remind them and try to continue.
3492  Diag(Tok, diag::err_requires_expr_missing_arrow)
3493  << FixItHint::CreateInsertion(Tok.getLocation(), "->");
3494  // Try to parse a 'type-constraint'
3495  if (TryAnnotateTypeConstraint()) {
3496  SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch);
3497  break;
3498  }
3499  if (!isTypeConstraintAnnotation()) {
3500  Diag(Tok, diag::err_requires_expr_expected_type_constraint);
3501  SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch);
3502  break;
3503  }
3504  CXXScopeSpec SS;
3505  if (Tok.is(tok::annot_cxxscope)) {
3507  Tok.getAnnotationRange(),
3508  SS);
3509  ConsumeAnnotationToken();
3510  }
3511 
3512  Req = Actions.ActOnCompoundRequirement(
3513  Expression.get(), NoexceptLoc, SS, takeTemplateIdAnnotation(Tok),
3514  TemplateParameterDepth);
3515  ConsumeAnnotationToken();
3516  if (Req)
3517  Requirements.push_back(Req);
3518  break;
3519  }
3520  default: {
3521  bool PossibleRequiresExprInSimpleRequirement = false;
3522  if (Tok.is(tok::kw_requires)) {
3523  auto IsNestedRequirement = [&] {
3524  RevertingTentativeParsingAction TPA(*this);
3525  ConsumeToken(); // 'requires'
3526  if (Tok.is(tok::l_brace))
3527  // This is a requires expression
3528  // requires (T t) {
3529  // requires { t++; };
3530  // ... ^
3531  // }
3532  return false;
3533  if (Tok.is(tok::l_paren)) {
3534  // This might be the parameter list of a requires expression
3535  ConsumeParen();
3536  auto Res = TryParseParameterDeclarationClause();
3537  if (Res != TPResult::False) {
3538  // Skip to the closing parenthesis
3539  // FIXME: Don't traverse these tokens twice (here and in
3540  // TryParseParameterDeclarationClause).
3541  unsigned Depth = 1;
3542  while (Depth != 0) {
3543  if (Tok.is(tok::l_paren))
3544  Depth++;
3545  else if (Tok.is(tok::r_paren))
3546  Depth--;
3547  ConsumeAnyToken();
3548  }
3549  // requires (T t) {
3550  // requires () ?
3551  // ... ^
3552  // - OR -
3553  // requires (int x) ?
3554  // ... ^
3555  // }
3556  if (Tok.is(tok::l_brace))
3557  // requires (...) {
3558  // ^ - a requires expression as a
3559  // simple-requirement.
3560  return false;
3561  }
3562  }
3563  return true;
3564  };
3565  if (IsNestedRequirement()) {
3566  ConsumeToken();
3567  // Nested requirement
3568  // C++ [expr.prim.req.nested]
3569  // nested-requirement:
3570  // 'requires' constraint-expression ';'
3571  ExprResult ConstraintExpr =
3573  if (ConstraintExpr.isInvalid() || !ConstraintExpr.isUsable()) {
3574  SkipUntil(tok::semi, tok::r_brace,
3575  SkipUntilFlags::StopBeforeMatch);
3576  break;
3577  }
3578  if (auto *Req =
3579  Actions.ActOnNestedRequirement(ConstraintExpr.get()))
3580  Requirements.push_back(Req);
3581  else {
3582  SkipUntil(tok::semi, tok::r_brace,
3583  SkipUntilFlags::StopBeforeMatch);
3584  break;
3585  }
3586  break;
3587  } else
3588  PossibleRequiresExprInSimpleRequirement = true;
3589  } else if (Tok.is(tok::kw_typename)) {
3590  // This might be 'typename T::value_type;' (a type requirement) or
3591  // 'typename T::value_type{};' (a simple requirement).
3592  TentativeParsingAction TPA(*this);
3593 
3594  // We need to consume the typename to allow 'requires { typename a; }'
3595  SourceLocation TypenameKWLoc = ConsumeToken();
3597  TPA.Commit();
3598  SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch);
3599  break;
3600  }
3601  CXXScopeSpec SS;
3602  if (Tok.is(tok::annot_cxxscope)) {
3604  Tok.getAnnotationValue(), Tok.getAnnotationRange(), SS);
3605  ConsumeAnnotationToken();
3606  }
3607 
3608  if (Tok.isOneOf(tok::identifier, tok::annot_template_id) &&
3609  !NextToken().isOneOf(tok::l_brace, tok::l_paren)) {
3610  TPA.Commit();
3611  SourceLocation NameLoc = Tok.getLocation();
3612  IdentifierInfo *II = nullptr;
3613  TemplateIdAnnotation *TemplateId = nullptr;
3614  if (Tok.is(tok::identifier)) {
3615  II = Tok.getIdentifierInfo();
3616  ConsumeToken();
3617  } else {
3618  TemplateId = takeTemplateIdAnnotation(Tok);
3619  ConsumeAnnotationToken();
3620  if (TemplateId->isInvalid())
3621  break;
3622  }
3623 
3624  if (auto *Req = Actions.ActOnTypeRequirement(TypenameKWLoc, SS,
3625  NameLoc, II,
3626  TemplateId)) {
3627  Requirements.push_back(Req);
3628  }
3629  break;
3630  }
3631  TPA.Revert();
3632  }
3633  // Simple requirement
3634  // C++ [expr.prim.req.simple]
3635  // simple-requirement:
3636  // expression ';'
3637  SourceLocation StartLoc = Tok.getLocation();
3640  if (!Expression.isUsable()) {
3641  SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch);
3642  break;
3643  }
3644  if (!Expression.isInvalid() && PossibleRequiresExprInSimpleRequirement)
3645  Diag(StartLoc, diag::err_requires_expr_in_simple_requirement)
3646  << FixItHint::CreateInsertion(StartLoc, "requires");
3647  if (auto *Req = Actions.ActOnSimpleRequirement(Expression.get()))
3648  Requirements.push_back(Req);
3649  else {
3650  SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch);
3651  break;
3652  }
3653  // User may have tried to put some compound requirement stuff here
3654  if (Tok.is(tok::kw_noexcept)) {
3655  Diag(Tok, diag::err_requires_expr_simple_requirement_noexcept)
3656  << FixItHint::CreateInsertion(StartLoc, "{")
3657  << FixItHint::CreateInsertion(Tok.getLocation(), "}");
3658  SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch);
3659  break;
3660  }
3661  break;
3662  }
3663  }
3664  if (ExpectAndConsumeSemi(diag::err_expected_semi_requirement)) {
3665  SkipUntil(tok::semi, tok::r_brace, SkipUntilFlags::StopBeforeMatch);
3666  TryConsumeToken(tok::semi);
3667  break;
3668  }
3669  }
3670  if (Requirements.empty()) {
3671  // Don't emit an empty requires expr here to avoid confusing the user with
3672  // other diagnostics quoting an empty requires expression they never
3673  // wrote.
3674  Braces.consumeClose();
3675  Actions.ActOnFinishRequiresExpr();
3676  return ExprError();
3677  }
3678  }
3679  Braces.consumeClose();
3680  Actions.ActOnFinishRequiresExpr();
3681  return Actions.ActOnRequiresExpr(RequiresKWLoc, Body, LocalParameterDecls,
3682  Requirements, Braces.getCloseLocation());
3683 }
3684 
3686  switch (kind) {
3687  default: llvm_unreachable("Not a known type trait");
3688 #define TYPE_TRAIT_1(Spelling, Name, Key) \
3689 case tok::kw_ ## Spelling: return UTT_ ## Name;
3690 #define TYPE_TRAIT_2(Spelling, Name, Key) \
3691 case tok::kw_ ## Spelling: return BTT_ ## Name;
3692 #include "clang/Basic/TokenKinds.def"
3693 #define TYPE_TRAIT_N(Spelling, Name, Key) \
3694  case tok::kw_ ## Spelling: return TT_ ## Name;
3695 #include "clang/Basic/TokenKinds.def"
3696  }
3697 }
3698 
3700  switch (kind) {
3701  default:
3702  llvm_unreachable("Not a known array type trait");
3703 #define ARRAY_TYPE_TRAIT(Spelling, Name, Key) \
3704  case tok::kw_##Spelling: \
3705  return ATT_##Name;
3706 #include "clang/Basic/TokenKinds.def"
3707  }
3708 }
3709 
3711  switch (kind) {
3712  default:
3713  llvm_unreachable("Not a known unary expression trait.");
3714 #define EXPRESSION_TRAIT(Spelling, Name, Key) \
3715  case tok::kw_##Spelling: \
3716  return ET_##Name;
3717 #include "clang/Basic/TokenKinds.def"
3718  }
3719 }
3720 
3722  switch (kind) {
3723  default: llvm_unreachable("Not a known type trait");
3724 #define TYPE_TRAIT(N,Spelling,K) case tok::kw_##Spelling: return N;
3725 #include "clang/Basic/TokenKinds.def"
3726  }
3727 }
3728 
3729 /// Parse the built-in type-trait pseudo-functions that allow
3730 /// implementation of the TR1/C++11 type traits templates.
3731 ///
3732 /// primary-expression:
3733 /// unary-type-trait '(' type-id ')'
3734 /// binary-type-trait '(' type-id ',' type-id ')'
3735 /// type-trait '(' type-id-seq ')'
3736 ///
3737 /// type-id-seq:
3738 /// type-id ...[opt] type-id-seq[opt]
3739 ///
3740 ExprResult Parser::ParseTypeTrait() {
3741  tok::TokenKind Kind = Tok.getKind();
3742  unsigned Arity = TypeTraitArity(Kind);
3743 
3744  SourceLocation Loc = ConsumeToken();
3745 
3746  BalancedDelimiterTracker Parens(*this, tok::l_paren);
3747  if (Parens.expectAndConsume())
3748  return ExprError();
3749 
3751  do {
3752  // Parse the next type.
3753  TypeResult Ty = ParseTypeName();
3754  if (Ty.isInvalid()) {
3755  Parens.skipToEnd();
3756  return ExprError();
3757  }
3758 
3759  // Parse the ellipsis, if present.
3760  if (Tok.is(tok::ellipsis)) {
3761  Ty = Actions.ActOnPackExpansion(Ty.get(), ConsumeToken());
3762  if (Ty.isInvalid()) {
3763  Parens.skipToEnd();
3764  return ExprError();
3765  }
3766  }
3767 
3768  // Add this type to the list of arguments.
3769  Args.push_back(Ty.get());
3770  } while (TryConsumeToken(tok::comma));
3771 
3772  if (Parens.consumeClose())
3773  return ExprError();
3774 
3775  SourceLocation EndLoc = Parens.getCloseLocation();
3776 
3777  if (Arity && Args.size() != Arity) {
3778  Diag(EndLoc, diag::err_type_trait_arity)
3779  << Arity << 0 << (Arity > 1) << (int)Args.size() << SourceRange(Loc);
3780  return ExprError();
3781  }
3782 
3783  if (!Arity && Args.empty()) {
3784  Diag(EndLoc, diag::err_type_trait_arity)
3785  << 1 << 1 << 1 << (int)Args.size() << SourceRange(Loc);
3786  return ExprError();
3787  }
3788 
3789  return Actions.ActOnTypeTrait(TypeTraitFromTokKind(Kind), Loc, Args, EndLoc);
3790 }
3791 
3792 /// ParseArrayTypeTrait - Parse the built-in array type-trait
3793 /// pseudo-functions.
3794 ///
3795 /// primary-expression:
3796 /// [Embarcadero] '__array_rank' '(' type-id ')'
3797 /// [Embarcadero] '__array_extent' '(' type-id ',' expression ')'
3798 ///
3799 ExprResult Parser::ParseArrayTypeTrait() {
3801  SourceLocation Loc = ConsumeToken();
3802 
3803  BalancedDelimiterTracker T(*this, tok::l_paren);
3804  if (T.expectAndConsume())
3805  return ExprError();
3806 
3807  TypeResult Ty = ParseTypeName();
3808  if (Ty.isInvalid()) {
3809  SkipUntil(tok::comma, StopAtSemi);
3810  SkipUntil(tok::r_paren, StopAtSemi);
3811  return ExprError();
3812  }
3813 
3814  switch (ATT) {
3815  case ATT_ArrayRank: {
3816  T.consumeClose();
3817  return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.get(), nullptr,
3818  T.getCloseLocation());
3819  }
3820  case ATT_ArrayExtent: {
3821  if (ExpectAndConsume(tok::comma)) {
3822  SkipUntil(tok::r_paren, StopAtSemi);
3823  return ExprError();
3824  }
3825 
3826  ExprResult DimExpr = ParseExpression();
3827  T.consumeClose();
3828 
3829  return Actions.ActOnArrayTypeTrait(ATT, Loc, Ty.get(), DimExpr.get(),
3830  T.getCloseLocation());
3831  }
3832  }
3833  llvm_unreachable("Invalid ArrayTypeTrait!");
3834 }
3835 
3836 /// ParseExpressionTrait - Parse built-in expression-trait
3837 /// pseudo-functions like __is_lvalue_expr( xxx ).
3838 ///
3839 /// primary-expression:
3840 /// [Embarcadero] expression-trait '(' expression ')'
3841 ///
3842 ExprResult Parser::ParseExpressionTrait() {
3844  SourceLocation Loc = ConsumeToken();
3845 
3846  BalancedDelimiterTracker T(*this, tok::l_paren);
3847  if (T.expectAndConsume())
3848  return ExprError();
3849 
3851 
3852  T.consumeClose();
3853 
3854  return Actions.ActOnExpressionTrait(ET, Loc, Expr.get(),
3855  T.getCloseLocation());
3856 }
3857 
3858 
3859 /// ParseCXXAmbiguousParenExpression - We have parsed the left paren of a
3860 /// parenthesized ambiguous type-id. This uses tentative parsing to disambiguate
3861 /// based on the context past the parens.
3862 ExprResult
3863 Parser::ParseCXXAmbiguousParenExpression(ParenParseOption &ExprType,
3864  ParsedType &CastTy,
3865  BalancedDelimiterTracker &Tracker,
3866  ColonProtectionRAIIObject &ColonProt) {
3867  assert(getLangOpts().CPlusPlus && "Should only be called for C++!");
3868  assert(ExprType == CastExpr && "Compound literals are not ambiguous!");
3869  assert(isTypeIdInParens() && "Not a type-id!");
3870 
3871  ExprResult Result(true);
3872  CastTy = nullptr;
3873 
3874  // We need to disambiguate a very ugly part of the C++ syntax:
3875  //
3876  // (T())x; - type-id
3877  // (T())*x; - type-id
3878  // (T())/x; - expression
3879  // (T()); - expression
3880  //
3881  // The bad news is that we cannot use the specialized tentative parser, since
3882  // it can only verify that the thing inside the parens can be parsed as
3883  // type-id, it is not useful for determining the context past the parens.
3884  //
3885  // The good news is that the parser can disambiguate this part without
3886  // making any unnecessary Action calls.
3887  //
3888  // It uses a scheme similar to parsing inline methods. The parenthesized
3889  // tokens are cached, the context that follows is determined (possibly by
3890  // parsing a cast-expression), and then we re-introduce the cached tokens
3891  // into the token stream and parse them appropriately.
3892 
3893  ParenParseOption ParseAs;
3894  CachedTokens Toks;
3895 
3896  // Store the tokens of the parentheses. We will parse them after we determine
3897  // the context that follows them.
3898  if (!ConsumeAndStoreUntil(tok::r_paren, Toks)) {
3899  // We didn't find the ')' we expected.
3900  Tracker.consumeClose();
3901  return ExprError();
3902  }
3903 
3904  if (Tok.is(tok::l_brace)) {
3905  ParseAs = CompoundLiteral;
3906  } else {
3907  bool NotCastExpr;
3908  if (Tok.is(tok::l_paren) && NextToken().is(tok::r_paren)) {
3909  NotCastExpr = true;
3910  } else {
3911  // Try parsing the cast-expression that may follow.
3912  // If it is not a cast-expression, NotCastExpr will be true and no token
3913  // will be consumed.
3914  ColonProt.restore();
3915  Result = ParseCastExpression(AnyCastExpr,
3916  false/*isAddressofOperand*/,
3917  NotCastExpr,
3918  // type-id has priority.
3919  IsTypeCast);
3920  }
3921 
3922  // If we parsed a cast-expression, it's really a type-id, otherwise it's
3923  // an expression.
3924  ParseAs = NotCastExpr ? SimpleExpr : CastExpr;
3925  }
3926 
3927  // Create a fake EOF to mark end of Toks buffer.
3928  Token AttrEnd;
3929  AttrEnd.startToken();
3930  AttrEnd.setKind(tok::eof);
3931  AttrEnd.setLocation(Tok.getLocation());
3932  AttrEnd.setEofData(Toks.data());
3933  Toks.push_back(AttrEnd);
3934 
3935  // The current token should go after the cached tokens.
3936  Toks.push_back(Tok);
3937  // Re-enter the stored parenthesized tokens into the token stream, so we may
3938  // parse them now.
3939  PP.EnterTokenStream(Toks, /*DisableMacroExpansion*/ true,
3940  /*IsReinject*/ true);
3941  // Drop the current token and bring the first cached one. It's the same token
3942  // as when we entered this function.
3943  ConsumeAnyToken();
3944 
3945  if (ParseAs >= CompoundLiteral) {
3946  // Parse the type declarator.
3947  DeclSpec DS(AttrFactory);
3948  Declarator DeclaratorInfo(DS, DeclaratorContext::TypeName);
3949  {
3950  ColonProtectionRAIIObject InnerColonProtection(*this);
3951  ParseSpecifierQualifierList(DS);
3952  ParseDeclarator(DeclaratorInfo);
3953  }
3954 
3955  // Match the ')'.
3956  Tracker.consumeClose();
3957  ColonProt.restore();
3958 
3959  // Consume EOF marker for Toks buffer.
3960  assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
3961  ConsumeAnyToken();
3962 
3963  if (ParseAs == CompoundLiteral) {
3964  ExprType = CompoundLiteral;
3965  if (DeclaratorInfo.isInvalidType())
3966  return ExprError();
3967 
3968  TypeResult Ty = Actions.ActOnTypeName(getCurScope(), DeclaratorInfo);
3969  return ParseCompoundLiteralExpression(Ty.get(),
3970  Tracker.getOpenLocation(),
3971  Tracker.getCloseLocation());
3972  }
3973 
3974  // We parsed '(' type-id ')' and the thing after it wasn't a '{'.
3975  assert(ParseAs == CastExpr);
3976 
3977  if (DeclaratorInfo.isInvalidType())
3978  return ExprError();
3979 
3980  // Result is what ParseCastExpression returned earlier.
3981  if (!Result.isInvalid())
3982  Result = Actions.ActOnCastExpr(getCurScope(), Tracker.getOpenLocation(),
3983  DeclaratorInfo, CastTy,
3984  Tracker.getCloseLocation(), Result.get());
3985  return Result;
3986  }
3987 
3988  // Not a compound literal, and not followed by a cast-expression.
3989  assert(ParseAs == SimpleExpr);
3990 
3991  ExprType = SimpleExpr;
3992  Result = ParseExpression();
3993  if (!Result.isInvalid() && Tok.is(tok::r_paren))
3994  Result = Actions.ActOnParenExpr(Tracker.getOpenLocation(),
3995  Tok.getLocation(), Result.get());
3996 
3997  // Match the ')'.
3998  if (Result.isInvalid()) {
3999  while (Tok.isNot(tok::eof))
4000  ConsumeAnyToken();
4001  assert(Tok.getEofData() == AttrEnd.getEofData());
4002  ConsumeAnyToken();
4003  return ExprError();
4004  }
4005 
4006  Tracker.consumeClose();
4007  // Consume EOF marker for Toks buffer.
4008  assert(Tok.is(tok::eof) && Tok.getEofData() == AttrEnd.getEofData());
4009  ConsumeAnyToken();
4010  return Result;
4011 }
4012 
4013 /// Parse a __builtin_bit_cast(T, E).
4014 ExprResult Parser::ParseBuiltinBitCast() {
4015  SourceLocation KWLoc = ConsumeToken();
4016 
4017  BalancedDelimiterTracker T(*this, tok::l_paren);
4018  if (T.expectAndConsume(diag::err_expected_lparen_after, "__builtin_bit_cast"))
4019  return ExprError();
4020 
4021  // Parse the common declaration-specifiers piece.
4022  DeclSpec DS(AttrFactory);
4023  ParseSpecifierQualifierList(DS);
4024 
4025  // Parse the abstract-declarator, if present.
4026  Declarator DeclaratorInfo(DS, DeclaratorContext::TypeName);
4027  ParseDeclarator(DeclaratorInfo);
4028 
4029  if (ExpectAndConsume(tok::comma)) {
4030  Diag(Tok.getLocation(), diag::err_expected) << tok::comma;
4031  SkipUntil(tok::r_paren, StopAtSemi);
4032  return ExprError();
4033  }
4034 
4036 
4037  if (T.consumeClose())
4038  return ExprError();
4039 
4040  if (Operand.isInvalid() || DeclaratorInfo.isInvalidType())
4041  return ExprError();
4042 
4043  return Actions.ActOnBuiltinBitCastExpr(KWLoc, DeclaratorInfo, Operand,
4044  T.getCloseLocation());
4045 }
clang::TypeSpecifierWidth::LongLong
@ LongLong
clang::Sema::ActOnCXXConditionDeclaration
DeclResult ActOnCXXConditionDeclaration(Scope *S, Declarator &D)
ActOnCXXConditionDeclarationExpr - Parsed a condition declaration of a C++ if/switch/while/for statem...
Definition: SemaDeclCXX.cpp:17650
clang::SourceRange::setBegin
void setBegin(SourceLocation b)
Definition: SourceLocation.h:222
clang::Token::startToken
void startToken()
Reset all flags to cleared.
Definition: Token.h:170
clang::UnqualifiedId
Represents a C++ unqualified-id that has been parsed.
Definition: DeclSpec.h:950
clang::CXXScopeSpec::setEndLoc
void setEndLoc(SourceLocation Loc)
Definition: DeclSpec.h:72
clang::UnqualifiedId::setIdentifier
void setIdentifier(const IdentifierInfo *Id, SourceLocation IdLoc)
Specify that this unqualified-id was parsed as an identifier.
Definition: DeclSpec.h:1038
clang::Token::getAnnotationRange
SourceRange getAnnotationRange() const
SourceRange of the group of tokens that this annotation token represents.
Definition: Token.h:159
TypeTraitFromTokKind
static TypeTrait TypeTraitFromTokKind(tok::TokenKind kind)
Definition: ParseExprCXX.cpp:3685
clang::Sema::CodeCompleteOperatorName
void CodeCompleteOperatorName(Scope *S)
Definition: SemaCodeComplete.cpp:6660
clang::OpaquePtr::get
PtrTy get() const
Definition: Ownership.h:80
clang::ArrayTypeTrait
ArrayTypeTrait
Names for the array type traits.
Definition: TypeTraits.h:42
clang::Scope::FunctionPrototypeScope
@ FunctionPrototypeScope
This is a scope that corresponds to the parameters within a function prototype.
Definition: Scope.h:81
clang::TNK_Non_template
@ TNK_Non_template
The name does not refer to a template.
Definition: TemplateKinds.h:22
clang::TemplateIdAnnotation
Information about a template-id annotation token.
Definition: ParsedTemplate.h:149
clang::UnqualifiedIdKind::IK_OperatorFunctionId
@ IK_OperatorFunctionId
An overloaded operator name, e.g., operator+.
clang::Scope::FnScope
@ FnScope
This indicates that the scope corresponds to a function, which means that labels are set here.
Definition: Scope.h:47
clang::LambdaIntroducer
Represents a complete lambda introducer.
Definition: DeclSpec.h:2667
clang::Token::setEofData
void setEofData(const void *D)
Definition: Token.h:195
clang::Preprocessor::LookAhead
const Token & LookAhead(unsigned N)
Peeks ahead N tokens and returns that token without consuming any tokens.
Definition: Preprocessor.h:1576
clang::Sema::ActOnParenListExpr
ExprResult ActOnParenListExpr(SourceLocation L, SourceLocation R, MultiExprArg Val)
Definition: SemaExpr.cpp:8067
clang::SourceRange
A trivial tuple used to represent a source range.
Definition: SourceLocation.h:210
clang::TemplateIdAnnotation::Create
static TemplateIdAnnotation * Create(SourceLocation TemplateKWLoc, SourceLocation TemplateNameLoc, IdentifierInfo *Name, OverloadedOperatorKind OperatorKind, ParsedTemplateTy OpaqueTemplateName, TemplateNameKind TemplateKind, SourceLocation LAngleLoc, SourceLocation RAngleLoc, ArrayRef< ParsedTemplateArgument > TemplateArgs, bool ArgsInvalid, SmallVectorImpl< TemplateIdAnnotation * > &CleanupList)
Creates a new TemplateIdAnnotation with NumArgs arguments and appends it to List.
Definition: ParsedTemplate.h:199
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::Parser::getAttrFactory
AttributeFactory & getAttrFactory()
Definition: Parser.h:444
clang::Sema::ActOnSimpleRequirement
concepts::Requirement * ActOnSimpleRequirement(Expr *E)
Definition: SemaExprCXX.cpp:8862
clang::Sema::ActOnCXXBoolLiteral
ExprResult ActOnCXXBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind)
ActOnCXXBoolLiteral - Parse {true,false} literals.
Definition: SemaExprCXX.cpp:808
clang::Sema::ActOnLambdaExplicitTemplateParameterList
void ActOnLambdaExplicitTemplateParameterList(SourceLocation LAngleLoc, ArrayRef< NamedDecl * > TParams, SourceLocation RAngleLoc, ExprResult RequiresClause)
This is called after parsing the explicit template parameter list on a lambda (if it exists) in C++2a...
Definition: SemaLambda.cpp:522
clang::FixItHint::CreateInsertion
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:97
clang::Preprocessor::Lex
void Lex(Token &Result)
Lex the next token for this preprocessor.
Definition: Preprocessor.cpp:892
clang::InMessageExpressionRAIIObject
Definition: RAIIObjectsForParser.h:325
clang::Parser::SkipUntil
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:1217
clang::Sema::getASTContext
ASTContext & getASTContext() const
Definition: Sema.h:1614
clang::Token::getEofData
const void * getEofData() const
Definition: Token.h:191
clang::TemplateNameKind
TemplateNameKind
Specifies the kind of template name that an identifier refers to.
Definition: TemplateKinds.h:20
clang::Sema::ActOnCXXTypeid
ExprResult ActOnCXXTypeid(SourceLocation OpLoc, SourceLocation LParenLoc, bool isType, void *TyOrExpr, SourceLocation RParenLoc)
ActOnCXXTypeid - Parse typeid( something ).
Definition: SemaExprCXX.cpp:641
clang::Sema::ActOnIdExpression
ExprResult ActOnIdExpression(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, UnqualifiedId &Id, bool HasTrailingLParen, bool IsAddressOfOperand, CorrectionCandidateCallback *CCC=nullptr, bool IsInlineAsmIdentifier=false, Token *KeywordReplacement=nullptr)
Definition: SemaExpr.cpp:2482
clang::DeclSpec::SetTypeSpecError
bool SetTypeSpecError()
Definition: DeclSpec.cpp:927
clang::UnqualifiedId::setTemplateId
void setTemplateId(TemplateIdAnnotation *TemplateId)
Specify that this unqualified-id was parsed as a template-id.
Definition: DeclSpec.cpp:31
clang::Sema::ActOnRequiresExpr
ExprResult ActOnRequiresExpr(SourceLocation RequiresKWLoc, RequiresExprBodyDecl *Body, ArrayRef< ParmVarDecl * > LocalParameters, ArrayRef< concepts::Requirement * > Requirements, SourceLocation ClosingBraceLoc)
Definition: SemaExprCXX.cpp:9067
llvm::SmallVector
Definition: LLVM.h:38
clang::IdentifierTable::get
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
Definition: IdentifierTable.h:596
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::TNK_Undeclared_template
@ TNK_Undeclared_template
Lookup for the name failed, but we're assuming it was a template name anyway.
Definition: TemplateKinds.h:50
clang::SourceLocation::getLocWithOffset
SourceLocation getLocWithOffset(IntTy Offset) const
Return a source location with the specified offset from this SourceLocation.
Definition: SourceLocation.h:134
clang::NamedDecl
This represents a decl that may have a name.
Definition: Decl.h:247
clang::SourceRange::getBegin
SourceLocation getBegin() const
Definition: SourceLocation.h:219
clang::Scope::BlockScope
@ BlockScope
This is a scope that corresponds to a block/closure object.
Definition: Scope.h:71
clang::ColonProtectionRAIIObject::restore
void restore()
restore - This can be used to restore the state early, before the dtor is run.
Definition: RAIIObjectsForParser.h:281
clang::Sema::ActOnNameClassifiedAsDependentNonType
ExprResult ActOnNameClassifiedAsDependentNonType(const CXXScopeSpec &SS, IdentifierInfo *Name, SourceLocation NameLoc, bool IsAddressOfOperand)
Act on the result of classifying a name as an undeclared member of a dependent base class.
Definition: SemaDecl.cpp:1245
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:675
clang::DeclSpec::SetBitIntType
bool SetBitIntType(SourceLocation KWLoc, Expr *BitWidth, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
Definition: DeclSpec.cpp:935
clang::EST_None
@ EST_None
no exception specification
Definition: ExceptionSpecificationType.h:21
clang::DynamicInitKind::Initializer
@ Initializer
clang::Token::getIdentifierInfo
IdentifierInfo * getIdentifierInfo() const
Definition: Token.h:178
clang::Sema::ActOnBuiltinBitCastExpr
ExprResult ActOnBuiltinBitCastExpr(SourceLocation KWLoc, Declarator &Dcl, ExprResult Operand, SourceLocation RParenLoc)
Definition: SemaCast.cpp:382
clang::TypeTrait
TypeTrait
Names for traits that operate specifically on types.
Definition: TypeTraits.h:21
clang::Sema::actOnLambdaInitCaptureInitialization
ParsedType actOnLambdaInitCaptureInitialization(SourceLocation Loc, bool ByRef, SourceLocation EllipsisLoc, IdentifierInfo *Id, LambdaCaptureInitKind InitKind, Expr *&Init)
Perform initialization analysis of the init-capture and perform any implicit conversions such as an l...
Definition: Sema.h:6852
int
__device__ int
Definition: __clang_hip_libdevice_declares.h:63
ArrayTypeTraitFromTokKind
static ArrayTypeTrait ArrayTypeTraitFromTokKind(tok::TokenKind kind)
Definition: ParseExprCXX.cpp:3699
clang::UnqualifiedIdKind::IK_Identifier
@ IK_Identifier
An identifier.
clang::Sema::ActOnCXXNew
ExprResult ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal, SourceLocation PlacementLParen, MultiExprArg PlacementArgs, SourceLocation PlacementRParen, SourceRange TypeIdParens, Declarator &D, Expr *Initializer)
ActOnCXXNew - Parsed a C++ 'new' expression.
Definition: SemaExprCXX.cpp:1831
clang::Token::setAnnotationEndLoc
void setAnnotationEndLoc(SourceLocation L)
Definition: Token.h:143
clang::Parser
Parser - This implements a parser for the C family of languages.
Definition: Parser.h:60
clang::Parser::ParseAssignmentExpression
ExprResult ParseAssignmentExpression(TypeCastState isTypeCast=NotTypeCast)
Parse an expr that doesn't include (top-level) commas.
Definition: ParseExpr.cpp:160
clang::Sema::getSourceManager
SourceManager & getSourceManager() const
Definition: Sema.h:1612
clang::Parser::TemplateTy
OpaquePtr< TemplateName > TemplateTy
Definition: Parser.h:459
clang::Sema::ActOnCastExpr
ExprResult ActOnCastExpr(Scope *S, SourceLocation LParenLoc, Declarator &D, ParsedType &Ty, SourceLocation RParenLoc, Expr *CastExpr)
Definition: SemaExpr.cpp:7892
clang::DeclSpec::getSourceRange
SourceRange getSourceRange() const LLVM_READONLY
Definition: DeclSpec.h:506
clang::TST_error
@ TST_error
Definition: Specifiers.h:93
clang::ComparisonCategoryType::First
@ First
clang::Sema::ActOnCXXDelete
ExprResult ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal, bool ArrayForm, Expr *Operand)
ActOnCXXDelete - Parsed a C++ 'delete' expression.
Definition: SemaExprCXX.cpp:3510
clang::ActionResult::isUnset
bool isUnset() const
Definition: Ownership.h:167
RAIIObjectsForParser.h
clang::ColonProtectionRAIIObject
ColonProtectionRAIIObject - This sets the Parser::ColonIsSacred bool and restores it when destroyed.
Definition: RAIIObjectsForParser.h:270
Expression
isOneOf
constexpr static bool isOneOf()
Definition: RetainSummaryManager.cpp:27
DeclSpec.h
clang::Preprocessor::EnterToken
void EnterToken(const Token &Tok, bool IsReinject)
Enters a token in the token stream to be lexed next.
Definition: Preprocessor.h:1605
clang::CXXScopeSpec
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:64
clang::PrintingPolicy
Describes how types, statements, expressions, and declarations should be printed.
Definition: PrettyPrinter.h:57
clang::Sema::ActOnStartOfLambdaDefinition
void ActOnStartOfLambdaDefinition(LambdaIntroducer &Intro, Declarator &ParamInfo, Scope *CurScope)
ActOnStartOfLambdaDefinition - This is called just before we start parsing the body of a lambda; it a...
Definition: SemaLambda.cpp:891
Identifier
StringRef Identifier
Definition: Format.cpp:2559
clang::Sema::ActOnCXXGlobalScopeSpecifier
bool ActOnCXXGlobalScopeSpecifier(SourceLocation CCLoc, CXXScopeSpec &SS)
The parser has parsed a global nested-name-specifier '::'.
Definition: SemaCXXScopeSpec.cpp:286
clang::DeclaratorContext::ForInit
@ ForInit
clang::Token
Token - This structure provides full information about a lexed token.
Definition: Token.h:34
clang::TemplateIdAnnotation::NumArgs
unsigned NumArgs
NumArgs - The number of template arguments.
Definition: ParsedTemplate.h:185
LiteralSupport.h
clang::BalancedDelimiterTracker
RAII class that helps handle the parsing of an open/close delimiter pair, such as braces { ....
Definition: RAIIObjectsForParser.h:385
clang::Sema::ConditionKind
ConditionKind
Definition: Sema.h:12258
ExpressionTraitFromTokKind
static ExpressionTrait ExpressionTraitFromTokKind(tok::TokenKind kind)
Definition: ParseExprCXX.cpp:3710
clang::Preprocessor::isCodeCompletionReached
bool isCodeCompletionReached() const
Returns true if code-completion is enabled and we have hit the code-completion point.
Definition: Preprocessor.h:1731
clang::Preprocessor::getIdentifierTable
IdentifierTable & getIdentifierTable()
Definition: Preprocessor.h:1001
clang::LambdaCaptureInitKind::DirectInit
@ DirectInit
[a(b)]
clang::DeclaratorChunk::getFunction
static DeclaratorChunk getFunction(bool HasProto, bool IsAmbiguous, SourceLocation LParenLoc, ParamInfo *Params, unsigned NumParams, SourceLocation EllipsisLoc, SourceLocation RParenLoc, bool RefQualifierIsLvalueRef, SourceLocation RefQualifierLoc, SourceLocation MutableLoc, ExceptionSpecificationType ESpecType, SourceRange ESpecRange, ParsedType *Exceptions, SourceRange *ExceptionRanges, unsigned NumExceptions, Expr *NoexceptExpr, CachedTokens *ExceptionSpecTokens, ArrayRef< NamedDecl * > DeclsInPrototype, SourceLocation LocalRangeBegin, SourceLocation LocalRangeEnd, Declarator &TheDeclarator, TypeResult TrailingReturnType=TypeResult(), SourceLocation TrailingReturnTypeLoc=SourceLocation(), DeclSpec *MethodQualifiers=nullptr)
DeclaratorChunk::getFunction - Return a DeclaratorChunk for a function.
Definition: DeclSpec.cpp:160
clang::SourceManager
This class handles loading and caching of source files into memory.
Definition: SourceManager.h:627
clang::Type
The base class of the type hierarchy.
Definition: Type.h:1500
clang::Sema::ConditionKind::Switch
@ Switch
An integral condition for a 'switch' statement.
clang::ExprError
ExprResult ExprError()
Definition: Ownership.h:278
Decl.h
clang::CXXScopeSpec::clear
void clear()
Definition: DeclSpec.h:212
clang::DeclSpec::TST_float
static const TST TST_float
Definition: DeclSpec.h:272
clang::Preprocessor::AnnotateCachedTokens
void AnnotateCachedTokens(const Token &Tok)
We notify the Preprocessor that if it is caching tokens (because backtrack is enabled) it should repl...
Definition: Preprocessor.h:1627
clang::Parser::ParseConstraintExpression
ExprResult ParseConstraintExpression()
Parse a constraint-expression.
Definition: ParseExpr.cpp:235
clang::CXXScopeSpec::isSet
bool isSet() const
Deprecated.
Definition: DeclSpec.h:210
clang::AS_none
@ AS_none
Definition: Specifiers.h:112
clang::CPlusPlus17
@ CPlusPlus17
Definition: LangStandard.h:56
clang::DeclSpec::TST_char8
static const TST TST_char8
Definition: DeclSpec.h:264
clang::DeclSpec::SetRangeStart
void SetRangeStart(SourceLocation Loc)
Definition: DeclSpec.h:638
clang::Declarator::getDeclSpec
const DeclSpec & getDeclSpec() const
getDeclSpec - Return the declaration-specifier that this declarator was declared with.
Definition: DeclSpec.h:1910
clang::dataflow::Literal
uint32_t Literal
Literals are represented as positive integers.
Definition: WatchedLiteralsSolver.cpp:55
clang::ExprEmpty
ExprResult ExprEmpty()
Definition: Ownership.h:289
clang::ParenBraceBracketBalancer
RAII object that makes sure paren/bracket/brace count is correct after declaration/statement parsing,...
Definition: RAIIObjectsForParser.h:343
clang::DeclSpec::SetTypeSpecSign
bool SetTypeSpecSign(TypeSpecifierSign S, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:721
llvm::MutableArrayRef
Definition: LLVM.h:35
clang::Sema::ActOnLambdaError
void ActOnLambdaError(SourceLocation StartLoc, Scope *CurScope, bool IsInstantiation=false)
ActOnLambdaError - If there is an error parsing a lambda, this callback is invoked to pop the informa...
Definition: SemaLambda.cpp:1251
clang::Sema::ActOnNestedRequirement
concepts::Requirement * ActOnNestedRequirement(Expr *Constraint)
Definition: SemaExprCXX.cpp:9009
clang::DeclSpec::SetConstexprSpec
bool SetConstexprSpec(ConstexprSpecKind ConstexprKind, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID)
Definition: DeclSpec.cpp:1092
clang::Sema::ShouldEnterDeclaratorScope
bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS)
Definition: SemaCXXScopeSpec.cpp:1039
clang::Sema::ActOnNameClassifiedAsUndeclaredNonType
ExprResult ActOnNameClassifiedAsUndeclaredNonType(IdentifierInfo *Name, SourceLocation NameLoc)
Act on the result of classifying a name as an undeclared (ADL-only) non-type declaration.
Definition: SemaDecl.cpp:1236
DeclTemplate.h
clang::RequiresExprBodyDecl
Represents the body of a requires-expression.
Definition: DeclCXX.h:1946
clang::Sema::CodeCompleteQualifiedId
void CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS, bool EnteringContext, bool IsUsingDeclaration, QualType BaseType, QualType PreferredType)
Definition: SemaCodeComplete.cpp:6452
TypeTraitArity
static unsigned TypeTraitArity(tok::TokenKind kind)
Definition: ParseExprCXX.cpp:3721
clang::Sema::ActOnTypeName
TypeResult ActOnTypeName(Scope *S, Declarator &D)
Definition: SemaType.cpp:6449
clang::Sema::ActOnPseudoDestructorExpr
ExprResult ActOnPseudoDestructorExpr(Scope *S, Expr *Base, SourceLocation OpLoc, tok::TokenKind OpKind, CXXScopeSpec &SS, UnqualifiedId &FirstTypeName, SourceLocation CCLoc, SourceLocation TildeLoc, UnqualifiedId &SecondTypeName)
Definition: SemaExprCXX.cpp:7769
clang::ConstexprSpecKind::Consteval
@ Consteval
clang::Decl::getKind
Kind getKind() const
Definition: DeclBase.h:428
clang::ExceptionSpecificationType
ExceptionSpecificationType
The various types of exception specifications that exist in C++11.
Definition: ExceptionSpecificationType.h:20
Id
int Id
Definition: ASTDiff.cpp:191
clang::TypeSpecifierSign::Signed
@ Signed
clang::Scope
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
clang::CXXScopeSpec::SetInvalid
void SetInvalid(SourceRange R)
Indicate that this nested-name-specifier is invalid.
Definition: DeclSpec.h:200
clang::Parser::ParseUnqualifiedId
bool ParseUnqualifiedId(CXXScopeSpec &SS, ParsedType ObjectType, bool ObjectHadErrors, bool EnteringContext, bool AllowDestructorName, bool AllowConstructorName, bool AllowDeductionGuide, SourceLocation *TemplateKWLoc, UnqualifiedId &Result)
Parse a C++ unqualified-id (or a C identifier), which describes the name of an entity.
Definition: ParseExprCXX.cpp:2789
clang::TemplateIdAnnotation::RAngleLoc
SourceLocation RAngleLoc
The location of the '>' after the template argument list.
Definition: ParsedTemplate.h:182
clang::BalancedDelimiterTracker::getCloseLocation
SourceLocation getCloseLocation() const
Definition: RAIIObjectsForParser.h:428
clang::DeclSpec::TST_char
static const TST TST_char
Definition: DeclSpec.h:262
clang::SourceRange::getEnd
SourceLocation getEnd() const
Definition: SourceLocation.h:220
clang::DeclSpec::TST_double
static const TST TST_double
Definition: DeclSpec.h:273
clang::DeclSpec::TST_BFloat16
static const TST TST_BFloat16
Definition: DeclSpec.h:271
clang::Token::getKind
tok::TokenKind getKind() const
Definition: Token.h:92
clang::Sema::FinalizeDeclaration
void FinalizeDeclaration(Decl *D)
FinalizeDeclaration - called by ParseDeclarationAfterDeclarator to perform any semantic actions neces...
Definition: SemaDecl.cpp:13715
clang::ExprResult
ActionResult< Expr * > ExprResult
Definition: Ownership.h:262
clang::CPlusPlus
@ CPlusPlus
Definition: LangStandard.h:53
clang::Sema::ActOnExprStmt
StmtResult ActOnExprStmt(ExprResult Arg, bool DiscardedValue=true)
Definition: SemaStmt.cpp:46
clang::Token::getAnnotationValue
void * getAnnotationValue() const
Definition: Token.h:225
Depth
int Depth
Definition: ASTDiff.cpp:191
clang::DeclaratorContext::LambdaExpr
@ LambdaExpr
clang::Parser::StopBeforeMatch
@ StopBeforeMatch
Stop skipping at specified token, but don't skip the token itself.
Definition: Parser.h:1198
clang::Scope::CompoundStmtScope
@ CompoundStmtScope
This is a compound statement scope.
Definition: Scope.h:130
clang::Scope::FunctionDeclarationScope
@ FunctionDeclarationScope
This is a scope that corresponds to the parameters within a function prototype for a function declara...
Definition: Scope.h:87
clang::DeclaratorContext::SelectionInit
@ SelectionInit
clang::Sema::ActOnTypeRequirement
concepts::Requirement * ActOnTypeRequirement(SourceLocation TypenameKWLoc, CXXScopeSpec &SS, SourceLocation NameLoc, IdentifierInfo *TypeName, TemplateIdAnnotation *TemplateId)
Definition: SemaExprCXX.cpp:8869
clang::Sema::ExpressionEvaluationContext::Unevaluated
@ Unevaluated
The current expression and its subexpressions occur within an unevaluated operand (C++11 [expr]p7),...
clang::concepts::Requirement
A static requirement that can be used in a requires-expression to check properties of types and expre...
Definition: ExprConcepts.h:149
clang::Sema::AddInitializerToDecl
void AddInitializerToDecl(Decl *dcl, Expr *init, bool DirectInit)
AddInitializerToDecl - Adds the initializer Init to the declaration dcl.
Definition: SemaDecl.cpp:12508
clang::Parser::getLangOpts
const LangOptions & getLangOpts() const
Definition: Parser.h:440
clang::Declarator::AddTypeInfo
void AddTypeInfo(const DeclaratorChunk &TI, ParsedAttributes &&attrs, SourceLocation EndLoc)
AddTypeInfo - Add a chunk to this declarator.
Definition: DeclSpec.h:2211
clang::UnqualifiedIdKind::IK_LiteralOperatorId
@ IK_LiteralOperatorId
A user-defined literal name, e.g., operator "" _i.
clang::Sema::ConditionError
static ConditionResult ConditionError()
Definition: Sema.h:12256
clang::Token::is
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:97
clang::Stmt::getEndLoc
SourceLocation getEndLoc() const LLVM_READONLY
Definition: Stmt.cpp:348
clang::Parser::ParseExpression
ExprResult ParseExpression(TypeCastState isTypeCast=NotTypeCast)
Simple precedence-based parser for binary/ternary operators.
Definition: ParseExpr.cpp:123
clang::Parser::ConsumeAnyToken
SourceLocation ConsumeAnyToken(bool ConsumeCodeCompletionTok=false)
ConsumeAnyToken - Dispatch to the right Consume* method based on the current token type.
Definition: Parser.h:518
clang::ParsedAttr
ParsedAttr - Represents a syntactic attribute.
Definition: ParsedAttr.h:234
clang::UnqualifiedIdKind::IK_ConstructorName
@ IK_ConstructorName
A constructor name.
clang::CPlusPlus20
@ CPlusPlus20
Definition: LangStandard.h:57
clang::Sema::CodeCompleteOrdinaryName
void CodeCompleteOrdinaryName(Scope *S, ParserCompletionContext CompletionContext)
Definition: SemaCodeComplete.cpp:4286
llvm::SmallString< 32 >
clang::Scope::ContinueScope
@ ContinueScope
This is a while, do, for, which can have continue statements embedded into it.
Definition: Scope.h:55
clang::Sema::ActOnNullStmt
StmtResult ActOnNullStmt(SourceLocation SemiLoc, bool HasLeadingEmptyMacro=false)
Definition: SemaStmt.cpp:68
clang::Token::getAnnotationEndLoc
SourceLocation getAnnotationEndLoc() const
Definition: Token.h:139
ASTContext.h
clang::LCD_ByCopy
@ LCD_ByCopy
Definition: Lambda.h:24
clang::LambdaIntroducer::addCapture
void addCapture(LambdaCaptureKind Kind, SourceLocation Loc, IdentifierInfo *Id, SourceLocation EllipsisLoc, LambdaCaptureInitKind InitKind, ExprResult Init, ParsedType InitCaptureType, SourceRange ExplicitRange)
Append a capture in a lambda introducer.
Definition: DeclSpec.h:2698
clang::DeclSpec::getEndLoc
SourceLocation getEndLoc() const LLVM_READONLY
Definition: DeclSpec.h:508
clang::LambdaCaptureInitKind
LambdaCaptureInitKind
Definition: DeclSpec.h:2659
clang::ConstexprSpecKind::Constexpr
@ Constexpr
clang::LambdaIntroducer::Default
LambdaCaptureDefault Default
Definition: DeclSpec.h:2691
clang::Type::getCanonicalTypeInternal
QualType getCanonicalTypeInternal() const
Definition: Type.h:2468
clang::SourceRange::setEnd
void setEnd(SourceLocation e)
Definition: SourceLocation.h:223
clang::Sema::ActOnCoyieldExpr
ExprResult ActOnCoyieldExpr(Scope *S, SourceLocation KwLoc, Expr *E)
Definition: SemaCoroutine.cpp:907
clang::getOperatorSpelling
const char * getOperatorSpelling(OverloadedOperatorKind Operator)
Retrieve the spelling of the given overloaded operator, without the preceding "operator" keyword.
Definition: IdentifierTable.cpp:747
ExprCXX.h
SelectDigraphErrorMessage
static int SelectDigraphErrorMessage(tok::TokenKind Kind)
Definition: ParseExprCXX.cpp:29
Base
clang::Parser::getCurScope
Scope * getCurScope() const
Definition: Parser.h:447
clang::LCD_None
@ LCD_None
Definition: Lambda.h:23
clang::Declarator::SetSourceRange
void SetSourceRange(SourceRange R)
Definition: DeclSpec.h:1949
clang::Sema::CodeCompleteLambdaIntroducer
void CodeCompleteLambdaIntroducer(Scope *S, LambdaIntroducer &Intro, bool AfterAmpersand)
Definition: SemaCodeComplete.cpp:6853
clang::Parser::TryAnnotateOptionalCXXScopeToken
bool TryAnnotateOptionalCXXScopeToken(bool EnteringContext=false)
Definition: Parser.h:865
clang::Parser::Diag
DiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Definition: Parser.cpp:73
clang::Token::isNot
bool isNot(tok::TokenKind K) const
Definition: Token.h:98
clang::Preprocessor::getLastCachedTokenLocation
SourceLocation getLastCachedTokenLocation() const
Get the location of the last cached token, suitable for setting the end location of an annotation tok...
Definition: Preprocessor.h:1635
clang::Sema::checkLiteralOperatorId
bool checkLiteralOperatorId(const CXXScopeSpec &SS, const UnqualifiedId &Id, bool IsUDSuffix)
Definition: SemaExprCXX.cpp:489
clang::OverloadedOperatorKind
OverloadedOperatorKind
Enumeration specifying the different kinds of C++ overloaded operators.
Definition: OperatorKinds.h:21
clang::Sema::ConditionResult
Definition: Sema.h:12224
clang::Parser::StopAtSemi
@ StopAtSemi
Stop skipping at semicolon.
Definition: Parser.h:1196
clang::Sema::ActOnDeclStmt
StmtResult ActOnDeclStmt(DeclGroupPtrTy Decl, SourceLocation StartLoc, SourceLocation EndLoc)
Definition: SemaStmt.cpp:73
clang::Sema::ActOnInitializerError
void ActOnInitializerError(Decl *Dcl)
ActOnInitializerError - Given that there was an error parsing an initializer for the given declaratio...
Definition: SemaDecl.cpp:12971
clang::Token::getLength
unsigned getLength() const
Definition: Token.h:128
PrettyStackTrace.h
clang::Sema::PushLambdaScope
sema::LambdaScopeInfo * PushLambdaScope()
Definition: Sema.cpp:2102
clang::Sema::IsInvalidUnlessNestedName
bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS, NestedNameSpecInfo &IdInfo, bool EnteringContext)
IsInvalidUnlessNestedName - This method is used for error recovery purposes to determine whether the ...
Definition: SemaCXXScopeSpec.cpp:897
clang::DeclSpec::TST_ibm128
static const TST TST_ibm128
Definition: DeclSpec.h:278
clang::Sema::PCC_Condition
@ PCC_Condition
Code completion occurs within the condition of an if, while, switch, or for statement.
Definition: Sema.h:12668
clang::OpaquePtr< QualType >
clang::DeclSpec::TST_int
static const TST TST_int
Definition: DeclSpec.h:267
clang::TemplateIdAnnotation::LAngleLoc
SourceLocation LAngleLoc
The location of the '<' before the template argument list.
Definition: ParsedTemplate.h:178
clang::Preprocessor::getSourceManager
SourceManager & getSourceManager() const
Definition: Preprocessor.h:998
clang::CPlusPlus2b
@ CPlusPlus2b
Definition: LangStandard.h:58
clang::Sema::getCurGenericLambda
sema::LambdaScopeInfo * getCurGenericLambda()
Retrieve the current generic lambda info, if any.
Definition: Sema.cpp:2338
clang::transformer::EditKind::Range
@ Range
clang::TemplateName::getKind
NameKind getKind() const
Definition: TemplateName.cpp:84
clang::Sema::ActOnTemplateName
TemplateNameKind ActOnTemplateName(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, const UnqualifiedId &Name, ParsedType ObjectType, bool EnteringContext, TemplateTy &Template, bool AllowInjectedClassName=false)
Form a template name from a name that is syntactically required to name a template,...
Definition: SemaTemplate.cpp:4831
clang::DeclSpec::TST_int128
static const TST TST_int128
Definition: DeclSpec.h:268
clang::Parser::ParseConstantExpression
ExprResult ParseConstantExpression(TypeCastState isTypeCast=NotTypeCast)
Definition: ParseExpr.cpp:211
clang::syntax::NodeRole::Operand
@ Operand
clang::DeclaratorContext::RequiresExpr
@ RequiresExpr
clang::OO_None
@ OO_None
Not an overloaded operator.
Definition: OperatorKinds.h:22
clang::tok::TokenKind
TokenKind
Provides a simple uniform namespace for tokens from all C languages.
Definition: TokenKinds.h:25
clang::Sema::ActOnRequiresClause
ExprResult ActOnRequiresClause(ExprResult ConstraintExpr)
Definition: SemaDeclCXX.cpp:4011
P
StringRef P
Definition: ASTMatchersInternal.cpp:563
clang::DeclaratorContext
DeclaratorContext
Definition: DeclSpec.h:1761
clang::LambdaCaptureKind
LambdaCaptureKind
The different capture forms in a lambda introducer.
Definition: Lambda.h:33
clang::TemplateIdAnnotation::TemplateNameLoc
SourceLocation TemplateNameLoc
TemplateNameLoc - The location of the template name within the source.
Definition: ParsedTemplate.h:159
clang::LCD_ByRef
@ LCD_ByRef
Definition: Lambda.h:25
clang::Parser::ParseConstraintLogicalOrExpression
ExprResult ParseConstraintLogicalOrExpression(bool IsTrailingRequiresClause)
Parse a constraint-logical-or-expression.
Definition: ParseExpr.cpp:349
clang::LambdaCaptureInitKind::ListInit
@ ListInit
[a{b}]
clang::Parser::ConsumeToken
SourceLocation ConsumeToken()
ConsumeToken - Consume the current 'peek token' and lex the next one.
Definition: Parser.h:490
clang::syntax::NodeRole::Size
@ Size
clang::ActionResult::get
PtrTy get() const
Definition: Ownership.h:169
clang::Sema::ActOnTypeTrait
ExprResult ActOnTypeTrait(TypeTrait Kind, SourceLocation KWLoc, ArrayRef< ParsedType > Args, SourceLocation RParenLoc)
Parsed one of the type trait support pseudo-functions.
Definition: SemaExprCXX.cpp:5422
clang::Sema::ActOnCompoundRequirement
concepts::Requirement * ActOnCompoundRequirement(Expr *E, SourceLocation NoexceptLoc)
Definition: SemaExprCXX.cpp:8899
clang::LCK_ByRef
@ LCK_ByRef
Capturing by reference.
Definition: Lambda.h:37
clang::Sema::ActOnExpressionTrait
ExprResult ActOnExpressionTrait(ExpressionTrait OET, SourceLocation KWLoc, Expr *Queried, SourceLocation RParen)
ActOnExpressionTrait - Parsed one of the unary type trait support pseudo-functions.
Definition: SemaExprCXX.cpp:5737
clang::TemplateName
Represents a C++ template name within the type system.
Definition: TemplateName.h:192
clang::ASTContext::getPrintingPolicy
const clang::PrintingPolicy & getPrintingPolicy() const
Definition: ASTContext.h:708
clang::Sema::ActOnCXXNestedNameSpecifierDecltype
bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS, const DeclSpec &DS, SourceLocation ColonColonLoc)
Definition: SemaCXXScopeSpec.cpp:864
clang::Parser::ParseTypeName
TypeResult ParseTypeName(SourceRange *Range=nullptr, DeclaratorContext Context=DeclaratorContext::TypeName, 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:43
clang::DeclSpec::TST_float16
static const TST TST_float16
Definition: DeclSpec.h:274
clang::DeclSpec::TST_typename
static const TST TST_typename
Definition: DeclSpec.h:288
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:83
Scope.h
clang::EnterExpressionEvaluationContext
RAII object that enters a new expression evaluation context.
Definition: Sema.h:13337
clang::frontend::After
@ After
Like System, but searched after the system directories.
Definition: HeaderSearchOptions.h:61
clang::LCK_StarThis
@ LCK_StarThis
Capturing the *this object by copy.
Definition: Lambda.h:35
clang::DeclSpec::TST_half
static const TST TST_half
Definition: DeclSpec.h:270
clang::Sema::getConstructorName
ParsedType getConstructorName(IdentifierInfo &II, SourceLocation NameLoc, Scope *S, CXXScopeSpec &SS, bool EnteringContext)
Definition: SemaExprCXX.cpp:86
clang::DeclSpec::TST_decltype_auto
static const TST TST_decltype_auto
Definition: DeclSpec.h:292
clang::Parser::DeclGroupPtrTy
OpaquePtr< DeclGroupRef > DeclGroupPtrTy
Definition: Parser.h:458
clang::ActionResult::isInvalid
bool isInvalid() const
Definition: Ownership.h:165
clang::UnqualifiedIdKind::IK_DestructorName
@ IK_DestructorName
A destructor name.
clang::Token::getName
const char * getName() const
Definition: Token.h:167
clang::Declarator::isInvalidType
bool isInvalidType() const
Definition: DeclSpec.h:2557
clang::Parser::TryConsumeToken
bool TryConsumeToken(tok::TokenKind Expected)
Definition: Parser.h:498
clang::ParsedAttributes
ParsedAttributes - A collection of parsed attributes.
Definition: ParsedAttr.h:995
clang::BalancedDelimiterTracker::getOpenLocation
SourceLocation getOpenLocation() const
Definition: RAIIObjectsForParser.h:427
clang::Sema::ActOnArrayTypeTrait
ExprResult ActOnArrayTypeTrait(ArrayTypeTrait ATT, SourceLocation KWLoc, ParsedType LhsTy, Expr *DimExpr, SourceLocation RParen)
ActOnArrayTypeTrait - Parsed one of the binary type trait support pseudo-functions.
Definition: SemaExprCXX.cpp:5648
clang::IdentifierInfo
One of these records is kept for each identifier that is lexed.
Definition: IdentifierTable.h:84
clang::Token::getLocation
SourceLocation getLocation() const
Return a source location identifier for the specified offset in the current file.
Definition: Token.h:125
addConstevalToLambdaDeclSpecifier
static void addConstevalToLambdaDeclSpecifier(Parser &P, SourceLocation ConstevalLoc, DeclSpec &DS)
Definition: ParseExprCXX.cpp:1220
clang::DeclSpec::TST_float128
static const TST TST_float128
Definition: DeclSpec.h:277
clang::SourceLocation::isMacroID
bool isMacroID() const
Definition: SourceLocation.h:103
clang::Sema::getDestructorTypeForDecltype
ParsedType getDestructorTypeForDecltype(const DeclSpec &DS, ParsedType ObjectType)
Definition: SemaExprCXX.cpp:462
clang::PrettyStackTraceLoc
If a crash happens while one of these objects are live, the message is printed out along with the spe...
Definition: PrettyStackTrace.h:26
clang::Sema::ActOnCXXNamedCast
ExprResult ActOnCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, SourceLocation LAngleBracketLoc, Declarator &D, SourceLocation RAngleBracketLoc, SourceLocation LParenLoc, Expr *E, SourceLocation RParenLoc)
ActOnCXXNamedCast - Parse {dynamic,static,reinterpret,const,addrspace}_cast's.
Definition: SemaCast.cpp:273
clang::ObjCPropertyAttribute::Kind
Kind
Definition: DeclObjCCommon.h:22
clang::Sema::RecordParsingTemplateParameterDepth
void RecordParsingTemplateParameterDepth(unsigned Depth)
This is used to inform Sema what the current TemplateParameterDepth is during Parsing.
Definition: Sema.cpp:2108
clang::Sema::ActOnPackExpansion
ParsedTemplateArgument ActOnPackExpansion(const ParsedTemplateArgument &Arg, SourceLocation EllipsisLoc)
Invoked when parsing a template argument followed by an ellipsis, which creates a pack expansion.
Definition: SemaTemplateVariadic.cpp:551
clang::ActionResult
ActionResult - This structure is used while parsing/acting on expressions, stmts, etc.
Definition: Ownership.h:152
clang::LCK_ByCopy
@ LCK_ByCopy
Capturing by copy (a.k.a., by value)
Definition: Lambda.h:36
clang::DeclSpec::TST_void
static const TST TST_void
Definition: DeclSpec.h:261
clang::LambdaCaptureInitKind::NoInit
@ NoInit
[a]
clang::Sema::ReuseLambdaContextDecl
@ ReuseLambdaContextDecl
Definition: Sema.h:5133
clang::Token::setLocation
void setLocation(SourceLocation L)
Definition: Token.h:133
clang::Sema::getDestructorName
ParsedType getDestructorName(SourceLocation TildeLoc, IdentifierInfo &II, SourceLocation NameLoc, Scope *S, CXXScopeSpec &SS, ParsedType ObjectType, bool EnteringContext)
Definition: SemaExprCXX.cpp:136
clang::DeclSpec::TST_bool
static const TST TST_bool
Definition: DeclSpec.h:279
clang::DeclSpec::TST_char32
static const TST TST_char32
Definition: DeclSpec.h:266
clang::TemplateIdAnnotation::TemplateKWLoc
SourceLocation TemplateKWLoc
TemplateKWLoc - The location of the template keyword.
Definition: ParsedTemplate.h:155
clang::DeclSpec::takeAttributesFrom
void takeAttributesFrom(ParsedAttributes &attrs)
Definition: DeclSpec.h:798
clang::TypeSpecifierSign::Unsigned
@ Unsigned
clang::LambdaIntroducer::DefaultLoc
SourceLocation DefaultLoc
Definition: DeclSpec.h:2690
clang::StmtResult
ActionResult< Stmt * > StmtResult
Definition: Ownership.h:263
clang::DeclaratorContext::TypeName
@ TypeName
clang::Sema::ActOnSuperScopeSpecifier
bool ActOnSuperScopeSpecifier(SourceLocation SuperLoc, SourceLocation ColonColonLoc, CXXScopeSpec &SS)
The parser has parsed a '__super' nested-name-specifier.
Definition: SemaCXXScopeSpec.cpp:292
clang::IdentifierInfo::getName
StringRef getName() const
Return the actual identifier string.
Definition: IdentifierTable.h:195
clang::SourceLocation::isInvalid
bool isInvalid() const
Definition: SourceLocation.h:111
clang
Definition: CalledOnceCheck.h:17
addConstexprToLambdaDeclSpecifier
static void addConstexprToLambdaDeclSpecifier(Parser &P, SourceLocation ConstexprLoc, DeclSpec &DS)
Definition: ParseExprCXX.cpp:1205
clang::Sema::ActOnConditionVariable
ConditionResult ActOnConditionVariable(Decl *ConditionVar, SourceLocation StmtLoc, ConditionKind CK)
Definition: SemaExprCXX.cpp:3907
clang::TemplateIdAnnotation::Name
IdentifierInfo * Name
FIXME: Temporarily stores the name of a specialization.
Definition: ParsedTemplate.h:162
clang::PreferredTypeBuilder::enterTypeCast
void enterTypeCast(SourceLocation Tok, QualType CastType)
Handles all type casts, including C-style cast, C++ casts, etc.
Definition: SemaCodeComplete.cpp:594
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:69
clang::TemplateIdAnnotation::getTemplateArgs
ParsedTemplateArgument * getTemplateArgs()
Retrieves a pointer to the template arguments.
Definition: ParsedTemplate.h:192
clang::Declarator
Information about one declarator, including the parsed type information and the identifier.
Definition: DeclSpec.h:1803
clang::DeclaratorContext::Condition
@ Condition
clang::LambdaCaptureInitKind::CopyInit
@ CopyInit
[a = b], [a = {b}]
clang::Sema::ActOnCXXThrow
ExprResult ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr *expr)
ActOnCXXThrow - Parse throw expressions.
Definition: SemaExprCXX.cpp:823
clang::SourceLocation::isValid
bool isValid() const
Return true if this is a valid SourceLocation object.
Definition: SourceLocation.h:110
clang::DeclaratorContext::FunctionalCast
@ FunctionalCast
clang::Sema::RestoreNestedNameSpecifierAnnotation
void RestoreNestedNameSpecifierAnnotation(void *Annotation, SourceRange AnnotationRange, CXXScopeSpec &SS)
Given an annotation pointer for a nested-name-specifier, restore the nested-name-specifier structure.
Definition: SemaCXXScopeSpec.cpp:1026
clang::Token::setLength
void setLength(unsigned Len)
Definition: Token.h:134
clang::Attr
Attr - This represents one attribute.
Definition: Attr.h:41
clang::FixItHint::CreateRemoval
static FixItHint CreateRemoval(CharSourceRange RemoveRange)
Create a code modification hint that removes the given source range.
Definition: Diagnostic.h:123
clang::Sema::ActOnCXXThis
ExprResult ActOnCXXThis(SourceLocation loc)
Definition: SemaExprCXX.cpp:1378
clang::Preprocessor::getLocForEndOfToken
SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset=0)
Computes the source location just past the end of the token at this source location.
Definition: Preprocessor.h:1930
clang::Token::setKind
void setKind(tok::TokenKind K)
Definition: Token.h:93
clang::Sema::ActOnParenExpr
ExprResult ActOnParenExpr(SourceLocation L, SourceLocation R, Expr *E)
Definition: SemaExpr.cpp:4156
ParseDiagnostic.h
clang::Stmt::getBeginLoc
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: Stmt.cpp:336
clang::Sema::ActOnCondition
ConditionResult ActOnCondition(Scope *S, SourceLocation Loc, Expr *SubExpr, ConditionKind CK, bool MissingOK=false)
Definition: SemaExpr.cpp:19881
clang::LCK_This
@ LCK_This
Capturing the *this object by reference.
Definition: Lambda.h:34
clang::BalancedDelimiterTracker::consumeClose
bool consumeClose()
Definition: RAIIObjectsForParser.h:446
clang::TemplateIdAnnotation::isInvalid
bool isInvalid() const
Definition: ParsedTemplate.h:233
clang::Sema::ActOnStartRequiresExpr
RequiresExprBodyDecl * ActOnStartRequiresExpr(SourceLocation RequiresKWLoc, ArrayRef< ParmVarDecl * > LocalParameters, Scope *BodyScope)
Definition: SemaExprCXX.cpp:9031
clang::Token::isOneOf
bool isOneOf(tok::TokenKind K1, tok::TokenKind K2) const
Definition: Token.h:99
clang::Parser::getTypeAnnotation
static TypeResult getTypeAnnotation(const Token &Tok)
getTypeAnnotation - Read a parsed type out of an annotation token.
Definition: Parser.h:810
clang::DeclaratorContext::ConversionId
@ ConversionId
clang::DeclaratorContext::CXXNew
@ CXXNew
tryConsumeLambdaSpecifierToken
static void tryConsumeLambdaSpecifierToken(Parser &P, SourceLocation &MutableLoc, SourceLocation &ConstexprLoc, SourceLocation &ConstevalLoc, SourceLocation &DeclEndLoc)
Definition: ParseExprCXX.cpp:1157
clang::Sema::ProduceConstructorSignatureHelp
QualType ProduceConstructorSignatureHelp(QualType Type, SourceLocation Loc, ArrayRef< Expr * > Args, SourceLocation OpenParLoc, bool Braced)
Definition: SemaCodeComplete.cpp:6163
clang::CPlusPlus11
@ CPlusPlus11
Definition: LangStandard.h:54
clang::Lexer::AdvanceToTokenCharacter
static SourceLocation AdvanceToTokenCharacter(SourceLocation TokStart, unsigned Characters, const SourceManager &SM, const LangOptions &LangOpts)
AdvanceToTokenCharacter - If the current SourceLocation specifies a location at the start of a token,...
Definition: Lexer.h:380
FixDigraph
static void FixDigraph(Parser &P, Preprocessor &PP, Token &DigraphToken, Token &ColonToken, tok::TokenKind Kind, bool AtDigraph)
Definition: ParseExprCXX.cpp:53
clang::Lexer::getLocForEndOfToken
static SourceLocation getLocForEndOfToken(SourceLocation Loc, unsigned Offset, const SourceManager &SM, const LangOptions &LangOpts)
Computes the source location just past the end of the token at this source location.
Definition: Lexer.cpp:788
clang::Sema::ActOnTemplateIdType
TypeResult ActOnTemplateIdType(Scope *S, CXXScopeSpec &SS, SourceLocation TemplateKWLoc, TemplateTy Template, IdentifierInfo *TemplateII, SourceLocation TemplateIILoc, SourceLocation LAngleLoc, ASTTemplateArgsPtr TemplateArgs, SourceLocation RAngleLoc, bool IsCtorOrDtorName=false, bool IsClassName=false)
Definition: SemaTemplate.cpp:3909
clang::comments::tok::eof
@ eof
Definition: CommentLexer.h:33
llvm::SmallVectorImpl
Definition: Randstruct.h:18
clang::Scope::DeclScope
@ DeclScope
This is a scope that can contain a declaration.
Definition: Scope.h:59
clang::DeclSpec::Finish
void Finish(Sema &S, const PrintingPolicy &Policy)
Finish - This does final analysis of the declspec, issuing diagnostics for things like "_Imaginary" (...
Definition: DeclSpec.cpp:1115
clang::Scope::BreakScope
@ BreakScope
This is a while, do, switch, for, etc that can have break statements embedded into it.
Definition: Scope.h:51
clang::UnqualifiedId::isValid
bool isValid() const
Determine whether this unqualified-id refers to a valid name.
Definition: DeclSpec.h:1026
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::Preprocessor
Engages in a tight little dance with the lexer to efficiently preprocess tokens.
Definition: Preprocessor.h:131
clang::DeclSpec::TST_wchar
static const TST TST_wchar
Definition: DeclSpec.h:263
clang::CXXScopeSpec::isEmpty
bool isEmpty() const
No scope specifier.
Definition: DeclSpec.h:190
SM
#define SM(sm)
Definition: Cuda.cpp:81
clang::Sema::NestedNameSpecInfo
Keeps information about an identifier in a nested-name-spec.
Definition: Sema.h:6650
clang::Sema::isCurrentClassName
bool isCurrentClassName(const IdentifierInfo &II, Scope *S, const CXXScopeSpec *SS=nullptr)
isCurrentClassName - Determine whether the identifier II is the name of the class type currently bein...
Definition: SemaDeclCXX.cpp:2430
clang::CXXScopeSpec::getRange
SourceRange getRange() const
Definition: DeclSpec.h:69
clang::DeclSpec::SetRangeEnd
void SetRangeEnd(SourceLocation Loc)
Definition: DeclSpec.h:639
clang::StringLiteralParser
StringLiteralParser - This decodes string escape characters and performs wide string analysis and Tra...
Definition: LiteralSupport.h:218
clang::DeclaratorChunk::getArray
static DeclaratorChunk getArray(unsigned TypeQuals, bool isStatic, bool isStar, Expr *NumElts, SourceLocation LBLoc, SourceLocation RBLoc)
Return a DeclaratorChunk for an array.
Definition: DeclSpec.h:1608
clang::Sema::ActOnNameClassifiedAsNonType
ExprResult ActOnNameClassifiedAsNonType(Scope *S, const CXXScopeSpec &SS, NamedDecl *Found, SourceLocation NameLoc, const Token &NextToken)
Act on the result of classifying a name as a specific non-type declaration.
Definition: SemaDecl.cpp:1255
clang::CXXScopeSpec::getBeginLoc
SourceLocation getBeginLoc() const
Definition: DeclSpec.h:73
clang::Sema::ActOnCXXNestedNameSpecifier
bool ActOnCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo &IdInfo, bool EnteringContext, CXXScopeSpec &SS, bool ErrorRecoveryLookup=false, bool *IsCorrectedToColon=nullptr, bool OnlyNamespace=false)
The parser has parsed a nested-name-specifier 'identifier::'.
Definition: SemaCXXScopeSpec.cpp:851
clang::TypeSpecifierWidth::Short
@ Short
clang::Sema::ActOnLambdaExpr
ExprResult ActOnLambdaExpr(SourceLocation StartLoc, Stmt *Body, Scope *CurScope)
ActOnLambdaExpr - This is called when the body of a lambda expression was successfully completed.
Definition: SemaLambda.cpp:1632
clang::CastExpr
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3475
clang::DeclSpec::TST_auto
static const TST TST_auto
Definition: DeclSpec.h:294
clang::Parser::NextToken
const Token & NextToken()
NextToken - This peeks ahead one token and returns it without consuming it.
Definition: Parser.h:805
clang::Decl::getLocation
SourceLocation getLocation() const
Definition: DeclBase.h:425
clang::Parser::IsTypeCast
@ IsTypeCast
Definition: Parser.h:1746
clang::RISCV::Invalid
@ Invalid
Definition: RISCVVIntrinsicUtils.h:148
clang::Sema::isTemplateName
TemplateNameKind isTemplateName(Scope *S, CXXScopeSpec &SS, bool hasTemplateKeyword, const UnqualifiedId &Name, ParsedType ObjectType, bool EnteringContext, TemplateTy &Template, bool &MemberOfUnknownSpecialization, bool Disambiguation=false)
Definition: SemaTemplate.cpp:172
clang::DeclSpec::TST_char16
static const TST TST_char16
Definition: DeclSpec.h:265
clang::Sema::ActOnCXXTypeConstructExpr
ExprResult ActOnCXXTypeConstructExpr(ParsedType TypeRep, SourceLocation LParenOrBraceLoc, MultiExprArg Exprs, SourceLocation RParenOrBraceLoc, bool ListInitialization)
ActOnCXXTypeConstructExpr - Parse construction of a specified type.
Definition: SemaExprCXX.cpp:1417
clang::Sema::ActOnCXXUuidof
ExprResult ActOnCXXUuidof(SourceLocation OpLoc, SourceLocation LParenLoc, bool isType, void *TyOrExpr, SourceLocation RParenLoc)
ActOnCXXUuidof - Parse __uuidof( something ).
Definition: SemaExprCXX.cpp:783
clang::DeclSpec::SetTypeSpecWidth
bool SetTypeSpecWidth(TypeSpecifierWidth W, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
These methods set the specified attribute of the DeclSpec, but return true and ignore the request if ...
Definition: DeclSpec.cpp:694
clang::diag::kind
unsigned kind
All of the diagnostics that can be emitted by the frontend.
Definition: DiagnosticIDs.h:62
clang::TemplateIdAnnotation::Template
ParsedTemplateTy Template
The declaration of the template corresponding to the template-name.
Definition: ParsedTemplate.h:169
clang::TypeSpecifierWidth::Long
@ Long
clang::Preprocessor::RevertCachedTokens
void RevertCachedTokens(unsigned N)
When backtracking is enabled and tokens are cached, this allows to revert a specific number of tokens...
Definition: Preprocessor.h:1589
clang::Sema::isDeductionGuideName
bool isDeductionGuideName(Scope *S, const IdentifierInfo &Name, SourceLocation NameLoc, ParsedTemplateTy *Template=nullptr)
Determine whether a particular identifier might be the name in a C++1z deduction-guide declaration.
Definition: SemaTemplate.cpp:316
clang::ActionResult::isUsable
bool isUsable() const
Definition: Ownership.h:166
clang::CXXScopeSpec::isNotEmpty
bool isNotEmpty() const
A scope specifier is present, but may be valid or invalid.
Definition: DeclSpec.h:192
clang::DeclSpec::SetTypeSpecType
bool SetTypeSpecType(TST T, SourceLocation Loc, const char *&PrevSpec, unsigned &DiagID, const PrintingPolicy &Policy)
Definition: DeclSpec.cpp:824
clang::FixItHint::CreateReplacement
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:134
clang::Sema::CodeCompleteObjCMessageReceiver
void CodeCompleteObjCMessageReceiver(Scope *S)
Definition: SemaCodeComplete.cpp:7790
clang::Sema::ActOnFinishRequiresExpr
void ActOnFinishRequiresExpr()
Definition: SemaExprCXX.cpp:9060
clang::DeclSpec
Captures information about "declaration specifiers".
Definition: DeclSpec.h:229
ParsedTemplate.h
clang::LambdaIntroducer::Range
SourceRange Range
Definition: DeclSpec.h:2689
clang::Declarator::getMutableDeclSpec
DeclSpec & getMutableDeclSpec()
getMutableDeclSpec - Return a non-const version of the DeclSpec.
Definition: DeclSpec.h:1917
clang::Sema::CorrectDelayedTyposInExpr
ExprResult CorrectDelayedTyposInExpr(Expr *E, VarDecl *InitDecl=nullptr, bool RecoverUncorrectedTypos=false, 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...
Definition: SemaExprCXX.cpp:8680
clang::Sema::ExpressionEvaluationContext::PotentiallyEvaluated
@ PotentiallyEvaluated
The current expression is potentially evaluated at run time, which means that code may be generated t...
Parser.h
clang::ExpressionTrait
ExpressionTrait
Definition: ExpressionTraits.h:21
clang::Token::hasLeadingEmptyMacro
bool hasLeadingEmptyMacro() const
Return true if this token has an empty macro before it.
Definition: Token.h:288