clang  3.9.0
SemaCXXScopeSpec.cpp
Go to the documentation of this file.
1 //===--- SemaCXXScopeSpec.cpp - Semantic Analysis for C++ scope specifiers-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements C++ semantic analysis for scope specifiers.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "TypeLocBuilder.h"
16 #include "clang/AST/ASTContext.h"
17 #include "clang/AST/DeclTemplate.h"
18 #include "clang/AST/ExprCXX.h"
21 #include "clang/Sema/DeclSpec.h"
22 #include "clang/Sema/Lookup.h"
23 #include "clang/Sema/Template.h"
24 #include "llvm/ADT/STLExtras.h"
25 #include "llvm/Support/raw_ostream.h"
26 using namespace clang;
27 
28 /// \brief Find the current instantiation that associated with the given type.
30  DeclContext *CurContext) {
31  if (T.isNull())
32  return nullptr;
33 
34  const Type *Ty = T->getCanonicalTypeInternal().getTypePtr();
35  if (const RecordType *RecordTy = dyn_cast<RecordType>(Ty)) {
36  CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordTy->getDecl());
37  if (!Record->isDependentContext() ||
38  Record->isCurrentInstantiation(CurContext))
39  return Record;
40 
41  return nullptr;
42  } else if (isa<InjectedClassNameType>(Ty))
43  return cast<InjectedClassNameType>(Ty)->getDecl();
44  else
45  return nullptr;
46 }
47 
48 /// \brief Compute the DeclContext that is associated with the given type.
49 ///
50 /// \param T the type for which we are attempting to find a DeclContext.
51 ///
52 /// \returns the declaration context represented by the type T,
53 /// or NULL if the declaration context cannot be computed (e.g., because it is
54 /// dependent and not the current instantiation).
56  if (!T->isDependentType())
57  if (const TagType *Tag = T->getAs<TagType>())
58  return Tag->getDecl();
59 
61 }
62 
63 /// \brief Compute the DeclContext that is associated with the given
64 /// scope specifier.
65 ///
66 /// \param SS the C++ scope specifier as it appears in the source
67 ///
68 /// \param EnteringContext when true, we will be entering the context of
69 /// this scope specifier, so we can retrieve the declaration context of a
70 /// class template or class template partial specialization even if it is
71 /// not the current instantiation.
72 ///
73 /// \returns the declaration context represented by the scope specifier @p SS,
74 /// or NULL if the declaration context cannot be computed (e.g., because it is
75 /// dependent and not the current instantiation).
77  bool EnteringContext) {
78  if (!SS.isSet() || SS.isInvalid())
79  return nullptr;
80 
81  NestedNameSpecifier *NNS = SS.getScopeRep();
82  if (NNS->isDependent()) {
83  // If this nested-name-specifier refers to the current
84  // instantiation, return its DeclContext.
85  if (CXXRecordDecl *Record = getCurrentInstantiationOf(NNS))
86  return Record;
87 
88  if (EnteringContext) {
89  const Type *NNSType = NNS->getAsType();
90  if (!NNSType) {
91  return nullptr;
92  }
93 
94  // Look through type alias templates, per C++0x [temp.dep.type]p1.
95  NNSType = Context.getCanonicalType(NNSType);
96  if (const TemplateSpecializationType *SpecType
97  = NNSType->getAs<TemplateSpecializationType>()) {
98  // We are entering the context of the nested name specifier, so try to
99  // match the nested name specifier to either a primary class template
100  // or a class template partial specialization.
101  if (ClassTemplateDecl *ClassTemplate
102  = dyn_cast_or_null<ClassTemplateDecl>(
103  SpecType->getTemplateName().getAsTemplateDecl())) {
104  QualType ContextType
105  = Context.getCanonicalType(QualType(SpecType, 0));
106 
107  // If the type of the nested name specifier is the same as the
108  // injected class name of the named class template, we're entering
109  // into that class template definition.
110  QualType Injected
111  = ClassTemplate->getInjectedClassNameSpecialization();
112  if (Context.hasSameType(Injected, ContextType))
113  return ClassTemplate->getTemplatedDecl();
114 
115  // If the type of the nested name specifier is the same as the
116  // type of one of the class template's class template partial
117  // specializations, we're entering into the definition of that
118  // class template partial specialization.
120  = ClassTemplate->findPartialSpecialization(ContextType)) {
121  // A declaration of the partial specialization must be visible.
122  // We can always recover here, because this only happens when we're
123  // entering the context, and that can't happen in a SFINAE context.
124  assert(!isSFINAEContext() &&
125  "partial specialization scope specifier in SFINAE context?");
126  if (!hasVisibleDeclaration(PartialSpec))
129  /*Recover*/true);
130  return PartialSpec;
131  }
132  }
133  } else if (const RecordType *RecordT = NNSType->getAs<RecordType>()) {
134  // The nested name specifier refers to a member of a class template.
135  return RecordT->getDecl();
136  }
137  }
138 
139  return nullptr;
140  }
141 
142  switch (NNS->getKind()) {
144  llvm_unreachable("Dependent nested-name-specifier has no DeclContext");
145 
147  return NNS->getAsNamespace();
148 
150  return NNS->getAsNamespaceAlias()->getNamespace();
151 
154  const TagType *Tag = NNS->getAsType()->getAs<TagType>();
155  assert(Tag && "Non-tag type in nested-name-specifier");
156  return Tag->getDecl();
157  }
158 
161 
163  return NNS->getAsRecordDecl();
164  }
165 
166  llvm_unreachable("Invalid NestedNameSpecifier::Kind!");
167 }
168 
170  if (!SS.isSet() || SS.isInvalid())
171  return false;
172 
173  return SS.getScopeRep()->isDependent();
174 }
175 
176 /// \brief If the given nested name specifier refers to the current
177 /// instantiation, return the declaration that corresponds to that
178 /// current instantiation (C++0x [temp.dep.type]p1).
179 ///
180 /// \param NNS a dependent nested name specifier.
182  assert(getLangOpts().CPlusPlus && "Only callable in C++");
183  assert(NNS->isDependent() && "Only dependent nested-name-specifier allowed");
184 
185  if (!NNS->getAsType())
186  return nullptr;
187 
188  QualType T = QualType(NNS->getAsType(), 0);
190 }
191 
192 /// \brief Require that the context specified by SS be complete.
193 ///
194 /// If SS refers to a type, this routine checks whether the type is
195 /// complete enough (or can be made complete enough) for name lookup
196 /// into the DeclContext. A type that is not yet completed can be
197 /// considered "complete enough" if it is a class/struct/union/enum
198 /// that is currently being defined. Or, if we have a type that names
199 /// a class template specialization that is not a complete type, we
200 /// will attempt to instantiate that class template.
202  DeclContext *DC) {
203  assert(DC && "given null context");
204 
205  TagDecl *tag = dyn_cast<TagDecl>(DC);
206 
207  // If this is a dependent type, then we consider it complete.
208  // FIXME: This is wrong; we should require a (visible) definition to
209  // exist in this case too.
210  if (!tag || tag->isDependentContext())
211  return false;
212 
213  // If we're currently defining this type, then lookup into the
214  // type is okay: don't complain that it isn't complete yet.
216  const TagType *tagType = type->getAs<TagType>();
217  if (tagType && tagType->isBeingDefined())
218  return false;
219 
221  if (loc.isInvalid()) loc = SS.getRange().getBegin();
222 
223  // The type must be complete.
224  if (RequireCompleteType(loc, type, diag::err_incomplete_nested_name_spec,
225  SS.getRange())) {
226  SS.SetInvalid(SS.getRange());
227  return true;
228  }
229 
230  // Fixed enum types are complete, but they aren't valid as scopes
231  // until we see a definition, so awkwardly pull out this special
232  // case.
233  const EnumType *enumType = dyn_cast_or_null<EnumType>(tagType);
234  if (!enumType)
235  return false;
236  if (enumType->getDecl()->isCompleteDefinition()) {
237  // If we know about the definition but it is not visible, complain.
238  NamedDecl *SuggestedDef = nullptr;
239  if (!hasVisibleDefinition(enumType->getDecl(), &SuggestedDef,
240  /*OnlyNeedComplete*/false)) {
241  // If the user is going to see an error here, recover by making the
242  // definition visible.
243  bool TreatAsComplete = !isSFINAEContext();
245  /*Recover*/TreatAsComplete);
246  return !TreatAsComplete;
247  }
248  return false;
249  }
250 
251  // Try to instantiate the definition, if this is a specialization of an
252  // enumeration temploid.
253  EnumDecl *ED = enumType->getDecl();
254  if (EnumDecl *Pattern = ED->getInstantiatedFromMemberEnum()) {
257  if (InstantiateEnum(loc, ED, Pattern, getTemplateInstantiationArgs(ED),
259  SS.SetInvalid(SS.getRange());
260  return true;
261  }
262  return false;
263  }
264  }
265 
266  Diag(loc, diag::err_incomplete_nested_name_spec)
267  << type << SS.getRange();
268  SS.SetInvalid(SS.getRange());
269  return true;
270 }
271 
273  CXXScopeSpec &SS) {
274  SS.MakeGlobal(Context, CCLoc);
275  return false;
276 }
277 
279  SourceLocation ColonColonLoc,
280  CXXScopeSpec &SS) {
281  CXXRecordDecl *RD = nullptr;
282  for (Scope *S = getCurScope(); S; S = S->getParent()) {
283  if (S->isFunctionScope()) {
284  if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(S->getEntity()))
285  RD = MD->getParent();
286  break;
287  }
288  if (S->isClassScope()) {
289  RD = cast<CXXRecordDecl>(S->getEntity());
290  break;
291  }
292  }
293 
294  if (!RD) {
295  Diag(SuperLoc, diag::err_invalid_super_scope);
296  return true;
297  } else if (RD->isLambda()) {
298  Diag(SuperLoc, diag::err_super_in_lambda_unsupported);
299  return true;
300  } else if (RD->getNumBases() == 0) {
301  Diag(SuperLoc, diag::err_no_base_classes) << RD->getName();
302  return true;
303  }
304 
305  SS.MakeSuper(Context, RD, SuperLoc, ColonColonLoc);
306  return false;
307 }
308 
309 /// \brief Determines whether the given declaration is an valid acceptable
310 /// result for name lookup of a nested-name-specifier.
311 /// \param SD Declaration checked for nested-name-specifier.
312 /// \param IsExtension If not null and the declaration is accepted as an
313 /// extension, the pointed variable is assigned true.
315  bool *IsExtension) {
316  if (!SD)
317  return false;
318 
319  SD = SD->getUnderlyingDecl();
320 
321  // Namespace and namespace aliases are fine.
322  if (isa<NamespaceDecl>(SD))
323  return true;
324 
325  if (!isa<TypeDecl>(SD))
326  return false;
327 
328  // Determine whether we have a class (or, in C++11, an enum) or
329  // a typedef thereof. If so, build the nested-name-specifier.
330  QualType T = Context.getTypeDeclType(cast<TypeDecl>(SD));
331  if (T->isDependentType())
332  return true;
333  if (const TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(SD)) {
334  if (TD->getUnderlyingType()->isRecordType())
335  return true;
336  if (TD->getUnderlyingType()->isEnumeralType()) {
337  if (Context.getLangOpts().CPlusPlus11)
338  return true;
339  if (IsExtension)
340  *IsExtension = true;
341  }
342  } else if (isa<RecordDecl>(SD)) {
343  return true;
344  } else if (isa<EnumDecl>(SD)) {
345  if (Context.getLangOpts().CPlusPlus11)
346  return true;
347  if (IsExtension)
348  *IsExtension = true;
349  }
350 
351  return false;
352 }
353 
354 /// \brief If the given nested-name-specifier begins with a bare identifier
355 /// (e.g., Base::), perform name lookup for that identifier as a
356 /// nested-name-specifier within the given scope, and return the result of that
357 /// name lookup.
359  if (!S || !NNS)
360  return nullptr;
361 
362  while (NNS->getPrefix())
363  NNS = NNS->getPrefix();
364 
366  return nullptr;
367 
368  LookupResult Found(*this, NNS->getAsIdentifier(), SourceLocation(),
370  LookupName(Found, S);
371  assert(!Found.isAmbiguous() && "Cannot handle ambiguities here yet");
372 
373  if (!Found.isSingleResult())
374  return nullptr;
375 
376  NamedDecl *Result = Found.getFoundDecl();
378  return Result;
379 
380  return nullptr;
381 }
382 
384  SourceLocation IdLoc,
385  IdentifierInfo &II,
386  ParsedType ObjectTypePtr) {
387  QualType ObjectType = GetTypeFromParser(ObjectTypePtr);
388  LookupResult Found(*this, &II, IdLoc, LookupNestedNameSpecifierName);
389 
390  // Determine where to perform name lookup
391  DeclContext *LookupCtx = nullptr;
392  bool isDependent = false;
393  if (!ObjectType.isNull()) {
394  // This nested-name-specifier occurs in a member access expression, e.g.,
395  // x->B::f, and we are looking into the type of the object.
396  assert(!SS.isSet() && "ObjectType and scope specifier cannot coexist");
397  LookupCtx = computeDeclContext(ObjectType);
398  isDependent = ObjectType->isDependentType();
399  } else if (SS.isSet()) {
400  // This nested-name-specifier occurs after another nested-name-specifier,
401  // so long into the context associated with the prior nested-name-specifier.
402  LookupCtx = computeDeclContext(SS, false);
403  isDependent = isDependentScopeSpecifier(SS);
404  Found.setContextRange(SS.getRange());
405  }
406 
407  if (LookupCtx) {
408  // Perform "qualified" name lookup into the declaration context we
409  // computed, which is either the type of the base of a member access
410  // expression or the declaration context associated with a prior
411  // nested-name-specifier.
412 
413  // The declaration context must be complete.
414  if (!LookupCtx->isDependentContext() &&
415  RequireCompleteDeclContext(SS, LookupCtx))
416  return false;
417 
418  LookupQualifiedName(Found, LookupCtx);
419  } else if (isDependent) {
420  return false;
421  } else {
422  LookupName(Found, S);
423  }
424  Found.suppressDiagnostics();
425 
426  return Found.getAsSingle<NamespaceDecl>();
427 }
428 
429 namespace {
430 
431 // Callback to only accept typo corrections that can be a valid C++ member
432 // intializer: either a non-static field member or a base class.
433 class NestedNameSpecifierValidatorCCC : public CorrectionCandidateCallback {
434  public:
435  explicit NestedNameSpecifierValidatorCCC(Sema &SRef)
436  : SRef(SRef) {}
437 
438  bool ValidateCandidate(const TypoCorrection &candidate) override {
439  return SRef.isAcceptableNestedNameSpecifier(candidate.getCorrectionDecl());
440  }
441 
442  private:
443  Sema &SRef;
444 };
445 
446 }
447 
448 /// \brief Build a new nested-name-specifier for "identifier::", as described
449 /// by ActOnCXXNestedNameSpecifier.
450 ///
451 /// \param S Scope in which the nested-name-specifier occurs.
452 /// \param Identifier Identifier in the sequence "identifier" "::".
453 /// \param IdentifierLoc Location of the \p Identifier.
454 /// \param CCLoc Location of "::" following Identifier.
455 /// \param ObjectType Type of postfix expression if the nested-name-specifier
456 /// occurs in construct like: <tt>ptr->nns::f</tt>.
457 /// \param EnteringContext If true, enter the context specified by the
458 /// nested-name-specifier.
459 /// \param SS Optional nested name specifier preceding the identifier.
460 /// \param ScopeLookupResult Provides the result of name lookup within the
461 /// scope of the nested-name-specifier that was computed at template
462 /// definition time.
463 /// \param ErrorRecoveryLookup Specifies if the method is called to improve
464 /// error recovery and what kind of recovery is performed.
465 /// \param IsCorrectedToColon If not null, suggestion of replace '::' -> ':'
466 /// are allowed. The bool value pointed by this parameter is set to
467 /// 'true' if the identifier is treated as if it was followed by ':',
468 /// not '::'.
469 ///
470 /// This routine differs only slightly from ActOnCXXNestedNameSpecifier, in
471 /// that it contains an extra parameter \p ScopeLookupResult, which provides
472 /// the result of name lookup within the scope of the nested-name-specifier
473 /// that was computed at template definition time.
474 ///
475 /// If ErrorRecoveryLookup is true, then this call is used to improve error
476 /// recovery. This means that it should not emit diagnostics, it should
477 /// just return true on failure. It also means it should only return a valid
478 /// scope if it *knows* that the result is correct. It should not return in a
479 /// dependent context, for example. Nor will it extend \p SS with the scope
480 /// specifier.
482  IdentifierInfo &Identifier,
484  SourceLocation CCLoc,
485  QualType ObjectType,
486  bool EnteringContext,
487  CXXScopeSpec &SS,
488  NamedDecl *ScopeLookupResult,
489  bool ErrorRecoveryLookup,
490  bool *IsCorrectedToColon) {
491  LookupResult Found(*this, &Identifier, IdentifierLoc,
493 
494  // Determine where to perform name lookup
495  DeclContext *LookupCtx = nullptr;
496  bool isDependent = false;
497  if (IsCorrectedToColon)
498  *IsCorrectedToColon = false;
499  if (!ObjectType.isNull()) {
500  // This nested-name-specifier occurs in a member access expression, e.g.,
501  // x->B::f, and we are looking into the type of the object.
502  assert(!SS.isSet() && "ObjectType and scope specifier cannot coexist");
503  LookupCtx = computeDeclContext(ObjectType);
504  isDependent = ObjectType->isDependentType();
505  } else if (SS.isSet()) {
506  // This nested-name-specifier occurs after another nested-name-specifier,
507  // so look into the context associated with the prior nested-name-specifier.
508  LookupCtx = computeDeclContext(SS, EnteringContext);
509  isDependent = isDependentScopeSpecifier(SS);
510  Found.setContextRange(SS.getRange());
511  }
512 
513  bool ObjectTypeSearchedInScope = false;
514  if (LookupCtx) {
515  // Perform "qualified" name lookup into the declaration context we
516  // computed, which is either the type of the base of a member access
517  // expression or the declaration context associated with a prior
518  // nested-name-specifier.
519 
520  // The declaration context must be complete.
521  if (!LookupCtx->isDependentContext() &&
522  RequireCompleteDeclContext(SS, LookupCtx))
523  return true;
524 
525  LookupQualifiedName(Found, LookupCtx);
526 
527  if (!ObjectType.isNull() && Found.empty()) {
528  // C++ [basic.lookup.classref]p4:
529  // If the id-expression in a class member access is a qualified-id of
530  // the form
531  //
532  // class-name-or-namespace-name::...
533  //
534  // the class-name-or-namespace-name following the . or -> operator is
535  // looked up both in the context of the entire postfix-expression and in
536  // the scope of the class of the object expression. If the name is found
537  // only in the scope of the class of the object expression, the name
538  // shall refer to a class-name. If the name is found only in the
539  // context of the entire postfix-expression, the name shall refer to a
540  // class-name or namespace-name. [...]
541  //
542  // Qualified name lookup into a class will not find a namespace-name,
543  // so we do not need to diagnose that case specifically. However,
544  // this qualified name lookup may find nothing. In that case, perform
545  // unqualified name lookup in the given scope (if available) or
546  // reconstruct the result from when name lookup was performed at template
547  // definition time.
548  if (S)
549  LookupName(Found, S);
550  else if (ScopeLookupResult)
551  Found.addDecl(ScopeLookupResult);
552 
553  ObjectTypeSearchedInScope = true;
554  }
555  } else if (!isDependent) {
556  // Perform unqualified name lookup in the current scope.
557  LookupName(Found, S);
558  }
559 
560  if (Found.isAmbiguous())
561  return true;
562 
563  // If we performed lookup into a dependent context and did not find anything,
564  // that's fine: just build a dependent nested-name-specifier.
565  if (Found.empty() && isDependent &&
566  !(LookupCtx && LookupCtx->isRecord() &&
567  (!cast<CXXRecordDecl>(LookupCtx)->hasDefinition() ||
568  !cast<CXXRecordDecl>(LookupCtx)->hasAnyDependentBases()))) {
569  // Don't speculate if we're just trying to improve error recovery.
570  if (ErrorRecoveryLookup)
571  return true;
572 
573  // We were not able to compute the declaration context for a dependent
574  // base object type or prior nested-name-specifier, so this
575  // nested-name-specifier refers to an unknown specialization. Just build
576  // a dependent nested-name-specifier.
577  SS.Extend(Context, &Identifier, IdentifierLoc, CCLoc);
578  return false;
579  }
580 
581  if (Found.empty() && !ErrorRecoveryLookup) {
582  // If identifier is not found as class-name-or-namespace-name, but is found
583  // as other entity, don't look for typos.
585  if (LookupCtx)
586  LookupQualifiedName(R, LookupCtx);
587  else if (S && !isDependent)
588  LookupName(R, S);
589  if (!R.empty()) {
590  // Don't diagnose problems with this speculative lookup.
591  R.suppressDiagnostics();
592  // The identifier is found in ordinary lookup. If correction to colon is
593  // allowed, suggest replacement to ':'.
594  if (IsCorrectedToColon) {
595  *IsCorrectedToColon = true;
596  Diag(CCLoc, diag::err_nested_name_spec_is_not_class)
597  << &Identifier << getLangOpts().CPlusPlus
598  << FixItHint::CreateReplacement(CCLoc, ":");
599  if (NamedDecl *ND = R.getAsSingle<NamedDecl>())
600  Diag(ND->getLocation(), diag::note_declared_at);
601  return true;
602  }
603  // Replacement '::' -> ':' is not allowed, just issue respective error.
604  Diag(R.getNameLoc(), diag::err_expected_class_or_namespace)
605  << &Identifier << getLangOpts().CPlusPlus;
606  if (NamedDecl *ND = R.getAsSingle<NamedDecl>())
607  Diag(ND->getLocation(), diag::note_entity_declared_at) << &Identifier;
608  return true;
609  }
610  }
611 
612  if (Found.empty() && !ErrorRecoveryLookup && !getLangOpts().MSVCCompat) {
613  // We haven't found anything, and we're not recovering from a
614  // different kind of error, so look for typos.
616  Found.clear();
617  if (TypoCorrection Corrected = CorrectTypo(
618  Found.getLookupNameInfo(), Found.getLookupKind(), S, &SS,
619  llvm::make_unique<NestedNameSpecifierValidatorCCC>(*this),
620  CTK_ErrorRecovery, LookupCtx, EnteringContext)) {
621  if (LookupCtx) {
622  bool DroppedSpecifier =
623  Corrected.WillReplaceSpecifier() &&
624  Name.getAsString() == Corrected.getAsString(getLangOpts());
625  if (DroppedSpecifier)
626  SS.clear();
627  diagnoseTypo(Corrected, PDiag(diag::err_no_member_suggest)
628  << Name << LookupCtx << DroppedSpecifier
629  << SS.getRange());
630  } else
631  diagnoseTypo(Corrected, PDiag(diag::err_undeclared_var_use_suggest)
632  << Name);
633 
634  if (Corrected.getCorrectionSpecifier())
635  SS.MakeTrivial(Context, Corrected.getCorrectionSpecifier(),
636  SourceRange(Found.getNameLoc()));
637 
638  if (NamedDecl *ND = Corrected.getFoundDecl())
639  Found.addDecl(ND);
640  Found.setLookupName(Corrected.getCorrection());
641  } else {
642  Found.setLookupName(&Identifier);
643  }
644  }
645 
646  NamedDecl *SD =
647  Found.isSingleResult() ? Found.getRepresentativeDecl() : nullptr;
648  bool IsExtension = false;
649  bool AcceptSpec = isAcceptableNestedNameSpecifier(SD, &IsExtension);
650  if (!AcceptSpec && IsExtension) {
651  AcceptSpec = true;
652  Diag(IdentifierLoc, diag::ext_nested_name_spec_is_enum);
653  }
654  if (AcceptSpec) {
655  if (!ObjectType.isNull() && !ObjectTypeSearchedInScope &&
656  !getLangOpts().CPlusPlus11) {
657  // C++03 [basic.lookup.classref]p4:
658  // [...] If the name is found in both contexts, the
659  // class-name-or-namespace-name shall refer to the same entity.
660  //
661  // We already found the name in the scope of the object. Now, look
662  // into the current scope (the scope of the postfix-expression) to
663  // see if we can find the same name there. As above, if there is no
664  // scope, reconstruct the result from the template instantiation itself.
665  //
666  // Note that C++11 does *not* perform this redundant lookup.
667  NamedDecl *OuterDecl;
668  if (S) {
669  LookupResult FoundOuter(*this, &Identifier, IdentifierLoc,
671  LookupName(FoundOuter, S);
672  OuterDecl = FoundOuter.getAsSingle<NamedDecl>();
673  } else
674  OuterDecl = ScopeLookupResult;
675 
676  if (isAcceptableNestedNameSpecifier(OuterDecl) &&
677  OuterDecl->getCanonicalDecl() != SD->getCanonicalDecl() &&
678  (!isa<TypeDecl>(OuterDecl) || !isa<TypeDecl>(SD) ||
680  Context.getTypeDeclType(cast<TypeDecl>(OuterDecl)),
681  Context.getTypeDeclType(cast<TypeDecl>(SD))))) {
682  if (ErrorRecoveryLookup)
683  return true;
684 
685  Diag(IdentifierLoc,
686  diag::err_nested_name_member_ref_lookup_ambiguous)
687  << &Identifier;
688  Diag(SD->getLocation(), diag::note_ambig_member_ref_object_type)
689  << ObjectType;
690  Diag(OuterDecl->getLocation(), diag::note_ambig_member_ref_scope);
691 
692  // Fall through so that we'll pick the name we found in the object
693  // type, since that's probably what the user wanted anyway.
694  }
695  }
696 
697  if (auto *TD = dyn_cast_or_null<TypedefNameDecl>(SD))
698  MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
699 
700  // If we're just performing this lookup for error-recovery purposes,
701  // don't extend the nested-name-specifier. Just return now.
702  if (ErrorRecoveryLookup)
703  return false;
704 
705  // The use of a nested name specifier may trigger deprecation warnings.
706  DiagnoseUseOfDecl(SD, CCLoc);
707 
708 
709  if (NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(SD)) {
710  SS.Extend(Context, Namespace, IdentifierLoc, CCLoc);
711  return false;
712  }
713 
714  if (NamespaceAliasDecl *Alias = dyn_cast<NamespaceAliasDecl>(SD)) {
715  SS.Extend(Context, Alias, IdentifierLoc, CCLoc);
716  return false;
717  }
718 
719  QualType T =
720  Context.getTypeDeclType(cast<TypeDecl>(SD->getUnderlyingDecl()));
721  TypeLocBuilder TLB;
722  if (isa<InjectedClassNameType>(T)) {
723  InjectedClassNameTypeLoc InjectedTL
724  = TLB.push<InjectedClassNameTypeLoc>(T);
725  InjectedTL.setNameLoc(IdentifierLoc);
726  } else if (isa<RecordType>(T)) {
727  RecordTypeLoc RecordTL = TLB.push<RecordTypeLoc>(T);
728  RecordTL.setNameLoc(IdentifierLoc);
729  } else if (isa<TypedefType>(T)) {
730  TypedefTypeLoc TypedefTL = TLB.push<TypedefTypeLoc>(T);
731  TypedefTL.setNameLoc(IdentifierLoc);
732  } else if (isa<EnumType>(T)) {
733  EnumTypeLoc EnumTL = TLB.push<EnumTypeLoc>(T);
734  EnumTL.setNameLoc(IdentifierLoc);
735  } else if (isa<TemplateTypeParmType>(T)) {
736  TemplateTypeParmTypeLoc TemplateTypeTL
737  = TLB.push<TemplateTypeParmTypeLoc>(T);
738  TemplateTypeTL.setNameLoc(IdentifierLoc);
739  } else if (isa<UnresolvedUsingType>(T)) {
740  UnresolvedUsingTypeLoc UnresolvedTL
741  = TLB.push<UnresolvedUsingTypeLoc>(T);
742  UnresolvedTL.setNameLoc(IdentifierLoc);
743  } else if (isa<SubstTemplateTypeParmType>(T)) {
746  TL.setNameLoc(IdentifierLoc);
747  } else if (isa<SubstTemplateTypeParmPackType>(T)) {
750  TL.setNameLoc(IdentifierLoc);
751  } else {
752  llvm_unreachable("Unhandled TypeDecl node in nested-name-specifier");
753  }
754 
755  if (T->isEnumeralType())
756  Diag(IdentifierLoc, diag::warn_cxx98_compat_enum_nested_name_spec);
757 
759  CCLoc);
760  return false;
761  }
762 
763  // Otherwise, we have an error case. If we don't want diagnostics, just
764  // return an error now.
765  if (ErrorRecoveryLookup)
766  return true;
767 
768  // If we didn't find anything during our lookup, try again with
769  // ordinary name lookup, which can help us produce better error
770  // messages.
771  if (Found.empty()) {
772  Found.clear(LookupOrdinaryName);
773  LookupName(Found, S);
774  }
775 
776  // In Microsoft mode, if we are within a templated function and we can't
777  // resolve Identifier, then extend the SS with Identifier. This will have
778  // the effect of resolving Identifier during template instantiation.
779  // The goal is to be able to resolve a function call whose
780  // nested-name-specifier is located inside a dependent base class.
781  // Example:
782  //
783  // class C {
784  // public:
785  // static void foo2() { }
786  // };
787  // template <class T> class A { public: typedef C D; };
788  //
789  // template <class T> class B : public A<T> {
790  // public:
791  // void foo() { D::foo2(); }
792  // };
793  if (getLangOpts().MSVCCompat) {
794  DeclContext *DC = LookupCtx ? LookupCtx : CurContext;
795  if (DC->isDependentContext() && DC->isFunctionOrMethod()) {
796  CXXRecordDecl *ContainingClass = dyn_cast<CXXRecordDecl>(DC->getParent());
797  if (ContainingClass && ContainingClass->hasAnyDependentBases()) {
798  Diag(IdentifierLoc, diag::ext_undeclared_unqual_id_with_dependent_base)
799  << &Identifier << ContainingClass;
800  SS.Extend(Context, &Identifier, IdentifierLoc, CCLoc);
801  return false;
802  }
803  }
804  }
805 
806  if (!Found.empty()) {
807  if (TypeDecl *TD = Found.getAsSingle<TypeDecl>())
808  Diag(IdentifierLoc, diag::err_expected_class_or_namespace)
809  << QualType(TD->getTypeForDecl(), 0) << getLangOpts().CPlusPlus;
810  else {
811  Diag(IdentifierLoc, diag::err_expected_class_or_namespace)
812  << &Identifier << getLangOpts().CPlusPlus;
813  if (NamedDecl *ND = Found.getAsSingle<NamedDecl>())
814  Diag(ND->getLocation(), diag::note_entity_declared_at) << &Identifier;
815  }
816  } else if (SS.isSet())
817  Diag(IdentifierLoc, diag::err_no_member) << &Identifier << LookupCtx
818  << SS.getRange();
819  else
820  Diag(IdentifierLoc, diag::err_undeclared_var_use) << &Identifier;
821 
822  return true;
823 }
824 
826  IdentifierInfo &Identifier,
828  SourceLocation CCLoc,
829  ParsedType ObjectType,
830  bool EnteringContext,
831  CXXScopeSpec &SS,
832  bool ErrorRecoveryLookup,
833  bool *IsCorrectedToColon) {
834  if (SS.isInvalid())
835  return true;
836 
837  return BuildCXXNestedNameSpecifier(S, Identifier, IdentifierLoc, CCLoc,
838  GetTypeFromParser(ObjectType),
839  EnteringContext, SS,
840  /*ScopeLookupResult=*/nullptr, false,
841  IsCorrectedToColon);
842 }
843 
845  const DeclSpec &DS,
846  SourceLocation ColonColonLoc) {
847  if (SS.isInvalid() || DS.getTypeSpecType() == DeclSpec::TST_error)
848  return true;
849 
850  assert(DS.getTypeSpecType() == DeclSpec::TST_decltype);
851 
853  if (!T->isDependentType() && !T->getAs<TagType>()) {
854  Diag(DS.getTypeSpecTypeLoc(), diag::err_expected_class_or_namespace)
855  << T << getLangOpts().CPlusPlus;
856  return true;
857  }
858 
859  TypeLocBuilder TLB;
860  DecltypeTypeLoc DecltypeTL = TLB.push<DecltypeTypeLoc>(T);
861  DecltypeTL.setNameLoc(DS.getTypeSpecTypeLoc());
863  ColonColonLoc);
864  return false;
865 }
866 
867 /// IsInvalidUnlessNestedName - This method is used for error recovery
868 /// purposes to determine whether the specified identifier is only valid as
869 /// a nested name specifier, for example a namespace name. It is
870 /// conservatively correct to always return false from this method.
871 ///
872 /// The arguments are the same as those passed to ActOnCXXNestedNameSpecifier.
874  IdentifierInfo &Identifier,
877  ParsedType ObjectType,
878  bool EnteringContext) {
879  if (SS.isInvalid())
880  return false;
881 
882  return !BuildCXXNestedNameSpecifier(S, Identifier, IdentifierLoc, ColonLoc,
883  GetTypeFromParser(ObjectType),
884  EnteringContext, SS,
885  /*ScopeLookupResult=*/nullptr, true);
886 }
887 
889  CXXScopeSpec &SS,
890  SourceLocation TemplateKWLoc,
891  TemplateTy Template,
892  SourceLocation TemplateNameLoc,
893  SourceLocation LAngleLoc,
894  ASTTemplateArgsPtr TemplateArgsIn,
895  SourceLocation RAngleLoc,
896  SourceLocation CCLoc,
897  bool EnteringContext) {
898  if (SS.isInvalid())
899  return true;
900 
901  // Translate the parser's template argument list in our AST format.
902  TemplateArgumentListInfo TemplateArgs(LAngleLoc, RAngleLoc);
903  translateTemplateArguments(TemplateArgsIn, TemplateArgs);
904 
906  if (DTN && DTN->isIdentifier()) {
907  // Handle a dependent template specialization for which we cannot resolve
908  // the template name.
909  assert(DTN->getQualifier() == SS.getScopeRep());
911  DTN->getQualifier(),
912  DTN->getIdentifier(),
913  TemplateArgs);
914 
915  // Create source-location information for this type.
921  SpecTL.setTemplateKeywordLoc(TemplateKWLoc);
922  SpecTL.setTemplateNameLoc(TemplateNameLoc);
923  SpecTL.setLAngleLoc(LAngleLoc);
924  SpecTL.setRAngleLoc(RAngleLoc);
925  for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
926  SpecTL.setArgLocInfo(I, TemplateArgs[I].getLocInfo());
927 
928  SS.Extend(Context, TemplateKWLoc, Builder.getTypeLocInContext(Context, T),
929  CCLoc);
930  return false;
931  }
932 
933  TemplateDecl *TD = Template.get().getAsTemplateDecl();
934  if (Template.get().getAsOverloadedTemplate() || DTN ||
935  isa<FunctionTemplateDecl>(TD) || isa<VarTemplateDecl>(TD)) {
936  SourceRange R(TemplateNameLoc, RAngleLoc);
937  if (SS.getRange().isValid())
938  R.setBegin(SS.getRange().getBegin());
939 
940  Diag(CCLoc, diag::err_non_type_template_in_nested_name_specifier)
941  << (TD && isa<VarTemplateDecl>(TD)) << Template.get() << R;
942  NoteAllFoundTemplates(Template.get());
943  return true;
944  }
945 
946  // We were able to resolve the template name to an actual template.
947  // Build an appropriate nested-name-specifier.
948  QualType T = CheckTemplateIdType(Template.get(), TemplateNameLoc,
949  TemplateArgs);
950  if (T.isNull())
951  return true;
952 
953  // Alias template specializations can produce types which are not valid
954  // nested name specifiers.
955  if (!T->isDependentType() && !T->getAs<TagType>()) {
956  Diag(TemplateNameLoc, diag::err_nested_name_spec_non_tag) << T;
957  NoteAllFoundTemplates(Template.get());
958  return true;
959  }
960 
961  // Provide source-location information for the template specialization type.
964  = Builder.push<TemplateSpecializationTypeLoc>(T);
965  SpecTL.setTemplateKeywordLoc(TemplateKWLoc);
966  SpecTL.setTemplateNameLoc(TemplateNameLoc);
967  SpecTL.setLAngleLoc(LAngleLoc);
968  SpecTL.setRAngleLoc(RAngleLoc);
969  for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
970  SpecTL.setArgLocInfo(I, TemplateArgs[I].getLocInfo());
971 
972 
973  SS.Extend(Context, TemplateKWLoc, Builder.getTypeLocInContext(Context, T),
974  CCLoc);
975  return false;
976 }
977 
978 namespace {
979  /// \brief A structure that stores a nested-name-specifier annotation,
980  /// including both the nested-name-specifier
981  struct NestedNameSpecifierAnnotation {
982  NestedNameSpecifier *NNS;
983  };
984 }
985 
987  if (SS.isEmpty() || SS.isInvalid())
988  return nullptr;
989 
990  void *Mem = Context.Allocate((sizeof(NestedNameSpecifierAnnotation) +
991  SS.location_size()),
992  llvm::alignOf<NestedNameSpecifierAnnotation>());
993  NestedNameSpecifierAnnotation *Annotation
994  = new (Mem) NestedNameSpecifierAnnotation;
995  Annotation->NNS = SS.getScopeRep();
996  memcpy(Annotation + 1, SS.location_data(), SS.location_size());
997  return Annotation;
998 }
999 
1001  SourceRange AnnotationRange,
1002  CXXScopeSpec &SS) {
1003  if (!AnnotationPtr) {
1004  SS.SetInvalid(AnnotationRange);
1005  return;
1006  }
1007 
1008  NestedNameSpecifierAnnotation *Annotation
1009  = static_cast<NestedNameSpecifierAnnotation *>(AnnotationPtr);
1010  SS.Adopt(NestedNameSpecifierLoc(Annotation->NNS, Annotation + 1));
1011 }
1012 
1014  assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
1015 
1016  NestedNameSpecifier *Qualifier = SS.getScopeRep();
1017 
1018  // There are only two places a well-formed program may qualify a
1019  // declarator: first, when defining a namespace or class member
1020  // out-of-line, and second, when naming an explicitly-qualified
1021  // friend function. The latter case is governed by
1022  // C++03 [basic.lookup.unqual]p10:
1023  // In a friend declaration naming a member function, a name used
1024  // in the function declarator and not part of a template-argument
1025  // in a template-id is first looked up in the scope of the member
1026  // function's class. If it is not found, or if the name is part of
1027  // a template-argument in a template-id, the look up is as
1028  // described for unqualified names in the definition of the class
1029  // granting friendship.
1030  // i.e. we don't push a scope unless it's a class member.
1031 
1032  switch (Qualifier->getKind()) {
1036  // These are always namespace scopes. We never want to enter a
1037  // namespace scope from anything but a file context.
1039 
1044  // These are never namespace scopes.
1045  return true;
1046  }
1047 
1048  llvm_unreachable("Invalid NestedNameSpecifier::Kind!");
1049 }
1050 
1051 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
1052 /// scope or nested-name-specifier) is parsed, part of a declarator-id.
1053 /// After this method is called, according to [C++ 3.4.3p3], names should be
1054 /// looked up in the declarator-id's scope, until the declarator is parsed and
1055 /// ActOnCXXExitDeclaratorScope is called.
1056 /// The 'SS' should be a non-empty valid CXXScopeSpec.
1058  assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
1059 
1060  if (SS.isInvalid()) return true;
1061 
1062  DeclContext *DC = computeDeclContext(SS, true);
1063  if (!DC) return true;
1064 
1065  // Before we enter a declarator's context, we need to make sure that
1066  // it is a complete declaration context.
1067  if (!DC->isDependentContext() && RequireCompleteDeclContext(SS, DC))
1068  return true;
1069 
1070  EnterDeclaratorContext(S, DC);
1071 
1072  // Rebuild the nested name specifier for the new scope.
1073  if (DC->isDependentContext())
1075 
1076  return false;
1077 }
1078 
1079 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
1080 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
1081 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
1082 /// Used to indicate that names should revert to being looked up in the
1083 /// defining scope.
1085  assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
1086  if (SS.isInvalid())
1087  return;
1088  assert(!SS.isInvalid() && computeDeclContext(SS, true) &&
1089  "exiting declarator scope we never really entered");
1091 }
NamedDecl * FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS)
If the given nested-name-specifier begins with a bare identifier (e.g., Base::), perform name lookup ...
Defines the clang::ASTContext interface.
Scope * getCurScope() const
Retrieve the parser's current scope.
Definition: Sema.h:9565
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:237
void MakeSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)
Turns this (empty) nested-name-specifier into '__super' nested-name-specifier.
Definition: DeclSpec.cpp:107
A (possibly-)qualified type.
Definition: Type.h:598
Simple class containing the result of Sema::CorrectTypo.
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc...
Definition: Sema.h:2705
const LangOptions & getLangOpts() const
Definition: Sema.h:1062
void setLookupName(DeclarationName Name)
Sets the name to look up.
Definition: Sema/Lookup.h:252
bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation=false)
Perform unqualified name lookup starting from a given scope.
DeclClass * getAsSingle() const
Definition: Sema/Lookup.h:491
NamedDecl * getRepresentativeDecl() const
Fetches a representative decl. Useful for lazy diagnostics.
Definition: Sema/Lookup.h:508
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1458
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in...
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition: Sema.h:1139
Defines the C++ template declaration subclasses.
bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS)
bool isEnumeralType() const
Definition: Type.h:5542
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization...
Definition: Decl.h:3230
The base class of the type hierarchy.
Definition: Type.h:1281
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier.
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:922
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1874
NamespaceDecl - Represent a C++ namespace.
Definition: Decl.h:471
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
Wrapper for source info for typedefs.
Definition: TypeLoc.h:620
Look up of a name that precedes the '::' scope resolution operator in C++.
Definition: Sema.h:2721
bool isAcceptableNestedNameSpecifier(const NamedDecl *SD, bool *CanCorrect=nullptr)
Determines whether the given declaration is an valid acceptable result for name lookup of a nested-na...
void * SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS)
Given a C++ nested-name-specifier, produce an annotation value that the parser can use later to recon...
An identifier, stored as an IdentifierInfo*.
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Definition: DeclSpec.cpp:125
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
Definition: SemaInternal.h:25
DeclContext * computeDeclContext(QualType T)
Compute the DeclContext that is associated with the given type.
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition: Decl.h:387
A namespace, stored as a NamespaceDecl*.
void setBegin(SourceLocation b)
void ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS)
ActOnCXXExitDeclaratorScope - Called when a declarator that previously invoked ActOnCXXEnterDeclarato...
Defines the clang::Expr interface and subclasses for C++ expressions.
bool isEmpty() const
No scope specifier.
Definition: DeclSpec.h:189
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
Definition: TemplateName.h:474
bool isDependentScopeSpecifier(const CXXScopeSpec &SS)
bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS, const DeclSpec &DS, SourceLocation ColonColonLoc)
One of these records is kept for each identifier that is lexed.
OverloadedTemplateStorage * getAsOverloadedTemplate() const
Retrieve the underlying, overloaded function template.
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition: Decl.cpp:3699
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Definition: Type.h:4549
A C++ nested-name-specifier augmented with source location information.
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:412
bool isIdentifier() const
Determine whether this template name refers to an identifier.
Definition: TemplateName.h:471
NamespaceDecl * getNamespace()
Retrieve the namespace declaration aliased by this directive.
Definition: DeclCXX.h:2789
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:1472
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
bool hasVisibleDeclaration(const NamedDecl *D, llvm::SmallVectorImpl< Module * > *Modules=nullptr)
Determine whether any declaration of an entity is visible.
Definition: Sema.h:1415
bool isCompleteDefinition() const
isCompleteDefinition - Return true if this decl has its body fully specified.
Definition: Decl.h:2871
CXXRecordDecl * getCurrentInstantiationOf(NestedNameSpecifier *NNS)
If the given nested name specifier refers to the current instantiation, return the declaration that c...
bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS)
bool isBeingDefined() const
Determines whether this type is in the process of being defined.
Definition: Type.cpp:2964
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:1982
static const TST TST_error
Definition: DeclSpec.h:306
Wrapper for source info for unresolved typename using decls.
Definition: TypeLoc.h:642
SourceLocation getTypeSpecTypeLoc() const
Definition: DeclSpec.h:509
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
Definition: ASTContext.h:1199
void setNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:496
Represents the results of name lookup.
Definition: Sema/Lookup.h:30
bool DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc, const ObjCInterfaceDecl *UnknownObjCClass=nullptr, bool ObjCPropertyAccess=false)
Determine whether the use of this declaration is valid, and emit any corresponding diagnostics...
Definition: SemaExpr.cpp:317
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1895
const LangOptions & getLangOpts() const
Definition: ASTContext.h:604
Wrapper for source info for injected class names of class templates.
Definition: TypeLoc.h:631
A convenient class for passing around template argument information.
Definition: TemplateBase.h:523
unsigned location_size() const
Retrieve the size of the data associated with source-location information.
Definition: DeclSpec.h:221
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:704
char * location_data() const
Retrieve the data associated with the source-location information.
Definition: DeclSpec.h:217
TypeDecl - Represents a declaration of a type.
Definition: Decl.h:2569
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:697
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:39
void SetInvalid(SourceRange R)
Indicate that this nested-name-specifier is invalid.
Definition: DeclSpec.h:199
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:63
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:468
std::string getAsString() const
getNameAsString - Retrieve the human-readable string for this name.
void addDecl(NamedDecl *D)
Add a declaration to these results with its natural access.
Definition: Sema/Lookup.h:410
detail::InMemoryDirectory::const_iterator I
QualType getCanonicalTypeInternal() const
Definition: Type.h:2001
bool isInvalid() const
SourceRange getRange() const
Definition: DeclSpec.h:68
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
EnumDecl * getDecl() const
Definition: Type.h:3739
QualType CheckTemplateIdType(TemplateName Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &TemplateArgs)
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:263
TST getTypeSpecType() const
Definition: DeclSpec.h:479
const DeclarationNameInfo & getLookupNameInfo() const
Gets the name info to look up.
Definition: Sema/Lookup.h:237
void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool MightBeOdrUse)
Perform marking for a reference to an arbitrary declaration.
Definition: SemaExpr.cpp:14058
bool InstantiateEnum(SourceLocation PointOfInstantiation, EnumDecl *Instantiation, EnumDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateSpecializationKind TSK)
Instantiate the definition of an enum from a given pattern.
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:1903
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:1881
QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, const TemplateArgumentListInfo &Args) const
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:1855
MultiLevelTemplateArgumentList getTemplateInstantiationArgs(NamedDecl *D, const TemplateArgumentList *Innermost=nullptr, bool RelativeToPrimary=false, const FunctionDecl *Pattern=nullptr)
Retrieve the template argument list(s) that should be used to instantiate the definition of the given...
DeclarationName getLookupName() const
Gets the name to look up.
Definition: Sema/Lookup.h:247
bool ActOnCXXGlobalScopeSpecifier(SourceLocation CCLoc, CXXScopeSpec &SS)
The parser has parsed a global nested-name-specifier '::'.
SourceLocation getNameLoc() const
Gets the location of the identifier.
Definition: Sema/Lookup.h:589
This file defines the classes used to store parsed information about declaration-specifiers and decla...
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:886
void NoteAllFoundTemplates(TemplateName Name)
bool RequireCompleteType(SourceLocation Loc, QualType T, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
Definition: SemaType.cpp:6826
A namespace alias, stored as a NamespaceAliasDecl*.
Wrapper for source info for enum types.
Definition: TypeLoc.h:680
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:1774
bool isFunctionOrMethod() const
Definition: DeclBase.h:1263
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1214
void diagnoseMissingImport(SourceLocation Loc, NamedDecl *Decl, MissingImportKind MIK, bool Recover=true)
Diagnose that the specified declaration needs to be visible but isn't, and suggest a module import th...
static bool hasDefinition(const ObjCObjectPointerType *ObjPtr)
unsigned getNumBases() const
Retrieves the number of base classes of this class.
Definition: DeclCXX.h:712
Wraps an identifier and optional source location for the identifier.
Definition: AttributeList.h:72
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
The result type of a method or function.
This template specialization was implicitly instantiated from a template.
Definition: Specifiers.h:147
void translateTemplateArguments(const ASTTemplateArgsPtr &In, TemplateArgumentListInfo &Out)
Translates template arguments as provided by the parser into template arguments used by semantic anal...
bool isAmbiguous() const
Definition: Sema/Lookup.h:285
NestedNameSpecifier * getScopeRep() const
Retrieve the representation of the nested-name-specifier.
Definition: DeclSpec.h:76
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
TypeLoc getTypeLocInContext(ASTContext &Context, QualType T)
Copies the type-location information to the given AST context and returns a TypeLoc referring into th...
SourceLocation getLastQualifierNameLoc() const
Retrieve the location of the name in the last qualifier in this nested name specifier.
Definition: DeclSpec.cpp:136
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1888
Encodes a location in the source.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
Definition: Type.h:3733
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:5259
Expr * getRepAsExpr() const
Definition: DeclSpec.h:495
void ExitDeclaratorContext(Scope *S)
Definition: SemaDecl.cpp:1177
TagDecl - Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:2727
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
Definition: DeclSpec.cpp:143
bool isValid() const
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:1736
bool hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested, bool OnlyNeedComplete=false)
Determine if D has a visible definition.
Definition: SemaType.cpp:6848
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
bool isInvalid() const
An error occurred during parsing of the scope specifier.
Definition: DeclSpec.h:194
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1843
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
SourceLocation getBegin() const
bool isFileContext() const
Definition: DeclBase.h:1279
PtrTy get() const
Definition: Ownership.h:75
bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC)
Require that the context specified by SS be complete.
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1451
void diagnoseTypo(const TypoCorrection &Correction, const PartialDiagnostic &TypoDiag, bool ErrorRecovery=true)
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2609
bool ActOnCXXNestedNameSpecifier(Scope *S, IdentifierInfo &Identifier, SourceLocation IdentifierLoc, SourceLocation CCLoc, ParsedType ObjectType, bool EnteringContext, CXXScopeSpec &SS, bool ErrorRecoveryLookup=false, bool *IsCorrectedToColon=nullptr)
The parser has parsed a nested-name-specifier 'identifier::'.
bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS, IdentifierInfo &Identifier, SourceLocation IdentifierLoc, SourceLocation ColonLoc, ParsedType ObjectType, bool EnteringContext)
IsInvalidUnlessNestedName - This method is used for error recovery purposes to determine whether the ...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1135
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:330
void setContextRange(SourceRange SR)
Sets a 'context' source range.
Definition: Sema/Lookup.h:576
void EnterDeclaratorContext(Scope *S, DeclContext *DC)
EnterDeclaratorContext - Used when we must lookup names in the context of a declarator's nested name ...
Definition: SemaDecl.cpp:1148
Sema::LookupNameKind getLookupKind() const
Gets the kind of lookup to perform.
Definition: Sema/Lookup.h:257
static const TST TST_decltype
Definition: DeclSpec.h:296
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Definition: ASTMatchers.h:1983
bool BuildCXXNestedNameSpecifier(Scope *S, IdentifierInfo &Identifier, SourceLocation IdentifierLoc, SourceLocation CCLoc, QualType ObjectType, bool EnteringContext, CXXScopeSpec &SS, NamedDecl *ScopeLookupResult, bool ErrorRecoveryLookup, bool *IsCorrectedToColon=nullptr)
Build a new nested-name-specifier for "identifier::", as described by ActOnCXXNestedNameSpecifier.
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
Definition: DeclTemplate.h:522
DeclarationName - The name of a declaration.
EnumDecl - Represents an enum.
Definition: Decl.h:3013
bool isSingleResult() const
Determines if this names a single result which is not an unresolved value using decl.
Definition: Sema/Lookup.h:292
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:1966
bool isCurrentInstantiation(const DeclContext *CurContext) const
Determine whether this dependent class is a current instantiation, when viewed from within the given ...
bool hasAnyDependentBases() const
Determine whether this class has any dependent base classes which are not the current instantiation...
Definition: DeclCXX.cpp:406
A type that was preceded by the 'template' keyword, stored as a Type*.
bool ActOnSuperScopeSpecifier(SourceLocation SuperLoc, SourceLocation ColonColonLoc, CXXScopeSpec &SS)
The parser has parsed a '__super' nested-name-specifier.
bool isLambda() const
Determine whether this class describes a lambda function object.
Definition: DeclCXX.h:1027
bool empty() const
Return true if no decls were found.
Definition: Sema/Lookup.h:323
NamedDecl * getCorrectionDecl() const
Gets the pointer to the declaration of the typo correction.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:3707
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:5818
This template specialization was declared or defined by an explicit specialization (C++ [temp...
Definition: Specifiers.h:151
void RestoreNestedNameSpecifierAnnotation(void *Annotation, SourceRange AnnotationRange, CXXScopeSpec &SS)
Given an annotation pointer for a nested-name-specifier, restore the nested-name-specifier structure...
QualType BuildDecltypeType(Expr *E, SourceLocation Loc, bool AsUnevaluated=true)
If AsUnevaluated is false, E is treated as though it were an evaluated context, such as when building...
Definition: SemaType.cpp:7312
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1534
Wrapper for source info for record types.
Definition: TypeLoc.h:672
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream...
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
Definition: SemaType.cpp:2533
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS)
ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global scope or nested-name-specifi...
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL, SourceLocation ColonColonLoc)
Extend the current nested-name-specifier by another nested-name-specifier component of the form 'type...
Definition: DeclSpec.cpp:47
Captures information about "declaration specifiers".
Definition: DeclSpec.h:228
bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS, SourceLocation IdLoc, IdentifierInfo &II, ParsedType ObjectType)
Represents a C++ struct/union/class.
Definition: DeclCXX.h:263
BoundNodesTreeBuilder *const Builder
Optional< sema::TemplateDeductionInfo * > isSFINAEContext() const
Determines whether we are currently in a context where template argument substitution failures are no...
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:568
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:500
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:311
Declaration of a class template.
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string...
Definition: Diagnostic.h:115
void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc)
Turn this (empty) nested-name-specifier into the global nested-name-specifier '::'.
Definition: DeclSpec.cpp:97
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1465
TagDecl * getDecl() const
Definition: Type.cpp:2960
bool isRecord() const
Definition: DeclBase.h:1287
static CXXRecordDecl * getCurrentInstantiationOf(QualType T, DeclContext *CurContext)
Find the current instantiation that associated with the given type.
bool isSet() const
Deprecated.
Definition: DeclSpec.h:209
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
Definition: Sema/Lookup.h:566
Wrapper for template type parameters.
Definition: TypeLoc.h:688
A trivial tuple used to represent a source range.
ASTContext & Context
Definition: Sema.h:299
TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, Sema::LookupNameKind LookupKind, Scope *S, CXXScopeSpec *SS, std::unique_ptr< CorrectionCandidateCallback > CCC, CorrectTypoKind Mode, DeclContext *MemberContext=nullptr, bool EnteringContext=false, const ObjCObjectPointerType *OPT=nullptr, bool RecordFailure=true)
Try to "correct" a typo in the source code by finding visible declarations whose names are similar to...
NamedDecl - This represents a decl with a name.
Definition: Decl.h:213
Represents a C++ namespace alias.
Definition: DeclCXX.h:2718
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:1486
No keyword precedes the qualified type name.
Definition: Type.h:4372
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:665
The global specifier '::'. There is no stored value.
SourceLocation ColonLoc
Location of ':'.
Definition: OpenMPClause.h:266
TemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon, QualType Aliased)
void clear()
Clears out any current state.
Definition: Sema/Lookup.h:538