clang 19.0.0git
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"
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"
24using 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
58 return ::getCurrentInstantiationOf(T, CurContext);
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
80 if (NNS->isDependent()) {
81 // If this nested-name-specifier refers to the current
82 // instantiation, return its DeclContext.
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.
100 = dyn_cast_or_null<ClassTemplateDecl>(
101 SpecType->getTemplateName().getAsTemplateDecl())) {
103 Context.getCanonicalType(QualType(SpecType, 0));
104
105 // FIXME: The fallback on the search of partial
106 // specialization using ContextType should be eventually removed since
107 // it doesn't handle the case of constrained template parameters
108 // correctly. Currently removing this fallback would change the
109 // diagnostic output for invalid code in a number of tests.
110 ClassTemplatePartialSpecializationDecl *PartialSpec = nullptr;
111 ArrayRef<TemplateParameterList *> TemplateParamLists =
113 if (!TemplateParamLists.empty()) {
114 unsigned Depth = ClassTemplate->getTemplateParameters()->getDepth();
115 auto L = find_if(TemplateParamLists,
116 [Depth](TemplateParameterList *TPL) {
117 return TPL->getDepth() == Depth;
118 });
119 if (L != TemplateParamLists.end()) {
120 void *Pos = nullptr;
121 PartialSpec = ClassTemplate->findPartialSpecialization(
122 SpecType->template_arguments(), *L, Pos);
123 }
124 } else {
125 PartialSpec = ClassTemplate->findPartialSpecialization(ContextType);
126 }
127
128 if (PartialSpec) {
129 // A declaration of the partial specialization must be visible.
130 // We can always recover here, because this only happens when we're
131 // entering the context, and that can't happen in a SFINAE context.
132 assert(!isSFINAEContext() && "partial specialization scope "
133 "specifier in SFINAE context?");
134 if (PartialSpec->hasDefinition() &&
135 !hasReachableDefinition(PartialSpec))
138 true);
139 return PartialSpec;
140 }
141
142 // If the type of the nested name specifier is the same as the
143 // injected class name of the named class template, we're entering
144 // into that class template definition.
145 QualType Injected =
146 ClassTemplate->getInjectedClassNameSpecialization();
147 if (Context.hasSameType(Injected, ContextType))
148 return ClassTemplate->getTemplatedDecl();
149 }
150 } else if (const RecordType *RecordT = NNSType->getAs<RecordType>()) {
151 // The nested name specifier refers to a member of a class template.
152 return RecordT->getDecl();
153 }
154 }
155
156 return nullptr;
157 }
158
159 switch (NNS->getKind()) {
161 llvm_unreachable("Dependent nested-name-specifier has no DeclContext");
162
164 return NNS->getAsNamespace();
165
167 return NNS->getAsNamespaceAlias()->getNamespace();
168
171 const TagType *Tag = NNS->getAsType()->getAs<TagType>();
172 assert(Tag && "Non-tag type in nested-name-specifier");
173 return Tag->getDecl();
174 }
175
178
180 return NNS->getAsRecordDecl();
181 }
182
183 llvm_unreachable("Invalid NestedNameSpecifier::Kind!");
184}
185
187 if (!SS.isSet() || SS.isInvalid())
188 return false;
189
190 return SS.getScopeRep()->isDependent();
191}
192
193/// If the given nested name specifier refers to the current
194/// instantiation, return the declaration that corresponds to that
195/// current instantiation (C++0x [temp.dep.type]p1).
196///
197/// \param NNS a dependent nested name specifier.
199 assert(getLangOpts().CPlusPlus && "Only callable in C++");
200 assert(NNS->isDependent() && "Only dependent nested-name-specifier allowed");
201
202 if (!NNS->getAsType())
203 return nullptr;
204
205 QualType T = QualType(NNS->getAsType(), 0);
206 return ::getCurrentInstantiationOf(T, CurContext);
207}
208
209/// Require that the context specified by SS be complete.
210///
211/// If SS refers to a type, this routine checks whether the type is
212/// complete enough (or can be made complete enough) for name lookup
213/// into the DeclContext. A type that is not yet completed can be
214/// considered "complete enough" if it is a class/struct/union/enum
215/// that is currently being defined. Or, if we have a type that names
216/// a class template specialization that is not a complete type, we
217/// will attempt to instantiate that class template.
219 DeclContext *DC) {
220 assert(DC && "given null context");
221
222 TagDecl *tag = dyn_cast<TagDecl>(DC);
223
224 // If this is a dependent type, then we consider it complete.
225 // FIXME: This is wrong; we should require a (visible) definition to
226 // exist in this case too.
227 if (!tag || tag->isDependentContext())
228 return false;
229
230 // Grab the tag definition, if there is one.
232 tag = type->getAsTagDecl();
233
234 // If we're currently defining this type, then lookup into the
235 // type is okay: don't complain that it isn't complete yet.
236 if (tag->isBeingDefined())
237 return false;
238
240 if (loc.isInvalid()) loc = SS.getRange().getBegin();
241
242 // The type must be complete.
243 if (RequireCompleteType(loc, type, diag::err_incomplete_nested_name_spec,
244 SS.getRange())) {
245 SS.SetInvalid(SS.getRange());
246 return true;
247 }
248
249 if (auto *EnumD = dyn_cast<EnumDecl>(tag))
250 // Fixed enum types and scoped enum instantiations are complete, but they
251 // aren't valid as scopes until we see or instantiate their definition.
252 return RequireCompleteEnumDecl(EnumD, loc, &SS);
253
254 return false;
255}
256
257/// Require that the EnumDecl is completed with its enumerators defined or
258/// instantiated. SS, if provided, is the ScopeRef parsed.
259///
261 CXXScopeSpec *SS) {
262 if (EnumD->isCompleteDefinition()) {
263 // If we know about the definition but it is not visible, complain.
264 NamedDecl *SuggestedDef = nullptr;
265 if (!hasReachableDefinition(EnumD, &SuggestedDef,
266 /*OnlyNeedComplete*/ false)) {
267 // If the user is going to see an error here, recover by making the
268 // definition visible.
269 bool TreatAsComplete = !isSFINAEContext();
271 /*Recover*/ TreatAsComplete);
272 return !TreatAsComplete;
273 }
274 return false;
275 }
276
277 // Try to instantiate the definition, if this is a specialization of an
278 // enumeration temploid.
279 if (EnumDecl *Pattern = EnumD->getInstantiatedFromMemberEnum()) {
282 if (InstantiateEnum(L, EnumD, Pattern,
285 if (SS)
286 SS->SetInvalid(SS->getRange());
287 return true;
288 }
289 return false;
290 }
291 }
292
293 if (SS) {
294 Diag(L, diag::err_incomplete_nested_name_spec)
295 << QualType(EnumD->getTypeForDecl(), 0) << SS->getRange();
296 SS->SetInvalid(SS->getRange());
297 } else {
298 Diag(L, diag::err_incomplete_enum) << QualType(EnumD->getTypeForDecl(), 0);
299 Diag(EnumD->getLocation(), diag::note_declared_at);
300 }
301
302 return true;
303}
304
306 CXXScopeSpec &SS) {
307 SS.MakeGlobal(Context, CCLoc);
308 return false;
309}
310
312 SourceLocation ColonColonLoc,
313 CXXScopeSpec &SS) {
314 if (getCurLambda()) {
315 Diag(SuperLoc, diag::err_super_in_lambda_unsupported);
316 return true;
317 }
318
319 CXXRecordDecl *RD = nullptr;
320 for (Scope *S = getCurScope(); S; S = S->getParent()) {
321 if (S->isFunctionScope()) {
322 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(S->getEntity()))
323 RD = MD->getParent();
324 break;
325 }
326 if (S->isClassScope()) {
327 RD = cast<CXXRecordDecl>(S->getEntity());
328 break;
329 }
330 }
331
332 if (!RD) {
333 Diag(SuperLoc, diag::err_invalid_super_scope);
334 return true;
335 } else if (RD->getNumBases() == 0) {
336 Diag(SuperLoc, diag::err_no_base_classes) << RD->getName();
337 return true;
338 }
339
340 SS.MakeSuper(Context, RD, SuperLoc, ColonColonLoc);
341 return false;
342}
343
344/// Determines whether the given declaration is an valid acceptable
345/// result for name lookup of a nested-name-specifier.
346/// \param SD Declaration checked for nested-name-specifier.
347/// \param IsExtension If not null and the declaration is accepted as an
348/// extension, the pointed variable is assigned true.
350 bool *IsExtension) {
351 if (!SD)
352 return false;
353
354 SD = SD->getUnderlyingDecl();
355
356 // Namespace and namespace aliases are fine.
357 if (isa<NamespaceDecl>(SD))
358 return true;
359
360 if (!isa<TypeDecl>(SD))
361 return false;
362
363 // Determine whether we have a class (or, in C++11, an enum) or
364 // a typedef thereof. If so, build the nested-name-specifier.
365 QualType T = Context.getTypeDeclType(cast<TypeDecl>(SD));
366 if (T->isDependentType())
367 return true;
368 if (const TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(SD)) {
369 if (TD->getUnderlyingType()->isRecordType())
370 return true;
371 if (TD->getUnderlyingType()->isEnumeralType()) {
372 if (Context.getLangOpts().CPlusPlus11)
373 return true;
374 if (IsExtension)
375 *IsExtension = true;
376 }
377 } else if (isa<RecordDecl>(SD)) {
378 return true;
379 } else if (isa<EnumDecl>(SD)) {
380 if (Context.getLangOpts().CPlusPlus11)
381 return true;
382 if (IsExtension)
383 *IsExtension = true;
384 }
385
386 return false;
387}
388
389/// If the given nested-name-specifier begins with a bare identifier
390/// (e.g., Base::), perform name lookup for that identifier as a
391/// nested-name-specifier within the given scope, and return the result of that
392/// name lookup.
394 if (!S || !NNS)
395 return nullptr;
396
397 while (NNS->getPrefix())
398 NNS = NNS->getPrefix();
399
401 return nullptr;
402
403 LookupResult Found(*this, NNS->getAsIdentifier(), SourceLocation(),
405 LookupName(Found, S);
406 assert(!Found.isAmbiguous() && "Cannot handle ambiguities here yet");
407
408 if (!Found.isSingleResult())
409 return nullptr;
410
411 NamedDecl *Result = Found.getFoundDecl();
413 return Result;
414
415 return nullptr;
416}
417
418namespace {
419
420// Callback to only accept typo corrections that can be a valid C++ member
421// initializer: either a non-static field member or a base class.
422class NestedNameSpecifierValidatorCCC final
424public:
425 explicit NestedNameSpecifierValidatorCCC(Sema &SRef)
426 : SRef(SRef) {}
427
428 bool ValidateCandidate(const TypoCorrection &candidate) override {
429 return SRef.isAcceptableNestedNameSpecifier(candidate.getCorrectionDecl());
430 }
431
432 std::unique_ptr<CorrectionCandidateCallback> clone() override {
433 return std::make_unique<NestedNameSpecifierValidatorCCC>(*this);
434 }
435
436 private:
437 Sema &SRef;
438};
439
440}
441
442/// Build a new nested-name-specifier for "identifier::", as described
443/// by ActOnCXXNestedNameSpecifier.
444///
445/// \param S Scope in which the nested-name-specifier occurs.
446/// \param IdInfo Parser information about an identifier in the
447/// nested-name-spec.
448/// \param EnteringContext If true, enter the context specified by the
449/// nested-name-specifier.
450/// \param SS Optional nested name specifier preceding the identifier.
451/// \param ScopeLookupResult Provides the result of name lookup within the
452/// scope of the nested-name-specifier that was computed at template
453/// definition time.
454/// \param ErrorRecoveryLookup Specifies if the method is called to improve
455/// error recovery and what kind of recovery is performed.
456/// \param IsCorrectedToColon If not null, suggestion of replace '::' -> ':'
457/// are allowed. The bool value pointed by this parameter is set to
458/// 'true' if the identifier is treated as if it was followed by ':',
459/// not '::'.
460/// \param OnlyNamespace If true, only considers namespaces in lookup.
461///
462/// This routine differs only slightly from ActOnCXXNestedNameSpecifier, in
463/// that it contains an extra parameter \p ScopeLookupResult, which provides
464/// the result of name lookup within the scope of the nested-name-specifier
465/// that was computed at template definition time.
466///
467/// If ErrorRecoveryLookup is true, then this call is used to improve error
468/// recovery. This means that it should not emit diagnostics, it should
469/// just return true on failure. It also means it should only return a valid
470/// scope if it *knows* that the result is correct. It should not return in a
471/// dependent context, for example. Nor will it extend \p SS with the scope
472/// specifier.
474 bool EnteringContext, CXXScopeSpec &SS,
475 NamedDecl *ScopeLookupResult,
476 bool ErrorRecoveryLookup,
477 bool *IsCorrectedToColon,
478 bool OnlyNamespace) {
479 if (IdInfo.Identifier->isEditorPlaceholder())
480 return true;
481 LookupResult Found(*this, IdInfo.Identifier, IdInfo.IdentifierLoc,
482 OnlyNamespace ? LookupNamespaceName
484 QualType ObjectType = GetTypeFromParser(IdInfo.ObjectType);
485
486 // Determine where to perform name lookup
487 DeclContext *LookupCtx = nullptr;
488 bool isDependent = false;
489 if (IsCorrectedToColon)
490 *IsCorrectedToColon = false;
491 if (!ObjectType.isNull()) {
492 // This nested-name-specifier occurs in a member access expression, e.g.,
493 // x->B::f, and we are looking into the type of the object.
494 assert(!SS.isSet() && "ObjectType and scope specifier cannot coexist");
495 LookupCtx = computeDeclContext(ObjectType);
496 isDependent = ObjectType->isDependentType();
497 } else if (SS.isSet()) {
498 // This nested-name-specifier occurs after another nested-name-specifier,
499 // so look into the context associated with the prior nested-name-specifier.
500 LookupCtx = computeDeclContext(SS, EnteringContext);
501 isDependent = isDependentScopeSpecifier(SS);
502 Found.setContextRange(SS.getRange());
503 }
504
505 bool ObjectTypeSearchedInScope = false;
506 if (LookupCtx) {
507 // Perform "qualified" name lookup into the declaration context we
508 // computed, which is either the type of the base of a member access
509 // expression or the declaration context associated with a prior
510 // nested-name-specifier.
511
512 // The declaration context must be complete.
513 if (!LookupCtx->isDependentContext() &&
514 RequireCompleteDeclContext(SS, LookupCtx))
515 return true;
516
517 LookupQualifiedName(Found, LookupCtx);
518
519 if (!ObjectType.isNull() && Found.empty()) {
520 // C++ [basic.lookup.classref]p4:
521 // If the id-expression in a class member access is a qualified-id of
522 // the form
523 //
524 // class-name-or-namespace-name::...
525 //
526 // the class-name-or-namespace-name following the . or -> operator is
527 // looked up both in the context of the entire postfix-expression and in
528 // the scope of the class of the object expression. If the name is found
529 // only in the scope of the class of the object expression, the name
530 // shall refer to a class-name. If the name is found only in the
531 // context of the entire postfix-expression, the name shall refer to a
532 // class-name or namespace-name. [...]
533 //
534 // Qualified name lookup into a class will not find a namespace-name,
535 // so we do not need to diagnose that case specifically. However,
536 // this qualified name lookup may find nothing. In that case, perform
537 // unqualified name lookup in the given scope (if available) or
538 // reconstruct the result from when name lookup was performed at template
539 // definition time.
540 if (S)
541 LookupName(Found, S);
542 else if (ScopeLookupResult)
543 Found.addDecl(ScopeLookupResult);
544
545 ObjectTypeSearchedInScope = true;
546 }
547 } else if (!isDependent) {
548 // Perform unqualified name lookup in the current scope.
549 LookupName(Found, S);
550 }
551
552 if (Found.isAmbiguous())
553 return true;
554
555 // If we performed lookup into a dependent context and did not find anything,
556 // that's fine: just build a dependent nested-name-specifier.
557 if (Found.empty() && isDependent &&
558 !(LookupCtx && LookupCtx->isRecord() &&
559 (!cast<CXXRecordDecl>(LookupCtx)->hasDefinition() ||
560 !cast<CXXRecordDecl>(LookupCtx)->hasAnyDependentBases()))) {
561 // Don't speculate if we're just trying to improve error recovery.
562 if (ErrorRecoveryLookup)
563 return true;
564
565 // We were not able to compute the declaration context for a dependent
566 // base object type or prior nested-name-specifier, so this
567 // nested-name-specifier refers to an unknown specialization. Just build
568 // a dependent nested-name-specifier.
569 SS.Extend(Context, IdInfo.Identifier, IdInfo.IdentifierLoc, IdInfo.CCLoc);
570 return false;
571 }
572
573 if (Found.empty() && !ErrorRecoveryLookup) {
574 // If identifier is not found as class-name-or-namespace-name, but is found
575 // as other entity, don't look for typos.
577 if (LookupCtx)
578 LookupQualifiedName(R, LookupCtx);
579 else if (S && !isDependent)
580 LookupName(R, S);
581 if (!R.empty()) {
582 // Don't diagnose problems with this speculative lookup.
584 // The identifier is found in ordinary lookup. If correction to colon is
585 // allowed, suggest replacement to ':'.
586 if (IsCorrectedToColon) {
587 *IsCorrectedToColon = true;
588 Diag(IdInfo.CCLoc, diag::err_nested_name_spec_is_not_class)
589 << IdInfo.Identifier << getLangOpts().CPlusPlus
590 << FixItHint::CreateReplacement(IdInfo.CCLoc, ":");
591 if (NamedDecl *ND = R.getAsSingle<NamedDecl>())
592 Diag(ND->getLocation(), diag::note_declared_at);
593 return true;
594 }
595 // Replacement '::' -> ':' is not allowed, just issue respective error.
596 Diag(R.getNameLoc(), OnlyNamespace
597 ? unsigned(diag::err_expected_namespace_name)
598 : unsigned(diag::err_expected_class_or_namespace))
599 << IdInfo.Identifier << getLangOpts().CPlusPlus;
600 if (NamedDecl *ND = R.getAsSingle<NamedDecl>())
601 Diag(ND->getLocation(), diag::note_entity_declared_at)
602 << IdInfo.Identifier;
603 return true;
604 }
605 }
606
607 if (Found.empty() && !ErrorRecoveryLookup && !getLangOpts().MSVCCompat) {
608 // We haven't found anything, and we're not recovering from a
609 // different kind of error, so look for typos.
610 DeclarationName Name = Found.getLookupName();
611 Found.clear();
612 NestedNameSpecifierValidatorCCC CCC(*this);
613 if (TypoCorrection Corrected = CorrectTypo(
614 Found.getLookupNameInfo(), Found.getLookupKind(), S, &SS, CCC,
615 CTK_ErrorRecovery, LookupCtx, EnteringContext)) {
616 if (LookupCtx) {
617 bool DroppedSpecifier =
618 Corrected.WillReplaceSpecifier() &&
619 Name.getAsString() == Corrected.getAsString(getLangOpts());
620 if (DroppedSpecifier)
621 SS.clear();
622 diagnoseTypo(Corrected, PDiag(diag::err_no_member_suggest)
623 << Name << LookupCtx << DroppedSpecifier
624 << SS.getRange());
625 } else
626 diagnoseTypo(Corrected, PDiag(diag::err_undeclared_var_use_suggest)
627 << Name);
628
629 if (Corrected.getCorrectionSpecifier())
630 SS.MakeTrivial(Context, Corrected.getCorrectionSpecifier(),
631 SourceRange(Found.getNameLoc()));
632
633 if (NamedDecl *ND = Corrected.getFoundDecl())
634 Found.addDecl(ND);
635 Found.setLookupName(Corrected.getCorrection());
636 } else {
637 Found.setLookupName(IdInfo.Identifier);
638 }
639 }
640
641 NamedDecl *SD =
642 Found.isSingleResult() ? Found.getRepresentativeDecl() : nullptr;
643 bool IsExtension = false;
644 bool AcceptSpec = isAcceptableNestedNameSpecifier(SD, &IsExtension);
645 if (!AcceptSpec && IsExtension) {
646 AcceptSpec = true;
647 Diag(IdInfo.IdentifierLoc, diag::ext_nested_name_spec_is_enum);
648 }
649 if (AcceptSpec) {
650 if (!ObjectType.isNull() && !ObjectTypeSearchedInScope &&
652 // C++03 [basic.lookup.classref]p4:
653 // [...] If the name is found in both contexts, the
654 // class-name-or-namespace-name shall refer to the same entity.
655 //
656 // We already found the name in the scope of the object. Now, look
657 // into the current scope (the scope of the postfix-expression) to
658 // see if we can find the same name there. As above, if there is no
659 // scope, reconstruct the result from the template instantiation itself.
660 //
661 // Note that C++11 does *not* perform this redundant lookup.
662 NamedDecl *OuterDecl;
663 if (S) {
664 LookupResult FoundOuter(*this, IdInfo.Identifier, IdInfo.IdentifierLoc,
666 LookupName(FoundOuter, S);
667 OuterDecl = FoundOuter.getAsSingle<NamedDecl>();
668 } else
669 OuterDecl = ScopeLookupResult;
670
671 if (isAcceptableNestedNameSpecifier(OuterDecl) &&
672 OuterDecl->getCanonicalDecl() != SD->getCanonicalDecl() &&
673 (!isa<TypeDecl>(OuterDecl) || !isa<TypeDecl>(SD) ||
675 Context.getTypeDeclType(cast<TypeDecl>(OuterDecl)),
676 Context.getTypeDeclType(cast<TypeDecl>(SD))))) {
677 if (ErrorRecoveryLookup)
678 return true;
679
680 Diag(IdInfo.IdentifierLoc,
681 diag::err_nested_name_member_ref_lookup_ambiguous)
682 << IdInfo.Identifier;
683 Diag(SD->getLocation(), diag::note_ambig_member_ref_object_type)
684 << ObjectType;
685 Diag(OuterDecl->getLocation(), diag::note_ambig_member_ref_scope);
686
687 // Fall through so that we'll pick the name we found in the object
688 // type, since that's probably what the user wanted anyway.
689 }
690 }
691
692 if (auto *TD = dyn_cast_or_null<TypedefNameDecl>(SD))
693 MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
694
695 // If we're just performing this lookup for error-recovery purposes,
696 // don't extend the nested-name-specifier. Just return now.
697 if (ErrorRecoveryLookup)
698 return false;
699
700 // The use of a nested name specifier may trigger deprecation warnings.
701 DiagnoseUseOfDecl(SD, IdInfo.CCLoc);
702
703 if (NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(SD)) {
704 SS.Extend(Context, Namespace, IdInfo.IdentifierLoc, IdInfo.CCLoc);
705 return false;
706 }
707
708 if (NamespaceAliasDecl *Alias = dyn_cast<NamespaceAliasDecl>(SD)) {
709 SS.Extend(Context, Alias, IdInfo.IdentifierLoc, IdInfo.CCLoc);
710 return false;
711 }
712
713 QualType T =
714 Context.getTypeDeclType(cast<TypeDecl>(SD->getUnderlyingDecl()));
715
716 if (T->isEnumeralType())
717 Diag(IdInfo.IdentifierLoc, diag::warn_cxx98_compat_enum_nested_name_spec);
718
719 TypeLocBuilder TLB;
720 if (const auto *USD = dyn_cast<UsingShadowDecl>(SD)) {
721 T = Context.getUsingType(USD, T);
723 } else if (isa<InjectedClassNameType>(T)) {
724 InjectedClassNameTypeLoc InjectedTL
726 InjectedTL.setNameLoc(IdInfo.IdentifierLoc);
727 } else if (isa<RecordType>(T)) {
728 RecordTypeLoc RecordTL = TLB.push<RecordTypeLoc>(T);
729 RecordTL.setNameLoc(IdInfo.IdentifierLoc);
730 } else if (isa<TypedefType>(T)) {
731 TypedefTypeLoc TypedefTL = TLB.push<TypedefTypeLoc>(T);
732 TypedefTL.setNameLoc(IdInfo.IdentifierLoc);
733 } else if (isa<EnumType>(T)) {
734 EnumTypeLoc EnumTL = TLB.push<EnumTypeLoc>(T);
735 EnumTL.setNameLoc(IdInfo.IdentifierLoc);
736 } else if (isa<TemplateTypeParmType>(T)) {
737 TemplateTypeParmTypeLoc TemplateTypeTL
739 TemplateTypeTL.setNameLoc(IdInfo.IdentifierLoc);
740 } else if (isa<UnresolvedUsingType>(T)) {
741 UnresolvedUsingTypeLoc UnresolvedTL
743 UnresolvedTL.setNameLoc(IdInfo.IdentifierLoc);
744 } else if (isa<SubstTemplateTypeParmType>(T)) {
747 TL.setNameLoc(IdInfo.IdentifierLoc);
748 } else if (isa<SubstTemplateTypeParmPackType>(T)) {
751 TL.setNameLoc(IdInfo.IdentifierLoc);
752 } else {
753 llvm_unreachable("Unhandled TypeDecl node in nested-name-specifier");
754 }
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()) {
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 if (Found.getAsSingle<TemplateDecl>()) {
811 ParsedType SuggestedType;
812 DiagnoseUnknownTypeName(IdInfo.Identifier, IdInfo.IdentifierLoc, S, &SS,
813 SuggestedType);
814 } else {
815 Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace)
816 << IdInfo.Identifier << getLangOpts().CPlusPlus;
817 if (NamedDecl *ND = Found.getAsSingle<NamedDecl>())
818 Diag(ND->getLocation(), diag::note_entity_declared_at)
819 << IdInfo.Identifier;
820 }
821 } else if (SS.isSet())
822 Diag(IdInfo.IdentifierLoc, diag::err_no_member) << IdInfo.Identifier
823 << LookupCtx << SS.getRange();
824 else
825 Diag(IdInfo.IdentifierLoc, diag::err_undeclared_var_use)
826 << IdInfo.Identifier;
827
828 return true;
829}
830
832 bool EnteringContext, CXXScopeSpec &SS,
833 bool *IsCorrectedToColon,
834 bool OnlyNamespace) {
835 if (SS.isInvalid())
836 return true;
837
838 return BuildCXXNestedNameSpecifier(S, IdInfo, EnteringContext, SS,
839 /*ScopeLookupResult=*/nullptr, false,
840 IsCorrectedToColon, OnlyNamespace);
841}
842
844 const DeclSpec &DS,
845 SourceLocation ColonColonLoc) {
847 return true;
848
850
852 if (T.isNull())
853 return true;
854
855 if (!T->isDependentType() && !T->getAs<TagType>()) {
856 Diag(DS.getTypeSpecTypeLoc(), diag::err_expected_class_or_namespace)
857 << T << getLangOpts().CPlusPlus;
858 return true;
859 }
860
861 TypeLocBuilder TLB;
862 DecltypeTypeLoc DecltypeTL = TLB.push<DecltypeTypeLoc>(T);
863 DecltypeTL.setDecltypeLoc(DS.getTypeSpecTypeLoc());
864 DecltypeTL.setRParenLoc(DS.getTypeofParensRange().getEnd());
866 ColonColonLoc);
867 return false;
868}
869
871 const DeclSpec &DS,
872 SourceLocation ColonColonLoc,
873 QualType Type) {
875 return true;
876
878
879 if (Type.isNull())
880 return true;
881
882 TypeLocBuilder TLB;
884 cast<PackIndexingType>(Type.getTypePtr())->getPattern(),
885 DS.getBeginLoc());
889 ColonColonLoc);
890 return false;
891}
892
893/// IsInvalidUnlessNestedName - This method is used for error recovery
894/// purposes to determine whether the specified identifier is only valid as
895/// a nested name specifier, for example a namespace name. It is
896/// conservatively correct to always return false from this method.
897///
898/// The arguments are the same as those passed to ActOnCXXNestedNameSpecifier.
900 NestedNameSpecInfo &IdInfo,
901 bool EnteringContext) {
902 if (SS.isInvalid())
903 return false;
904
905 return !BuildCXXNestedNameSpecifier(S, IdInfo, EnteringContext, SS,
906 /*ScopeLookupResult=*/nullptr, true);
907}
908
910 CXXScopeSpec &SS,
911 SourceLocation TemplateKWLoc,
912 TemplateTy OpaqueTemplate,
913 SourceLocation TemplateNameLoc,
914 SourceLocation LAngleLoc,
915 ASTTemplateArgsPtr TemplateArgsIn,
916 SourceLocation RAngleLoc,
917 SourceLocation CCLoc,
918 bool EnteringContext) {
919 if (SS.isInvalid())
920 return true;
921
922 TemplateName Template = OpaqueTemplate.get();
923
924 // Translate the parser's template argument list in our AST format.
925 TemplateArgumentListInfo TemplateArgs(LAngleLoc, RAngleLoc);
926 translateTemplateArguments(TemplateArgsIn, TemplateArgs);
927
929 if (DTN && DTN->isIdentifier()) {
930 // Handle a dependent template specialization for which we cannot resolve
931 // the template name.
932 assert(DTN->getQualifier() == SS.getScopeRep());
935 TemplateArgs.arguments());
936
937 // Create source-location information for this type.
938 TypeLocBuilder Builder;
943 SpecTL.setTemplateKeywordLoc(TemplateKWLoc);
944 SpecTL.setTemplateNameLoc(TemplateNameLoc);
945 SpecTL.setLAngleLoc(LAngleLoc);
946 SpecTL.setRAngleLoc(RAngleLoc);
947 for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
948 SpecTL.setArgLocInfo(I, TemplateArgs[I].getLocInfo());
949
950 SS.Extend(Context, TemplateKWLoc, Builder.getTypeLocInContext(Context, T),
951 CCLoc);
952 return false;
953 }
954
955 // If we assumed an undeclared identifier was a template name, try to
956 // typo-correct it now.
957 if (Template.getAsAssumedTemplateName() &&
958 resolveAssumedTemplateNameAsType(S, Template, TemplateNameLoc))
959 return true;
960
961 TemplateDecl *TD = Template.getAsTemplateDecl();
962 if (Template.getAsOverloadedTemplate() || DTN ||
963 isa<FunctionTemplateDecl>(TD) || isa<VarTemplateDecl>(TD)) {
964 SourceRange R(TemplateNameLoc, RAngleLoc);
965 if (SS.getRange().isValid())
966 R.setBegin(SS.getRange().getBegin());
967
968 Diag(CCLoc, diag::err_non_type_template_in_nested_name_specifier)
969 << (TD && isa<VarTemplateDecl>(TD)) << Template << R;
970 NoteAllFoundTemplates(Template);
971 return true;
972 }
973
974 // We were able to resolve the template name to an actual template.
975 // Build an appropriate nested-name-specifier.
976 QualType T = CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
977 if (T.isNull())
978 return true;
979
980 // Alias template specializations can produce types which are not valid
981 // nested name specifiers.
982 if (!T->isDependentType() && !T->getAs<TagType>()) {
983 Diag(TemplateNameLoc, diag::err_nested_name_spec_non_tag) << T;
984 NoteAllFoundTemplates(Template);
985 return true;
986 }
987
988 // Provide source-location information for the template specialization type.
989 TypeLocBuilder Builder;
991 = Builder.push<TemplateSpecializationTypeLoc>(T);
992 SpecTL.setTemplateKeywordLoc(TemplateKWLoc);
993 SpecTL.setTemplateNameLoc(TemplateNameLoc);
994 SpecTL.setLAngleLoc(LAngleLoc);
995 SpecTL.setRAngleLoc(RAngleLoc);
996 for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
997 SpecTL.setArgLocInfo(I, TemplateArgs[I].getLocInfo());
998
999
1000 SS.Extend(Context, TemplateKWLoc, Builder.getTypeLocInContext(Context, T),
1001 CCLoc);
1002 return false;
1003}
1004
1005namespace {
1006 /// A structure that stores a nested-name-specifier annotation,
1007 /// including both the nested-name-specifier
1008 struct NestedNameSpecifierAnnotation {
1010 };
1011}
1012
1014 if (SS.isEmpty() || SS.isInvalid())
1015 return nullptr;
1016
1017 void *Mem = Context.Allocate(
1018 (sizeof(NestedNameSpecifierAnnotation) + SS.location_size()),
1019 alignof(NestedNameSpecifierAnnotation));
1020 NestedNameSpecifierAnnotation *Annotation
1021 = new (Mem) NestedNameSpecifierAnnotation;
1022 Annotation->NNS = SS.getScopeRep();
1023 memcpy(Annotation + 1, SS.location_data(), SS.location_size());
1024 return Annotation;
1025}
1026
1028 SourceRange AnnotationRange,
1029 CXXScopeSpec &SS) {
1030 if (!AnnotationPtr) {
1031 SS.SetInvalid(AnnotationRange);
1032 return;
1033 }
1034
1035 NestedNameSpecifierAnnotation *Annotation
1036 = static_cast<NestedNameSpecifierAnnotation *>(AnnotationPtr);
1037 SS.Adopt(NestedNameSpecifierLoc(Annotation->NNS, Annotation + 1));
1038}
1039
1041 assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
1042
1043 // Don't enter a declarator context when the current context is an Objective-C
1044 // declaration.
1045 if (isa<ObjCContainerDecl>(CurContext) || isa<ObjCMethodDecl>(CurContext))
1046 return false;
1047
1048 NestedNameSpecifier *Qualifier = SS.getScopeRep();
1049
1050 // There are only two places a well-formed program may qualify a
1051 // declarator: first, when defining a namespace or class member
1052 // out-of-line, and second, when naming an explicitly-qualified
1053 // friend function. The latter case is governed by
1054 // C++03 [basic.lookup.unqual]p10:
1055 // In a friend declaration naming a member function, a name used
1056 // in the function declarator and not part of a template-argument
1057 // in a template-id is first looked up in the scope of the member
1058 // function's class. If it is not found, or if the name is part of
1059 // a template-argument in a template-id, the look up is as
1060 // described for unqualified names in the definition of the class
1061 // granting friendship.
1062 // i.e. we don't push a scope unless it's a class member.
1063
1064 switch (Qualifier->getKind()) {
1068 // These are always namespace scopes. We never want to enter a
1069 // namespace scope from anything but a file context.
1071
1076 // These are never namespace scopes.
1077 return true;
1078 }
1079
1080 llvm_unreachable("Invalid NestedNameSpecifier::Kind!");
1081}
1082
1083/// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
1084/// scope or nested-name-specifier) is parsed, part of a declarator-id.
1085/// After this method is called, according to [C++ 3.4.3p3], names should be
1086/// looked up in the declarator-id's scope, until the declarator is parsed and
1087/// ActOnCXXExitDeclaratorScope is called.
1088/// The 'SS' should be a non-empty valid CXXScopeSpec.
1090 assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
1091
1092 if (SS.isInvalid()) return true;
1093
1094 DeclContext *DC = computeDeclContext(SS, true);
1095 if (!DC) return true;
1096
1097 // Before we enter a declarator's context, we need to make sure that
1098 // it is a complete declaration context.
1099 if (!DC->isDependentContext() && RequireCompleteDeclContext(SS, DC))
1100 return true;
1101
1103
1104 // Rebuild the nested name specifier for the new scope.
1105 if (DC->isDependentContext())
1107
1108 return false;
1109}
1110
1111/// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
1112/// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
1113/// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
1114/// Used to indicate that names should revert to being looked up in the
1115/// defining scope.
1117 assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
1118 if (SS.isInvalid())
1119 return;
1120 assert(!SS.isInvalid() && computeDeclContext(SS, true) &&
1121 "exiting declarator scope we never really entered");
1123}
Defines the clang::ASTContext interface.
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
static CXXRecordDecl * getCurrentInstantiationOf(QualType T, DeclContext *CurContext)
Find the current instantiation that associated with the given type.
enum clang::format::@1240::AnnotatingParser::Context::@327 ContextType
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
QualType getUsingType(const UsingShadowDecl *Found, QualType Underlying) const
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1068
QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier *NNS, const IdentifierInfo *Name, ArrayRef< TemplateArgumentLoc > Args) const
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2549
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2565
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:1575
const LangOptions & getLangOpts() const
Definition: ASTContext.h:770
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:713
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2053
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
bool hasAnyDependentBases() const
Determine whether this class has any dependent base classes which are not the current instantiation.
Definition: DeclCXX.cpp:566
unsigned getNumBases() const
Retrieves the number of base classes of this class.
Definition: DeclCXX.h:612
bool hasDefinition() const
Definition: DeclCXX.h:571
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:73
char * location_data() const
Retrieve the data associated with the source-location information.
Definition: DeclSpec.h:235
void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
Definition: DeclSpec.cpp:126
SourceLocation getLastQualifierNameLoc() const
Retrieve the location of the name in the last qualifier in this nested name specifier.
Definition: DeclSpec.cpp:145
SourceRange getRange() const
Definition: DeclSpec.h:79
void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc)
Turn this (empty) nested-name-specifier into the global nested-name-specifier '::'.
Definition: DeclSpec.cpp:104
bool isSet() const
Deprecated.
Definition: DeclSpec.h:227
ArrayRef< TemplateParameterList * > getTemplateParamLists() const
Definition: DeclSpec.h:89
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
Definition: DeclSpec.cpp:152
NestedNameSpecifier * getScopeRep() const
Retrieve the representation of the nested-name-specifier.
Definition: DeclSpec.h:94
void SetInvalid(SourceRange R)
Indicate that this nested-name-specifier is invalid.
Definition: DeclSpec.h:217
unsigned location_size() const
Retrieve the size of the data associated with source-location information.
Definition: DeclSpec.h:239
void MakeSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)
Turns this (empty) nested-name-specifier into '__super' nested-name-specifier.
Definition: DeclSpec.cpp:114
void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL, SourceLocation ColonColonLoc)
Extend the current nested-name-specifier by another nested-name-specifier component of the form 'type...
Definition: DeclSpec.cpp:54
bool isInvalid() const
An error occurred during parsing of the scope specifier.
Definition: DeclSpec.h:212
bool isEmpty() const
No scope specifier.
Definition: DeclSpec.h:207
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Definition: DeclSpec.cpp:132
Declaration of a class template.
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1436
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:2066
bool isFileContext() const
Definition: DeclBase.h:2136
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1260
bool isRecord() const
Definition: DeclBase.h:2145
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1915
bool isFunctionOrMethod() const
Definition: DeclBase.h:2118
Captures information about "declaration specifiers".
Definition: DeclSpec.h:246
TST getTypeSpecType() const
Definition: DeclSpec.h:533
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclSpec.h:571
static const TST TST_typename_pack_indexing
Definition: DeclSpec.h:312
SourceLocation getEllipsisLoc() const
Definition: DeclSpec.h:619
Expr * getRepAsExpr() const
Definition: DeclSpec.h:551
static const TST TST_decltype
Definition: DeclSpec.h:310
SourceLocation getTypeSpecTypeLoc() const
Definition: DeclSpec.h:578
static const TST TST_error
Definition: DeclSpec.h:324
SourceRange getTypeofParensRange() const
Definition: DeclSpec.h:588
SourceLocation getLocation() const
Definition: DeclBase.h:444
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:968
The name of a declaration.
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:2056
void setDecltypeLoc(SourceLocation Loc)
Definition: TypeLoc.h:2053
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:488
bool isIdentifier() const
Determine whether this template name refers to an identifier.
Definition: TemplateName.h:547
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:544
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
Definition: TemplateName.h:550
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:2441
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2461
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2429
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2485
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2477
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:2493
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:2469
Represents an enum.
Definition: Decl.h:3832
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition: Decl.h:4091
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition: Decl.cpp:4895
Wrapper for source info for enum types.
Definition: TypeLoc.h:749
static FixItHint CreateReplacement(CharSourceRange RemoveRange, StringRef Code)
Create a code modification hint that replaces the given source range with the given code string.
Definition: Diagnostic.h:134
bool isEditorPlaceholder() const
Return true if this identifier is an editor placeholder.
Wrapper for source info for injected class names of class templates.
Definition: TypeLoc.h:705
Represents the results of name lookup.
Definition: Lookup.h:46
LLVM_ATTRIBUTE_REINITIALIZES void clear()
Clears out any current state.
Definition: Lookup.h:600
DeclClass * getAsSingle() const
Definition: Lookup.h:553
void setContextRange(SourceRange SR)
Sets a 'context' source range.
Definition: Lookup.h:646
void addDecl(NamedDecl *D)
Add a declaration to these results with its natural access.
Definition: Lookup.h:472
void setLookupName(DeclarationName Name)
Sets the name to look up.
Definition: Lookup.h:268
bool empty() const
Return true if no decls were found.
Definition: Lookup.h:359
SourceLocation getNameLoc() const
Gets the location of the identifier.
Definition: Lookup.h:659
NamedDecl * getFoundDecl() const
Fetch the unique decl found by this lookup.
Definition: Lookup.h:563
bool isAmbiguous() const
Definition: Lookup.h:321
bool isSingleResult() const
Determines if this names a single result which is not an unresolved value using decl.
Definition: Lookup.h:328
Sema::LookupNameKind getLookupKind() const
Gets the kind of lookup to perform.
Definition: Lookup.h:273
NamedDecl * getRepresentativeDecl() const
Fetches a representative decl. Useful for lazy diagnostics.
Definition: Lookup.h:570
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
Definition: Lookup.h:629
DeclarationName getLookupName() const
Gets the name to look up.
Definition: Lookup.h:263
const DeclarationNameInfo & getLookupNameInfo() const
Gets the name info to look up.
Definition: Lookup.h:253
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:616
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
Definition: DeclTemplate.h:638
This represents a decl that may have a name.
Definition: Decl.h:249
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition: Decl.h:462
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:276
Represents a C++ namespace alias.
Definition: DeclCXX.h:3113
NamespaceDecl * getNamespace()
Retrieve the namespace declaration aliased by this directive.
Definition: DeclCXX.h:3185
Represent a C++ namespace.
Definition: Decl.h:547
A C++ nested-name-specifier augmented with source location information.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
CXXRecordDecl * getAsRecordDecl() const
Retrieve the record declaration stored in this nested name specifier.
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
SpecifierKind getKind() const
Determine what kind of nested name specifier is stored.
NamespaceAliasDecl * getAsNamespaceAlias() const
Retrieve the namespace alias stored in this nested name specifier.
IdentifierInfo * getAsIdentifier() const
Retrieve the identifier stored in this nested name specifier.
NestedNameSpecifier * getPrefix() const
Return the prefix of this nested name specifier.
@ NamespaceAlias
A namespace alias, stored as a NamespaceAliasDecl*.
@ TypeSpec
A type, stored as a Type*.
@ TypeSpecWithTemplate
A type that was preceded by the 'template' keyword, stored as a Type*.
@ Super
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Identifier
An identifier, stored as an IdentifierInfo*.
@ Global
The global specifier '::'. There is no stored value.
@ Namespace
A namespace, stored as a NamespaceDecl*.
NamespaceDecl * getAsNamespace() const
Retrieve the namespace stored in this nested name specifier.
const Type * getAsType() const
Retrieve the type stored in this nested name specifier.
PtrTy get() const
Definition: Ownership.h:80
void setEllipsisLoc(SourceLocation Loc)
Definition: TypeLoc.h:2081
A (possibly-)qualified type.
Definition: Type.h:737
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:804
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6901
Wrapper for source info for record types.
Definition: TypeLoc.h:741
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5091
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:41
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:425
bool hasReachableDefinition(NamedDecl *D, NamedDecl **Suggested, bool OnlyNeedComplete=false)
Determine if D has a reachable definition.
Definition: SemaType.cpp:9379
Scope * getCurScope() const
Retrieve the parser's current scope.
Definition: Sema.h:14344
NamedDecl * FindFirstQualifierInScope(Scope *S, NestedNameSpecifier *NNS)
If the given nested-name-specifier begins with a bare identifier (e.g., Base::), perform name lookup ...
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
Definition: Sema.h:4490
@ LookupNestedNameSpecifierName
Look up of a name that precedes the '::' scope resolution operator in C++.
Definition: Sema.h:4509
@ LookupNamespaceName
Look up a namespace name within a C++ using directive or namespace alias definition,...
Definition: Sema.h:4513
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: Sema.cpp:1924
void NoteAllFoundTemplates(TemplateName Name)
bool RequireCompleteDeclContext(CXXScopeSpec &SS, DeclContext *DC)
Require that the context specified by SS be complete.
bool ActOnCXXNestedNameSpecifierDecltype(CXXScopeSpec &SS, const DeclSpec &DS, SourceLocation ColonColonLoc)
ASTContext & Context
Definition: Sema.h:476
ASTContext & getASTContext() const
Definition: Sema.h:1801
void translateTemplateArguments(const ASTTemplateArgsPtr &In, TemplateArgumentListInfo &Out)
Translates template arguments as provided by the parser into template arguments used by semantic anal...
void * SaveNestedNameSpecifierAnnotation(CXXScopeSpec &SS)
Given a C++ nested-name-specifier, produce an annotation value that the parser can use later to recon...
bool RebuildNestedNameSpecifierInCurrentInstantiation(CXXScopeSpec &SS)
bool ActOnCXXGlobalScopeSpecifier(SourceLocation CCLoc, CXXScopeSpec &SS)
The parser has parsed a global nested-name-specifier '::'.
bool ActOnCXXNestedNameSpecifier(Scope *S, NestedNameSpecInfo &IdInfo, bool EnteringContext, CXXScopeSpec &SS, bool *IsCorrectedToColon=nullptr, bool OnlyNamespace=false)
The parser has parsed a nested-name-specifier 'identifier::'.
const LangOptions & getLangOpts() const
Definition: Sema.h:1794
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 ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS)
ActOnCXXExitDeclaratorScope - Called when a declarator that previously invoked ActOnCXXEnterDeclarato...
sema::LambdaScopeInfo * getCurLambda(bool IgnoreNonLambdaCapturingScope=false)
Retrieve the current lambda scope info, if any.
Definition: Sema.cpp:2388
bool ShouldEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS)
void MarkAnyDeclReferenced(SourceLocation Loc, Decl *D, bool MightBeOdrUse)
Perform marking for a reference to an arbitrary declaration.
Definition: SemaExpr.cpp:20819
bool ActOnSuperScopeSpecifier(SourceLocation SuperLoc, SourceLocation ColonColonLoc, CXXScopeSpec &SS)
The parser has parsed a '__super' nested-name-specifier.
bool RequireCompleteEnumDecl(EnumDecl *D, SourceLocation L, CXXScopeSpec *SS=nullptr)
Require that the EnumDecl is completed with its enumerators defined or instantiated.
void ExitDeclaratorContext(Scope *S)
Definition: SemaDecl.cpp:1390
CXXRecordDecl * getCurrentInstantiationOf(NestedNameSpecifier *NNS)
If the given nested name specifier refers to the current instantiation, return the declaration that c...
std::optional< sema::TemplateDeductionInfo * > isSFINAEContext() const
Determines whether we are currently in a context where template argument substitution failures are no...
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:489
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.
void RestoreNestedNameSpecifierAnnotation(void *Annotation, SourceRange AnnotationRange, CXXScopeSpec &SS)
Given an annotation pointer for a nested-name-specifier, restore the nested-name-specifier structure.
void EnterDeclaratorContext(Scope *S, DeclContext *DC)
EnterDeclaratorContext - Used when we must lookup names in the context of a declarator's nested name ...
Definition: SemaDecl.cpp:1355
bool ActOnCXXNestedNameSpecifierIndexedPack(CXXScopeSpec &SS, const DeclSpec &DS, SourceLocation ColonColonLoc, QualType Type)
DeclContext * computeDeclContext(QualType T)
Compute the DeclContext that is associated with the given type.
QualType CheckTemplateIdType(TemplateName Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &TemplateArgs)
void diagnoseMissingImport(SourceLocation Loc, const NamedDecl *Decl, MissingImportKind MIK, bool Recover=true)
Diagnose that the specified declaration needs to be visible but isn't, and suggest a module import th...
bool DiagnoseUseOfDecl(NamedDecl *D, ArrayRef< SourceLocation > Locs, const ObjCInterfaceDecl *UnknownObjCClass=nullptr, bool ObjCPropertyAccess=false, bool AvoidPartialAvailabilityChecks=false, ObjCInterfaceDecl *ClassReciever=nullptr, bool SkipTrailingRequiresClause=false)
Determine whether the use of this declaration is valid, and emit any corresponding diagnostics.
Definition: SemaExpr.cpp:224
@ CTK_ErrorRecovery
Definition: Sema.h:4728
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...
QualType BuildDecltypeType(Expr *E, bool AsUnevaluated=true)
If AsUnevaluated is false, E is treated as though it were an evaluated context, such as when building...
Definition: SemaType.cpp:9819
void diagnoseTypo(const TypoCorrection &Correction, const PartialDiagnostic &TypoDiag, bool ErrorRecovery=true)
bool RequireCompleteType(SourceLocation Loc, QualType T, CompleteTypeKind Kind, TypeDiagnoser &Diagnoser)
Ensure that the type T is a complete type.
Definition: SemaType.cpp:9240
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
Definition: SemaInternal.h:24
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
bool isDependentScopeSpecifier(const CXXScopeSpec &SS)
bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS)
ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global scope or nested-name-specifi...
bool resolveAssumedTemplateNameAsType(Scope *S, TemplateName &Name, SourceLocation NameLoc, bool Diagnose=true)
bool InstantiateEnum(SourceLocation PointOfInstantiation, EnumDecl *Instantiation, EnumDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateSpecializationKind TSK)
Instantiate the definition of an enum from a given pattern.
bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation=false, bool ForceNoCPlusPlus=false)
Perform unqualified name lookup starting from a given scope.
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
Definition: SemaType.cpp:3213
bool IsInvalidUnlessNestedName(Scope *S, CXXScopeSpec &SS, NestedNameSpecInfo &IdInfo, bool EnteringContext)
IsInvalidUnlessNestedName - This method is used for error recovery purposes to determine whether the ...
void DiagnoseUnknownTypeName(IdentifierInfo *&II, SourceLocation IILoc, Scope *S, CXXScopeSpec *SS, ParsedType &SuggestedType, bool IsTemplateName=false)
Definition: SemaDecl.cpp:696
MultiLevelTemplateArgumentList getTemplateInstantiationArgs(const NamedDecl *D, const DeclContext *DC=nullptr, bool Final=false, std::optional< ArrayRef< TemplateArgument > > Innermost=std::nullopt, bool RelativeToPrimary=false, const FunctionDecl *Pattern=nullptr, bool ForConstraintInstantiation=false, bool SkipForSpecialization=false)
Retrieve the template argument list(s) that should be used to instantiate the definition of the given...
Encodes a location in the source.
A trivial tuple used to represent a source range.
void setBegin(SourceLocation b)
SourceLocation getEnd() const
SourceLocation getBegin() const
bool isValid() const
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:864
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:857
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3549
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition: Decl.h:3672
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3652
TagDecl * getDecl() const
Definition: Type.cpp:3900
A convenient class for passing around template argument information.
Definition: TemplateBase.h:632
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:659
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:394
Represents a C++ template name within the type system.
Definition: TemplateName.h:202
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
OverloadedTemplateStorage * getAsOverloadedTemplate() const
Retrieve the underlying, overloaded function template declarations that this template name refers to,...
AssumedTemplateStorage * getAsAssumedTemplateName() const
Retrieve information on a name that has been assumed to be a template-name in order to permit a call ...
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:73
unsigned getDepth() const
Get the depth of this template parameter list in the set of template parameter lists.
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:1656
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1632
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:1673
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1640
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1648
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:5631
Wrapper for template type parameters.
Definition: TypeLoc.h:758
Represents a declaration of a type.
Definition: Decl.h:3357
const Type * getTypeForDecl() const
Definition: Decl.h:3381
TypeLoc getTypeLocInContext(ASTContext &Context, QualType T)
Copies the type-location information to the given AST context and returns a TypeLoc referring into th...
TyLocType push(QualType T)
Pushes space for a new TypeLoc of the given type.
TypeSpecTypeLoc pushTypeSpec(QualType T)
Pushes space for a typespec TypeLoc.
void pushTrivial(ASTContext &Context, QualType T, SourceLocation Loc)
Pushes 'T' with all locations pointing to 'Loc'.
void setNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:539
The base class of the type hierarchy.
Definition: Type.h:1606
bool isEnumeralType() const
Definition: Type.h:7247
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2419
QualType getCanonicalTypeInternal() const
Definition: Type.h:2702
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7652
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3399
Wrapper for source info for typedefs.
Definition: TypeLoc.h:693
Simple class containing the result of Sema::CorrectTypo.
NamedDecl * getCorrectionDecl() const
Gets the pointer to the declaration of the typo correction.
Wrapper for source info for unresolved typename using decls.
Definition: TypeLoc.h:716
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
The JSON file list parser is used to communicate input to InstallAPI.
@ CPlusPlus
Definition: LangStandard.h:54
@ CPlusPlus11
Definition: LangStandard.h:55
@ Result
The result type of a method or function.
@ TSK_ExplicitSpecialization
This template specialization was declared or defined by an explicit specialization (C++ [temp....
Definition: Specifiers.h:195
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
Definition: Specifiers.h:191
@ None
No keyword precedes the qualified type name.
Keeps information about an identifier in a nested-name-spec.
Definition: Sema.h:7199
IdentifierInfo * Identifier
The identifier preceding the '::'.
Definition: Sema.h:7205
SourceLocation IdentifierLoc
The location of the identifier.
Definition: Sema.h:7208
SourceLocation CCLoc
The location of the '::'.
Definition: Sema.h:7211
ParsedType ObjectType
The type of the object, if we're parsing nested-name-specifier in a member access expression.
Definition: Sema.h:7202