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