clang  9.0.0svn
SemaCXXScopeSpec.cpp
Go to the documentation of this file.
1 //===--- SemaCXXScopeSpec.cpp - Semantic Analysis for C++ scope specifiers-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements C++ semantic analysis for scope specifiers.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "TypeLocBuilder.h"
14 #include "clang/AST/ASTContext.h"
15 #include "clang/AST/DeclTemplate.h"
16 #include "clang/AST/ExprCXX.h"
19 #include "clang/Sema/DeclSpec.h"
20 #include "clang/Sema/Lookup.h"
22 #include "clang/Sema/Template.h"
23 #include "llvm/ADT/STLExtras.h"
24 using namespace clang;
25 
26 /// Find the current instantiation that associated with the given type.
28  DeclContext *CurContext) {
29  if (T.isNull())
30  return nullptr;
31 
32  const Type *Ty = T->getCanonicalTypeInternal().getTypePtr();
33  if (const RecordType *RecordTy = dyn_cast<RecordType>(Ty)) {
34  CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordTy->getDecl());
35  if (!Record->isDependentContext() ||
36  Record->isCurrentInstantiation(CurContext))
37  return Record;
38 
39  return nullptr;
40  } else if (isa<InjectedClassNameType>(Ty))
41  return cast<InjectedClassNameType>(Ty)->getDecl();
42  else
43  return nullptr;
44 }
45 
46 /// Compute the DeclContext that is associated with the given type.
47 ///
48 /// \param T the type for which we are attempting to find a DeclContext.
49 ///
50 /// \returns the declaration context represented by the type T,
51 /// or NULL if the declaration context cannot be computed (e.g., because it is
52 /// dependent and not the current instantiation).
54  if (!T->isDependentType())
55  if (const TagType *Tag = T->getAs<TagType>())
56  return Tag->getDecl();
57 
59 }
60 
61 /// Compute the DeclContext that is associated with the given
62 /// scope specifier.
63 ///
64 /// \param SS the C++ scope specifier as it appears in the source
65 ///
66 /// \param EnteringContext when true, we will be entering the context of
67 /// this scope specifier, so we can retrieve the declaration context of a
68 /// class template or class template partial specialization even if it is
69 /// not the current instantiation.
70 ///
71 /// \returns the declaration context represented by the scope specifier @p SS,
72 /// or NULL if the declaration context cannot be computed (e.g., because it is
73 /// dependent and not the current instantiation).
75  bool EnteringContext) {
76  if (!SS.isSet() || SS.isInvalid())
77  return nullptr;
78 
79  NestedNameSpecifier *NNS = SS.getScopeRep();
80  if (NNS->isDependent()) {
81  // If this nested-name-specifier refers to the current
82  // instantiation, return its DeclContext.
83  if (CXXRecordDecl *Record = getCurrentInstantiationOf(NNS))
84  return Record;
85 
86  if (EnteringContext) {
87  const Type *NNSType = NNS->getAsType();
88  if (!NNSType) {
89  return nullptr;
90  }
91 
92  // Look through type alias templates, per C++0x [temp.dep.type]p1.
93  NNSType = Context.getCanonicalType(NNSType);
94  if (const TemplateSpecializationType *SpecType
95  = NNSType->getAs<TemplateSpecializationType>()) {
96  // We are entering the context of the nested name specifier, so try to
97  // match the nested name specifier to either a primary class template
98  // or a class template partial specialization.
99  if (ClassTemplateDecl *ClassTemplate
100  = dyn_cast_or_null<ClassTemplateDecl>(
101  SpecType->getTemplateName().getAsTemplateDecl())) {
102  QualType ContextType
103  = Context.getCanonicalType(QualType(SpecType, 0));
104 
105  // If the type of the nested name specifier is the same as the
106  // injected class name of the named class template, we're entering
107  // into that class template definition.
108  QualType Injected
109  = ClassTemplate->getInjectedClassNameSpecialization();
110  if (Context.hasSameType(Injected, ContextType))
111  return ClassTemplate->getTemplatedDecl();
112 
113  // If the type of the nested name specifier is the same as the
114  // type of one of the class template's class template partial
115  // specializations, we're entering into the definition of that
116  // class template partial specialization.
118  = ClassTemplate->findPartialSpecialization(ContextType)) {
119  // A declaration of the partial specialization must be visible.
120  // We can always recover here, because this only happens when we're
121  // entering the context, and that can't happen in a SFINAE context.
122  assert(!isSFINAEContext() &&
123  "partial specialization scope specifier in SFINAE context?");
124  if (!hasVisibleDeclaration(PartialSpec))
127  /*Recover*/true);
128  return PartialSpec;
129  }
130  }
131  } else if (const RecordType *RecordT = NNSType->getAs<RecordType>()) {
132  // The nested name specifier refers to a member of a class template.
133  return RecordT->getDecl();
134  }
135  }
136 
137  return nullptr;
138  }
139 
140  switch (NNS->getKind()) {
142  llvm_unreachable("Dependent nested-name-specifier has no DeclContext");
143 
145  return NNS->getAsNamespace();
146 
148  return NNS->getAsNamespaceAlias()->getNamespace();
149 
152  const TagType *Tag = NNS->getAsType()->getAs<TagType>();
153  assert(Tag && "Non-tag type in nested-name-specifier");
154  return Tag->getDecl();
155  }
156 
159 
161  return NNS->getAsRecordDecl();
162  }
163 
164  llvm_unreachable("Invalid NestedNameSpecifier::Kind!");
165 }
166 
168  if (!SS.isSet() || SS.isInvalid())
169  return false;
170 
171  return SS.getScopeRep()->isDependent();
172 }
173 
174 /// If the given nested name specifier refers to the current
175 /// instantiation, return the declaration that corresponds to that
176 /// current instantiation (C++0x [temp.dep.type]p1).
177 ///
178 /// \param NNS a dependent nested name specifier.
180  assert(getLangOpts().CPlusPlus && "Only callable in C++");
181  assert(NNS->isDependent() && "Only dependent nested-name-specifier allowed");
182 
183  if (!NNS->getAsType())
184  return nullptr;
185 
186  QualType T = QualType(NNS->getAsType(), 0);
188 }
189 
190 /// Require that the context specified by SS be complete.
191 ///
192 /// If SS refers to a type, this routine checks whether the type is
193 /// complete enough (or can be made complete enough) for name lookup
194 /// into the DeclContext. A type that is not yet completed can be
195 /// considered "complete enough" if it is a class/struct/union/enum
196 /// that is currently being defined. Or, if we have a type that names
197 /// a class template specialization that is not a complete type, we
198 /// will attempt to instantiate that class template.
200  DeclContext *DC) {
201  assert(DC && "given null context");
202 
203  TagDecl *tag = dyn_cast<TagDecl>(DC);
204 
205  // If this is a dependent type, then we consider it complete.
206  // FIXME: This is wrong; we should require a (visible) definition to
207  // exist in this case too.
208  if (!tag || tag->isDependentContext())
209  return false;
210 
211  // Grab the tag definition, if there is one.
213  tag = type->getAsTagDecl();
214 
215  // If we're currently defining this type, then lookup into the
216  // type is okay: don't complain that it isn't complete yet.
217  if (tag->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  auto *EnumD = dyn_cast<EnumDecl>(tag);
234  if (!EnumD)
235  return false;
236  if (EnumD->isCompleteDefinition()) {
237  // If we know about the definition but it is not visible, complain.
238  NamedDecl *SuggestedDef = nullptr;
239  if (!hasVisibleDefinition(EnumD, &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  if (EnumDecl *Pattern = EnumD->getInstantiatedFromMemberEnum()) {
254  MemberSpecializationInfo *MSI = EnumD->getMemberSpecializationInfo();
256  if (InstantiateEnum(loc, EnumD, Pattern,
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 /// 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 /// 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  NestedNameSpecInfo &IdInfo) {
385  QualType ObjectType = GetTypeFromParser(IdInfo.ObjectType);
386  LookupResult Found(*this, IdInfo.Identifier, IdInfo.IdentifierLoc,
388 
389  // Determine where to perform name lookup
390  DeclContext *LookupCtx = nullptr;
391  bool isDependent = false;
392  if (!ObjectType.isNull()) {
393  // This nested-name-specifier occurs in a member access expression, e.g.,
394  // x->B::f, and we are looking into the type of the object.
395  assert(!SS.isSet() && "ObjectType and scope specifier cannot coexist");
396  LookupCtx = computeDeclContext(ObjectType);
397  isDependent = ObjectType->isDependentType();
398  } else if (SS.isSet()) {
399  // This nested-name-specifier occurs after another nested-name-specifier,
400  // so long into the context associated with the prior nested-name-specifier.
401  LookupCtx = computeDeclContext(SS, false);
402  isDependent = isDependentScopeSpecifier(SS);
403  Found.setContextRange(SS.getRange());
404  }
405 
406  if (LookupCtx) {
407  // Perform "qualified" name lookup into the declaration context we
408  // computed, which is either the type of the base of a member access
409  // expression or the declaration context associated with a prior
410  // nested-name-specifier.
411 
412  // The declaration context must be complete.
413  if (!LookupCtx->isDependentContext() &&
414  RequireCompleteDeclContext(SS, LookupCtx))
415  return false;
416 
417  LookupQualifiedName(Found, LookupCtx);
418  } else if (isDependent) {
419  return false;
420  } else {
421  LookupName(Found, S);
422  }
423  Found.suppressDiagnostics();
424 
425  return Found.getAsSingle<NamespaceDecl>();
426 }
427 
428 namespace {
429 
430 // Callback to only accept typo corrections that can be a valid C++ member
431 // intializer: either a non-static field member or a base class.
432 class NestedNameSpecifierValidatorCCC final
433  : 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  std::unique_ptr<CorrectionCandidateCallback> clone() override {
443  return llvm::make_unique<NestedNameSpecifierValidatorCCC>(*this);
444  }
445 
446  private:
447  Sema &SRef;
448 };
449 
450 }
451 
452 /// Build a new nested-name-specifier for "identifier::", as described
453 /// by ActOnCXXNestedNameSpecifier.
454 ///
455 /// \param S Scope in which the nested-name-specifier occurs.
456 /// \param IdInfo Parser information about an identifier in the
457 /// nested-name-spec.
458 /// \param EnteringContext If true, enter the context specified by the
459 /// nested-name-specifier.
460 /// \param SS Optional nested name specifier preceding the identifier.
461 /// \param ScopeLookupResult Provides the result of name lookup within the
462 /// scope of the nested-name-specifier that was computed at template
463 /// definition time.
464 /// \param ErrorRecoveryLookup Specifies if the method is called to improve
465 /// error recovery and what kind of recovery is performed.
466 /// \param IsCorrectedToColon If not null, suggestion of replace '::' -> ':'
467 /// are allowed. The bool value pointed by this parameter is set to
468 /// 'true' if the identifier is treated as if it was followed by ':',
469 /// not '::'.
470 /// \param OnlyNamespace If true, only considers namespaces in lookup.
471 ///
472 /// This routine differs only slightly from ActOnCXXNestedNameSpecifier, in
473 /// that it contains an extra parameter \p ScopeLookupResult, which provides
474 /// the result of name lookup within the scope of the nested-name-specifier
475 /// that was computed at template definition time.
476 ///
477 /// If ErrorRecoveryLookup is true, then this call is used to improve error
478 /// recovery. This means that it should not emit diagnostics, it should
479 /// just return true on failure. It also means it should only return a valid
480 /// scope if it *knows* that the result is correct. It should not return in a
481 /// dependent context, for example. Nor will it extend \p SS with the scope
482 /// specifier.
484  bool EnteringContext, CXXScopeSpec &SS,
485  NamedDecl *ScopeLookupResult,
486  bool ErrorRecoveryLookup,
487  bool *IsCorrectedToColon,
488  bool OnlyNamespace) {
489  if (IdInfo.Identifier->isEditorPlaceholder())
490  return true;
491  LookupResult Found(*this, IdInfo.Identifier, IdInfo.IdentifierLoc,
492  OnlyNamespace ? LookupNamespaceName
494  QualType ObjectType = GetTypeFromParser(IdInfo.ObjectType);
495 
496  // Determine where to perform name lookup
497  DeclContext *LookupCtx = nullptr;
498  bool isDependent = false;
499  if (IsCorrectedToColon)
500  *IsCorrectedToColon = false;
501  if (!ObjectType.isNull()) {
502  // This nested-name-specifier occurs in a member access expression, e.g.,
503  // x->B::f, and we are looking into the type of the object.
504  assert(!SS.isSet() && "ObjectType and scope specifier cannot coexist");
505  LookupCtx = computeDeclContext(ObjectType);
506  isDependent = ObjectType->isDependentType();
507  } else if (SS.isSet()) {
508  // This nested-name-specifier occurs after another nested-name-specifier,
509  // so look into the context associated with the prior nested-name-specifier.
510  LookupCtx = computeDeclContext(SS, EnteringContext);
511  isDependent = isDependentScopeSpecifier(SS);
512  Found.setContextRange(SS.getRange());
513  }
514 
515  bool ObjectTypeSearchedInScope = false;
516  if (LookupCtx) {
517  // Perform "qualified" name lookup into the declaration context we
518  // computed, which is either the type of the base of a member access
519  // expression or the declaration context associated with a prior
520  // nested-name-specifier.
521 
522  // The declaration context must be complete.
523  if (!LookupCtx->isDependentContext() &&
524  RequireCompleteDeclContext(SS, LookupCtx))
525  return true;
526 
527  LookupQualifiedName(Found, LookupCtx);
528 
529  if (!ObjectType.isNull() && Found.empty()) {
530  // C++ [basic.lookup.classref]p4:
531  // If the id-expression in a class member access is a qualified-id of
532  // the form
533  //
534  // class-name-or-namespace-name::...
535  //
536  // the class-name-or-namespace-name following the . or -> operator is
537  // looked up both in the context of the entire postfix-expression and in
538  // the scope of the class of the object expression. If the name is found
539  // only in the scope of the class of the object expression, the name
540  // shall refer to a class-name. If the name is found only in the
541  // context of the entire postfix-expression, the name shall refer to a
542  // class-name or namespace-name. [...]
543  //
544  // Qualified name lookup into a class will not find a namespace-name,
545  // so we do not need to diagnose that case specifically. However,
546  // this qualified name lookup may find nothing. In that case, perform
547  // unqualified name lookup in the given scope (if available) or
548  // reconstruct the result from when name lookup was performed at template
549  // definition time.
550  if (S)
551  LookupName(Found, S);
552  else if (ScopeLookupResult)
553  Found.addDecl(ScopeLookupResult);
554 
555  ObjectTypeSearchedInScope = true;
556  }
557  } else if (!isDependent) {
558  // Perform unqualified name lookup in the current scope.
559  LookupName(Found, S);
560  }
561 
562  if (Found.isAmbiguous())
563  return true;
564 
565  // If we performed lookup into a dependent context and did not find anything,
566  // that's fine: just build a dependent nested-name-specifier.
567  if (Found.empty() && isDependent &&
568  !(LookupCtx && LookupCtx->isRecord() &&
569  (!cast<CXXRecordDecl>(LookupCtx)->hasDefinition() ||
570  !cast<CXXRecordDecl>(LookupCtx)->hasAnyDependentBases()))) {
571  // Don't speculate if we're just trying to improve error recovery.
572  if (ErrorRecoveryLookup)
573  return true;
574 
575  // We were not able to compute the declaration context for a dependent
576  // base object type or prior nested-name-specifier, so this
577  // nested-name-specifier refers to an unknown specialization. Just build
578  // a dependent nested-name-specifier.
579  SS.Extend(Context, IdInfo.Identifier, IdInfo.IdentifierLoc, IdInfo.CCLoc);
580  return false;
581  }
582 
583  if (Found.empty() && !ErrorRecoveryLookup) {
584  // If identifier is not found as class-name-or-namespace-name, but is found
585  // as other entity, don't look for typos.
587  if (LookupCtx)
588  LookupQualifiedName(R, LookupCtx);
589  else if (S && !isDependent)
590  LookupName(R, S);
591  if (!R.empty()) {
592  // Don't diagnose problems with this speculative lookup.
593  R.suppressDiagnostics();
594  // The identifier is found in ordinary lookup. If correction to colon is
595  // allowed, suggest replacement to ':'.
596  if (IsCorrectedToColon) {
597  *IsCorrectedToColon = true;
598  Diag(IdInfo.CCLoc, diag::err_nested_name_spec_is_not_class)
599  << IdInfo.Identifier << getLangOpts().CPlusPlus
600  << FixItHint::CreateReplacement(IdInfo.CCLoc, ":");
601  if (NamedDecl *ND = R.getAsSingle<NamedDecl>())
602  Diag(ND->getLocation(), diag::note_declared_at);
603  return true;
604  }
605  // Replacement '::' -> ':' is not allowed, just issue respective error.
606  Diag(R.getNameLoc(), OnlyNamespace
607  ? unsigned(diag::err_expected_namespace_name)
608  : unsigned(diag::err_expected_class_or_namespace))
609  << IdInfo.Identifier << getLangOpts().CPlusPlus;
610  if (NamedDecl *ND = R.getAsSingle<NamedDecl>())
611  Diag(ND->getLocation(), diag::note_entity_declared_at)
612  << IdInfo.Identifier;
613  return true;
614  }
615  }
616 
617  if (Found.empty() && !ErrorRecoveryLookup && !getLangOpts().MSVCCompat) {
618  // We haven't found anything, and we're not recovering from a
619  // different kind of error, so look for typos.
620  DeclarationName Name = Found.getLookupName();
621  Found.clear();
622  NestedNameSpecifierValidatorCCC CCC(*this);
623  if (TypoCorrection Corrected = CorrectTypo(
624  Found.getLookupNameInfo(), Found.getLookupKind(), S, &SS, CCC,
625  CTK_ErrorRecovery, LookupCtx, EnteringContext)) {
626  if (LookupCtx) {
627  bool DroppedSpecifier =
628  Corrected.WillReplaceSpecifier() &&
629  Name.getAsString() == Corrected.getAsString(getLangOpts());
630  if (DroppedSpecifier)
631  SS.clear();
632  diagnoseTypo(Corrected, PDiag(diag::err_no_member_suggest)
633  << Name << LookupCtx << DroppedSpecifier
634  << SS.getRange());
635  } else
636  diagnoseTypo(Corrected, PDiag(diag::err_undeclared_var_use_suggest)
637  << Name);
638 
639  if (Corrected.getCorrectionSpecifier())
640  SS.MakeTrivial(Context, Corrected.getCorrectionSpecifier(),
641  SourceRange(Found.getNameLoc()));
642 
643  if (NamedDecl *ND = Corrected.getFoundDecl())
644  Found.addDecl(ND);
645  Found.setLookupName(Corrected.getCorrection());
646  } else {
647  Found.setLookupName(IdInfo.Identifier);
648  }
649  }
650 
651  NamedDecl *SD =
652  Found.isSingleResult() ? Found.getRepresentativeDecl() : nullptr;
653  bool IsExtension = false;
654  bool AcceptSpec = isAcceptableNestedNameSpecifier(SD, &IsExtension);
655  if (!AcceptSpec && IsExtension) {
656  AcceptSpec = true;
657  Diag(IdInfo.IdentifierLoc, diag::ext_nested_name_spec_is_enum);
658  }
659  if (AcceptSpec) {
660  if (!ObjectType.isNull() && !ObjectTypeSearchedInScope &&
661  !getLangOpts().CPlusPlus11) {
662  // C++03 [basic.lookup.classref]p4:
663  // [...] If the name is found in both contexts, the
664  // class-name-or-namespace-name shall refer to the same entity.
665  //
666  // We already found the name in the scope of the object. Now, look
667  // into the current scope (the scope of the postfix-expression) to
668  // see if we can find the same name there. As above, if there is no
669  // scope, reconstruct the result from the template instantiation itself.
670  //
671  // Note that C++11 does *not* perform this redundant lookup.
672  NamedDecl *OuterDecl;
673  if (S) {
674  LookupResult FoundOuter(*this, IdInfo.Identifier, IdInfo.IdentifierLoc,
675  LookupNestedNameSpecifierName);
676  LookupName(FoundOuter, S);
677  OuterDecl = FoundOuter.getAsSingle<NamedDecl>();
678  } else
679  OuterDecl = ScopeLookupResult;
680 
681  if (isAcceptableNestedNameSpecifier(OuterDecl) &&
682  OuterDecl->getCanonicalDecl() != SD->getCanonicalDecl() &&
683  (!isa<TypeDecl>(OuterDecl) || !isa<TypeDecl>(SD) ||
685  Context.getTypeDeclType(cast<TypeDecl>(OuterDecl)),
686  Context.getTypeDeclType(cast<TypeDecl>(SD))))) {
687  if (ErrorRecoveryLookup)
688  return true;
689 
690  Diag(IdInfo.IdentifierLoc,
691  diag::err_nested_name_member_ref_lookup_ambiguous)
692  << IdInfo.Identifier;
693  Diag(SD->getLocation(), diag::note_ambig_member_ref_object_type)
694  << ObjectType;
695  Diag(OuterDecl->getLocation(), diag::note_ambig_member_ref_scope);
696 
697  // Fall through so that we'll pick the name we found in the object
698  // type, since that's probably what the user wanted anyway.
699  }
700  }
701 
702  if (auto *TD = dyn_cast_or_null<TypedefNameDecl>(SD))
703  MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
704 
705  // If we're just performing this lookup for error-recovery purposes,
706  // don't extend the nested-name-specifier. Just return now.
707  if (ErrorRecoveryLookup)
708  return false;
709 
710  // The use of a nested name specifier may trigger deprecation warnings.
711  DiagnoseUseOfDecl(SD, IdInfo.CCLoc);
712 
713  if (NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(SD)) {
714  SS.Extend(Context, Namespace, IdInfo.IdentifierLoc, IdInfo.CCLoc);
715  return false;
716  }
717 
718  if (NamespaceAliasDecl *Alias = dyn_cast<NamespaceAliasDecl>(SD)) {
719  SS.Extend(Context, Alias, IdInfo.IdentifierLoc, IdInfo.CCLoc);
720  return false;
721  }
722 
723  QualType T =
724  Context.getTypeDeclType(cast<TypeDecl>(SD->getUnderlyingDecl()));
725  TypeLocBuilder TLB;
726  if (isa<InjectedClassNameType>(T)) {
727  InjectedClassNameTypeLoc InjectedTL
728  = TLB.push<InjectedClassNameTypeLoc>(T);
729  InjectedTL.setNameLoc(IdInfo.IdentifierLoc);
730  } else if (isa<RecordType>(T)) {
731  RecordTypeLoc RecordTL = TLB.push<RecordTypeLoc>(T);
732  RecordTL.setNameLoc(IdInfo.IdentifierLoc);
733  } else if (isa<TypedefType>(T)) {
734  TypedefTypeLoc TypedefTL = TLB.push<TypedefTypeLoc>(T);
735  TypedefTL.setNameLoc(IdInfo.IdentifierLoc);
736  } else if (isa<EnumType>(T)) {
737  EnumTypeLoc EnumTL = TLB.push<EnumTypeLoc>(T);
738  EnumTL.setNameLoc(IdInfo.IdentifierLoc);
739  } else if (isa<TemplateTypeParmType>(T)) {
740  TemplateTypeParmTypeLoc TemplateTypeTL
741  = TLB.push<TemplateTypeParmTypeLoc>(T);
742  TemplateTypeTL.setNameLoc(IdInfo.IdentifierLoc);
743  } else if (isa<UnresolvedUsingType>(T)) {
744  UnresolvedUsingTypeLoc UnresolvedTL
745  = TLB.push<UnresolvedUsingTypeLoc>(T);
746  UnresolvedTL.setNameLoc(IdInfo.IdentifierLoc);
747  } else if (isa<SubstTemplateTypeParmType>(T)) {
750  TL.setNameLoc(IdInfo.IdentifierLoc);
751  } else if (isa<SubstTemplateTypeParmPackType>(T)) {
754  TL.setNameLoc(IdInfo.IdentifierLoc);
755  } else {
756  llvm_unreachable("Unhandled TypeDecl node in nested-name-specifier");
757  }
758 
759  if (T->isEnumeralType())
760  Diag(IdInfo.IdentifierLoc, diag::warn_cxx98_compat_enum_nested_name_spec);
761 
763  IdInfo.CCLoc);
764  return false;
765  }
766 
767  // Otherwise, we have an error case. If we don't want diagnostics, just
768  // return an error now.
769  if (ErrorRecoveryLookup)
770  return true;
771 
772  // If we didn't find anything during our lookup, try again with
773  // ordinary name lookup, which can help us produce better error
774  // messages.
775  if (Found.empty()) {
776  Found.clear(LookupOrdinaryName);
777  LookupName(Found, S);
778  }
779 
780  // In Microsoft mode, if we are within a templated function and we can't
781  // resolve Identifier, then extend the SS with Identifier. This will have
782  // the effect of resolving Identifier during template instantiation.
783  // The goal is to be able to resolve a function call whose
784  // nested-name-specifier is located inside a dependent base class.
785  // Example:
786  //
787  // class C {
788  // public:
789  // static void foo2() { }
790  // };
791  // template <class T> class A { public: typedef C D; };
792  //
793  // template <class T> class B : public A<T> {
794  // public:
795  // void foo() { D::foo2(); }
796  // };
797  if (getLangOpts().MSVCCompat) {
798  DeclContext *DC = LookupCtx ? LookupCtx : CurContext;
799  if (DC->isDependentContext() && DC->isFunctionOrMethod()) {
800  CXXRecordDecl *ContainingClass = dyn_cast<CXXRecordDecl>(DC->getParent());
801  if (ContainingClass && ContainingClass->hasAnyDependentBases()) {
802  Diag(IdInfo.IdentifierLoc,
803  diag::ext_undeclared_unqual_id_with_dependent_base)
804  << IdInfo.Identifier << ContainingClass;
805  SS.Extend(Context, IdInfo.Identifier, IdInfo.IdentifierLoc,
806  IdInfo.CCLoc);
807  return false;
808  }
809  }
810  }
811 
812  if (!Found.empty()) {
813  if (TypeDecl *TD = Found.getAsSingle<TypeDecl>())
814  Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace)
815  << Context.getTypeDeclType(TD) << getLangOpts().CPlusPlus;
816  else {
817  Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace)
818  << IdInfo.Identifier << getLangOpts().CPlusPlus;
819  if (NamedDecl *ND = Found.getAsSingle<NamedDecl>())
820  Diag(ND->getLocation(), diag::note_entity_declared_at)
821  << IdInfo.Identifier;
822  }
823  } else if (SS.isSet())
824  Diag(IdInfo.IdentifierLoc, diag::err_no_member) << IdInfo.Identifier
825  << LookupCtx << SS.getRange();
826  else
827  Diag(IdInfo.IdentifierLoc, diag::err_undeclared_var_use)
828  << IdInfo.Identifier;
829 
830  return true;
831 }
832 
834  bool EnteringContext, CXXScopeSpec &SS,
835  bool ErrorRecoveryLookup,
836  bool *IsCorrectedToColon,
837  bool OnlyNamespace) {
838  if (SS.isInvalid())
839  return true;
840 
841  return BuildCXXNestedNameSpecifier(S, IdInfo, EnteringContext, SS,
842  /*ScopeLookupResult=*/nullptr, false,
843  IsCorrectedToColon, OnlyNamespace);
844 }
845 
847  const DeclSpec &DS,
848  SourceLocation ColonColonLoc) {
849  if (SS.isInvalid() || DS.getTypeSpecType() == DeclSpec::TST_error)
850  return true;
851 
852  assert(DS.getTypeSpecType() == DeclSpec::TST_decltype);
853 
855  if (T.isNull())
856  return true;
857 
858  if (!T->isDependentType() && !T->getAs<TagType>()) {
859  Diag(DS.getTypeSpecTypeLoc(), diag::err_expected_class_or_namespace)
860  << T << getLangOpts().CPlusPlus;
861  return true;
862  }
863 
864  TypeLocBuilder TLB;
865  DecltypeTypeLoc DecltypeTL = TLB.push<DecltypeTypeLoc>(T);
866  DecltypeTL.setNameLoc(DS.getTypeSpecTypeLoc());
868  ColonColonLoc);
869  return false;
870 }
871 
872 /// IsInvalidUnlessNestedName - This method is used for error recovery
873 /// purposes to determine whether the specified identifier is only valid as
874 /// a nested name specifier, for example a namespace name. It is
875 /// conservatively correct to always return false from this method.
876 ///
877 /// The arguments are the same as those passed to ActOnCXXNestedNameSpecifier.
879  NestedNameSpecInfo &IdInfo,
880  bool EnteringContext) {
881  if (SS.isInvalid())
882  return false;
883 
884  return !BuildCXXNestedNameSpecifier(S, IdInfo, EnteringContext, SS,
885  /*ScopeLookupResult=*/nullptr, true);
886 }
887 
889  CXXScopeSpec &SS,
890  SourceLocation TemplateKWLoc,
891  TemplateTy OpaqueTemplate,
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  TemplateName Template = OpaqueTemplate.get();
902 
903  // Translate the parser's template argument list in our AST format.
904  TemplateArgumentListInfo TemplateArgs(LAngleLoc, RAngleLoc);
905  translateTemplateArguments(TemplateArgsIn, TemplateArgs);
906 
908  if (DTN && DTN->isIdentifier()) {
909  // Handle a dependent template specialization for which we cannot resolve
910  // the template name.
911  assert(DTN->getQualifier() == SS.getScopeRep());
913  DTN->getQualifier(),
914  DTN->getIdentifier(),
915  TemplateArgs);
916 
917  // Create source-location information for this type.
918  TypeLocBuilder Builder;
923  SpecTL.setTemplateKeywordLoc(TemplateKWLoc);
924  SpecTL.setTemplateNameLoc(TemplateNameLoc);
925  SpecTL.setLAngleLoc(LAngleLoc);
926  SpecTL.setRAngleLoc(RAngleLoc);
927  for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
928  SpecTL.setArgLocInfo(I, TemplateArgs[I].getLocInfo());
929 
930  SS.Extend(Context, TemplateKWLoc, Builder.getTypeLocInContext(Context, T),
931  CCLoc);
932  return false;
933  }
934 
935  // If we assumed an undeclared identifier was a template name, try to
936  // typo-correct it now.
937  if (Template.getAsAssumedTemplateName() &&
938  resolveAssumedTemplateNameAsType(S, Template, TemplateNameLoc))
939  return true;
940 
941  TemplateDecl *TD = Template.getAsTemplateDecl();
942  if (Template.getAsOverloadedTemplate() || DTN ||
943  isa<FunctionTemplateDecl>(TD) || isa<VarTemplateDecl>(TD)) {
944  SourceRange R(TemplateNameLoc, RAngleLoc);
945  if (SS.getRange().isValid())
946  R.setBegin(SS.getRange().getBegin());
947 
948  Diag(CCLoc, diag::err_non_type_template_in_nested_name_specifier)
949  << (TD && isa<VarTemplateDecl>(TD)) << Template << R;
950  NoteAllFoundTemplates(Template);
951  return true;
952  }
953 
954  // We were able to resolve the template name to an actual template.
955  // Build an appropriate nested-name-specifier.
956  QualType T = CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
957  if (T.isNull())
958  return true;
959 
960  // Alias template specializations can produce types which are not valid
961  // nested name specifiers.
962  if (!T->isDependentType() && !T->getAs<TagType>()) {
963  Diag(TemplateNameLoc, diag::err_nested_name_spec_non_tag) << T;
964  NoteAllFoundTemplates(Template);
965  return true;
966  }
967 
968  // Provide source-location information for the template specialization type.
969  TypeLocBuilder Builder;
971  = Builder.push<TemplateSpecializationTypeLoc>(T);
972  SpecTL.setTemplateKeywordLoc(TemplateKWLoc);
973  SpecTL.setTemplateNameLoc(TemplateNameLoc);
974  SpecTL.setLAngleLoc(LAngleLoc);
975  SpecTL.setRAngleLoc(RAngleLoc);
976  for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
977  SpecTL.setArgLocInfo(I, TemplateArgs[I].getLocInfo());
978 
979 
980  SS.Extend(Context, TemplateKWLoc, Builder.getTypeLocInContext(Context, T),
981  CCLoc);
982  return false;
983 }
984 
985 namespace {
986  /// A structure that stores a nested-name-specifier annotation,
987  /// including both the nested-name-specifier
988  struct NestedNameSpecifierAnnotation {
989  NestedNameSpecifier *NNS;
990  };
991 }
992 
994  if (SS.isEmpty() || SS.isInvalid())
995  return nullptr;
996 
997  void *Mem = Context.Allocate(
998  (sizeof(NestedNameSpecifierAnnotation) + SS.location_size()),
999  alignof(NestedNameSpecifierAnnotation));
1000  NestedNameSpecifierAnnotation *Annotation
1001  = new (Mem) NestedNameSpecifierAnnotation;
1002  Annotation->NNS = SS.getScopeRep();
1003  memcpy(Annotation + 1, SS.location_data(), SS.location_size());
1004  return Annotation;
1005 }
1006 
1008  SourceRange AnnotationRange,
1009  CXXScopeSpec &SS) {
1010  if (!AnnotationPtr) {
1011  SS.SetInvalid(AnnotationRange);
1012  return;
1013  }
1014 
1015  NestedNameSpecifierAnnotation *Annotation
1016  = static_cast<NestedNameSpecifierAnnotation *>(AnnotationPtr);
1017  SS.Adopt(NestedNameSpecifierLoc(Annotation->NNS, Annotation + 1));
1018 }
1019 
1021  assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
1022 
1023  // Don't enter a declarator context when the current context is an Objective-C
1024  // declaration.
1025  if (isa<ObjCContainerDecl>(CurContext) || isa<ObjCMethodDecl>(CurContext))
1026  return false;
1027 
1028  NestedNameSpecifier *Qualifier = SS.getScopeRep();
1029 
1030  // There are only two places a well-formed program may qualify a
1031  // declarator: first, when defining a namespace or class member
1032  // out-of-line, and second, when naming an explicitly-qualified
1033  // friend function. The latter case is governed by
1034  // C++03 [basic.lookup.unqual]p10:
1035  // In a friend declaration naming a member function, a name used
1036  // in the function declarator and not part of a template-argument
1037  // in a template-id is first looked up in the scope of the member
1038  // function's class. If it is not found, or if the name is part of
1039  // a template-argument in a template-id, the look up is as
1040  // described for unqualified names in the definition of the class
1041  // granting friendship.
1042  // i.e. we don't push a scope unless it's a class member.
1043 
1044  switch (Qualifier->getKind()) {
1048  // These are always namespace scopes. We never want to enter a
1049  // namespace scope from anything but a file context.
1051 
1056  // These are never namespace scopes.
1057  return true;
1058  }
1059 
1060  llvm_unreachable("Invalid NestedNameSpecifier::Kind!");
1061 }
1062 
1063 /// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
1064 /// scope or nested-name-specifier) is parsed, part of a declarator-id.
1065 /// After this method is called, according to [C++ 3.4.3p3], names should be
1066 /// looked up in the declarator-id's scope, until the declarator is parsed and
1067 /// ActOnCXXExitDeclaratorScope is called.
1068 /// The 'SS' should be a non-empty valid CXXScopeSpec.
1070  assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
1071 
1072  if (SS.isInvalid()) return true;
1073 
1074  DeclContext *DC = computeDeclContext(SS, true);
1075  if (!DC) return true;
1076 
1077  // Before we enter a declarator's context, we need to make sure that
1078  // it is a complete declaration context.
1079  if (!DC->isDependentContext() && RequireCompleteDeclContext(SS, DC))
1080  return true;
1081 
1082  EnterDeclaratorContext(S, DC);
1083 
1084  // Rebuild the nested name specifier for the new scope.
1085  if (DC->isDependentContext())
1087 
1088  return false;
1089 }
1090 
1091 /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
1092 /// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
1093 /// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
1094 /// Used to indicate that names should revert to being looked up in the
1095 /// defining scope.
1097  assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
1098  if (SS.isInvalid())
1099  return;
1100  assert(!SS.isInvalid() && computeDeclContext(SS, true) &&
1101  "exiting declarator scope we never really entered");
1103 }
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:135
PtrTy get() const
Definition: Ownership.h:80
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:106
A (possibly-)qualified type.
Definition: Type.h:643
Keeps information about an identifier in a nested-name-spec.
Definition: Sema.h:5571
Simple class containing the result of Sema::CorrectTypo.
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:498
unsigned getNumBases() const
Retrieves the number of base classes of this class.
Definition: DeclCXX.h:817
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:3172
void setLookupName(DeclarationName Name)
Sets the name to look up.
Definition: Lookup.h:248
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:1603
Microsoft&#39;s &#39;__super&#39; specifier, stored as a CXXRecordDecl* of the class it appeared in...
bool isEmpty() const
No scope specifier.
Definition: DeclSpec.h:189
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID)
Emit a diagnostic.
Definition: Sema.h:1353
TagDecl * getDecl() const
Definition: Type.cpp:3268
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:1418
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2126
Represent a C++ namespace.
Definition: Decl.h:514
Wrapper for source info for typedefs.
Definition: TypeLoc.h:666
Look up of a name that precedes the &#39;::&#39; scope resolution operator in C++.
Definition: Sema.h:3188
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:1686
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 ...
LLVM_ATTRIBUTE_REINITIALIZES void clear()
Clears out any current state.
Definition: Lookup.h:554
void * SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS)
Given a C++ nested-name-specifier, produce an annotation value that the parser can use later to recon...
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
Definition: TemplateName.h:504
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:3192
An identifier, stored as an IdentifierInfo*.
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Definition: DeclSpec.cpp:124
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
Definition: SemaInternal.h:24
DeclarationName getLookupName() const
Gets the name to look up.
Definition: Lookup.h:243
bool isEnumeralType() const
Definition: Type.h:6435
const T * getAs() const
Member-template getAs<specific type>&#39;.
Definition: Type.h:6818
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:431
bool isAmbiguous() const
Definition: Lookup.h:301
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:686
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:442
SourceLocation getTypeSpecTypeLoc() const
Definition: DeclSpec.h:505
NamespaceDecl * getNamespace()
Retrieve the namespace declaration aliased by this directive.
Definition: DeclCXX.h:3216
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:1619
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:233
static const TST TST_error
Definition: DeclSpec.h:310
Wrapper for source info for unresolved typename using decls.
Definition: TypeLoc.h:688
DeclClass * getAsSingle() const
Definition: Lookup.h:507
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:523
Represents the results of name lookup.
Definition: Lookup.h:46
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2150
Wrapper for source info for injected class names of class templates.
Definition: TypeLoc.h:677
A convenient class for passing around template argument information.
Definition: TemplateBase.h:554
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:840
Represents a declaration of a type.
Definition: Decl.h:2900
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:833
bool isLambda() const
Determine whether this class describes a lambda function object.
Definition: DeclCXX.h:1196
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6127
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:1276
void addDecl(NamedDecl *D)
Add a declaration to these results with its natural access.
Definition: Lookup.h:426
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context...
Definition: DeclSpec.cpp:142
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:877
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:328
void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool MightBeOdrUse)
Perform marking for a reference to an arbitrary declaration.
Definition: SemaExpr.cpp:16465
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:2158
TST getTypeSpecType() const
Definition: DeclSpec.h:473
Scope * getCurScope() const
Retrieve the parser&#39;s current scope.
Definition: Sema.h:11063
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:2134
SourceLocation IdentifierLoc
The location of the identifier.
Definition: Sema.h:5580
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:2106
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;.
This file defines the classes used to store parsed information about declaration-specifiers and decla...
std::string getAsString() const
Retrieve the human-readable string for this name.
bool isFileContext() const
Definition: DeclBase.h:1842
bool hasAnyDependentBases() const
Determine whether this class has any dependent base classes which are not the current instantiation...
Definition: DeclCXX.cpp:525
void NoteAllFoundTemplates(TemplateName Name)
Represents a C++ template name within the type system.
Definition: TemplateName.h:187
bool RequireCompleteType(SourceLocation Loc, QualType T, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
Definition: SemaType.cpp:7805
bool isIdentifier() const
Determine whether this template name refers to an identifier.
Definition: TemplateName.h:501
A namespace alias, stored as a NamespaceAliasDecl*.
bool isFunctionOrMethod() const
Definition: DeclBase.h:1824
TagDecl * getAsTagDecl() const
Retrieves the TagDecl that this type refers to, either because the type is a TagType or because it is...
Definition: Type.cpp:1644
Wrapper for source info for enum types.
Definition: TypeLoc.h:726
bool isSingleResult() const
Determines if this names a single result which is not an unresolved value using decl.
Definition: Lookup.h:308
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1772
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:5577
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1081
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:1395
The result type of a method or function.
This template specialization was implicitly instantiated from a template.
Definition: Specifiers.h:180
bool isNull() const
Return true if this QualType doesn&#39;t point to a type yet.
Definition: Type.h:708
bool resolveAssumedTemplateNameAsType(Scope *S, TemplateName &Name, SourceLocation NameLoc, bool Diagnose=true)
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:4180
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 declarations that this template name refers to...
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2142
Encodes a location in the source.
void ExitDeclaratorContext(Scope *S)
Definition: SemaDecl.cpp:1298
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3090
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2109
SourceLocation CCLoc
The location of the &#39;::&#39;.
Definition: Sema.h:5583
bool hasVisibleDefinition(NamedDecl *D, NamedDecl **Suggested, bool OnlyNeedComplete=false)
Determine if D has a visible definition.
Definition: SemaType.cpp:7842
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
TypoCorrection CorrectTypo(const DeclarationNameInfo &Typo, Sema::LookupNameKind LookupKind, Scope *S, CXXScopeSpec *SS, 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...
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2094
bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef< SourceLocation > Locs, const ObjCInterfaceDecl *UnknownObjCClass=nullptr, bool ObjCPropertyAccess=false, bool AvoidPartialAvailabilityChecks=false, ObjCInterfaceDecl *ClassReciever=nullptr)
Determine whether the use of this declaration is valid, and emit any corresponding diagnostics...
Definition: SemaExpr.cpp:211
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
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:669
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1595
void diagnoseTypo(const TypoCorrection &Correction, const PartialDiagnostic &TypoDiag, bool ErrorRecovery=true)
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:2942
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:1271
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:403
void setContextRange(SourceRange SR)
Sets a &#39;context&#39; source range.
Definition: Lookup.h:593
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:1269
static const TST TST_decltype
Definition: DeclSpec.h:300
bool isRecord() const
Definition: DeclBase.h:1851
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.
The name of a declaration.
Represents an enum.
Definition: Decl.h:3352
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:4423
QualType getCanonicalTypeInternal() const
Definition: Type.h:2372
This template specialization was declared or defined by an explicit specialization (C++ [temp...
Definition: Specifiers.h:184
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:8345
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1736
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2293
Wrapper for source info for record types.
Definition: TypeLoc.h:718
AssumedTemplateStorage * getAsAssumedTemplateName() const
Retrieve information on a name that has been assumed to be a template-name in order to permit a call ...
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:253
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
Definition: SemaType.cpp:2632
ParsedType ObjectType
The type of the object, if we&#39;re parsing nested-name-specifier in a member access expression...
Definition: Sema.h:5574
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:2277
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:46
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1004
Captures information about "declaration specifiers".
Definition: DeclSpec.h:228
Represents a C++ struct/union/class.
Definition: DeclCXX.h:300
bool isValid() const
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:664
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:386
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:128
void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc)
Turn this (empty) nested-name-specifier into the global nested-name-specifier &#39;::&#39;.
Definition: DeclSpec.cpp:96
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1611
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:275
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2093
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:4896
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:583
bool empty() const
Return true if no decls were found.
Definition: Lookup.h:339
Wrapper for template type parameters.
Definition: TypeLoc.h:734
A trivial tuple used to represent a source range.
ASTContext & Context
Definition: Sema.h:374
This represents a decl that may have a name.
Definition: Decl.h:248
Expr * getRepAsExpr() const
Definition: DeclSpec.h:490
Represents a C++ namespace alias.
Definition: DeclCXX.h:3143
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:1635
No keyword precedes the qualified type name.
Definition: Type.h:5126
SourceLocation getNameLoc() const
Gets the location of the identifier.
Definition: Lookup.h:606
NamedDecl * getRepresentativeDecl() const
Fetches a representative decl. Useful for lazy diagnostics.
Definition: Lookup.h:524
The global specifier &#39;::&#39;. There is no stored value.
SourceLocation getBegin() const
const LangOptions & getLangOpts() const
Definition: ASTContext.h:707
SourceLocation getLocation() const
Definition: DeclBase.h:429
bool isEditorPlaceholder() const
Return true if this identifier is an editor placeholder.
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition: Decl.h:3215