clang 22.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"
21#include "clang/Sema/Template.h"
22#include "llvm/ADT/STLExtras.h"
23using namespace clang;
24
25/// Find the current instantiation that associated with the given type.
27 DeclContext *CurContext) {
28 if (T.isNull())
29 return nullptr;
30
31 const TagType *TagTy = dyn_cast<TagType>(T->getCanonicalTypeInternal());
32 if (!isa_and_present<RecordType, InjectedClassNameType>(TagTy))
33 return nullptr;
34 auto *RD =
35 cast<CXXRecordDecl>(TagTy->getOriginalDecl())->getDefinitionOrSelf();
36 if (isa<InjectedClassNameType>(TagTy) ||
37 RD->isCurrentInstantiation(CurContext))
38 return RD;
39 return nullptr;
40}
41
43 if (!T->isDependentType())
44 if (auto *D = T->getAsTagDecl())
45 return D;
46 return ::getCurrentInstantiationOf(T, CurContext);
47}
48
50 bool EnteringContext) {
51 if (!SS.isSet() || SS.isInvalid())
52 return nullptr;
53
55 if (NNS.isDependent()) {
56 // If this nested-name-specifier refers to the current
57 // instantiation, return its DeclContext.
59 return Record;
60
61 if (EnteringContext) {
63 return nullptr;
64 const Type *NNSType = NNS.getAsType();
65
66 // Look through type alias templates, per C++0x [temp.dep.type]p1.
67 NNSType = Context.getCanonicalType(NNSType);
68 if (const auto *SpecType =
69 dyn_cast<TemplateSpecializationType>(NNSType)) {
70 // We are entering the context of the nested name specifier, so try to
71 // match the nested name specifier to either a primary class template
72 // or a class template partial specialization.
74 dyn_cast_or_null<ClassTemplateDecl>(
75 SpecType->getTemplateName().getAsTemplateDecl())) {
76 // FIXME: The fallback on the search of partial
77 // specialization using ContextType should be eventually removed since
78 // it doesn't handle the case of constrained template parameters
79 // correctly. Currently removing this fallback would change the
80 // diagnostic output for invalid code in a number of tests.
81 ClassTemplatePartialSpecializationDecl *PartialSpec = nullptr;
82 ArrayRef<TemplateParameterList *> TemplateParamLists =
84 if (!TemplateParamLists.empty()) {
85 unsigned Depth = ClassTemplate->getTemplateParameters()->getDepth();
86 auto L = find_if(TemplateParamLists,
87 [Depth](TemplateParameterList *TPL) {
88 return TPL->getDepth() == Depth;
89 });
90 if (L != TemplateParamLists.end()) {
91 void *Pos = nullptr;
92 PartialSpec = ClassTemplate->findPartialSpecialization(
93 SpecType->template_arguments(), *L, Pos);
94 }
95 } else {
96 PartialSpec =
97 ClassTemplate->findPartialSpecialization(QualType(SpecType, 0));
98 }
99
100 if (PartialSpec) {
101 // A declaration of the partial specialization must be visible.
102 // We can always recover here, because this only happens when we're
103 // entering the context, and that can't happen in a SFINAE context.
104 assert(!isSFINAEContext() && "partial specialization scope "
105 "specifier in SFINAE context?");
106 if (PartialSpec->hasDefinition() &&
107 !hasReachableDefinition(PartialSpec))
110 true);
111 return PartialSpec;
112 }
113
114 // If the type of the nested name specifier is the same as the
115 // injected class name of the named class template, we're entering
116 // into that class template definition.
117 CanQualType Injected =
118 ClassTemplate->getCanonicalInjectedSpecializationType(Context);
119 if (Context.hasSameType(Injected, QualType(SpecType, 0)))
120 return ClassTemplate->getTemplatedDecl();
121 }
122 } else if (const auto *RecordT = dyn_cast<RecordType>(NNSType)) {
123 // The nested name specifier refers to a member of a class template.
124 return RecordT->getOriginalDecl()->getDefinitionOrSelf();
125 }
126 }
127
128 return nullptr;
129 }
130
131 switch (NNS.getKind()) {
133 return const_cast<NamespaceDecl *>(
135
137 return NNS.getAsType()->castAsTagDecl();
138
141
143 return NNS.getAsMicrosoftSuper();
144
146 llvm_unreachable("unexpected null nested name specifier");
147 }
148
149 llvm_unreachable("Invalid NestedNameSpecifier::Kind!");
150}
151
153 if (!SS.isSet() || SS.isInvalid())
154 return false;
155
156 return SS.getScopeRep().isDependent();
157}
158
160 assert(getLangOpts().CPlusPlus && "Only callable in C++");
161 assert(NNS.isDependent() && "Only dependent nested-name-specifier allowed");
162
164 return nullptr;
165
166 QualType T = QualType(NNS.getAsType(), 0);
167 return ::getCurrentInstantiationOf(T, CurContext);
168}
169
170/// Require that the context specified by SS be complete.
171///
172/// If SS refers to a type, this routine checks whether the type is
173/// complete enough (or can be made complete enough) for name lookup
174/// into the DeclContext. A type that is not yet completed can be
175/// considered "complete enough" if it is a class/struct/union/enum
176/// that is currently being defined. Or, if we have a type that names
177/// a class template specialization that is not a complete type, we
178/// will attempt to instantiate that class template.
180 DeclContext *DC) {
181 assert(DC && "given null context");
182
183 TagDecl *tag = dyn_cast<TagDecl>(DC);
184
185 // If this is a dependent type, then we consider it complete.
186 // FIXME: This is wrong; we should require a (visible) definition to
187 // exist in this case too.
188 if (!tag || tag->isDependentContext())
189 return false;
190
191 // Grab the tag definition, if there is one.
192 tag = tag->getDefinitionOrSelf();
193
194 // If we're currently defining this type, then lookup into the
195 // type is okay: don't complain that it isn't complete yet.
196 if (tag->isBeingDefined())
197 return false;
198
200 if (loc.isInvalid()) loc = SS.getRange().getBegin();
201
202 // The type must be complete.
204 diag::err_incomplete_nested_name_spec,
205 SS.getRange())) {
206 SS.SetInvalid(SS.getRange());
207 return true;
208 }
209
210 if (auto *EnumD = dyn_cast<EnumDecl>(tag))
211 // Fixed enum types and scoped enum instantiations are complete, but they
212 // aren't valid as scopes until we see or instantiate their definition.
213 return RequireCompleteEnumDecl(EnumD, loc, &SS);
214
215 return false;
216}
217
218/// Require that the EnumDecl is completed with its enumerators defined or
219/// instantiated. SS, if provided, is the ScopeRef parsed.
220///
222 CXXScopeSpec *SS) {
223 if (EnumD->isCompleteDefinition()) {
224 // If we know about the definition but it is not visible, complain.
225 NamedDecl *SuggestedDef = nullptr;
226 if (!hasReachableDefinition(EnumD, &SuggestedDef,
227 /*OnlyNeedComplete*/ false)) {
228 // If the user is going to see an error here, recover by making the
229 // definition visible.
230 bool TreatAsComplete = !isSFINAEContext();
232 /*Recover*/ TreatAsComplete);
233 return !TreatAsComplete;
234 }
235 return false;
236 }
237
238 // Try to instantiate the definition, if this is a specialization of an
239 // enumeration temploid.
240 if (EnumDecl *Pattern = EnumD->getInstantiatedFromMemberEnum()) {
243 if (InstantiateEnum(L, EnumD, Pattern,
246 if (SS)
247 SS->SetInvalid(SS->getRange());
248 return true;
249 }
250 return false;
251 }
252 }
253
254 if (SS) {
255 Diag(L, diag::err_incomplete_nested_name_spec)
256 << Context.getCanonicalTagType(EnumD) << SS->getRange();
257 SS->SetInvalid(SS->getRange());
258 } else {
259 Diag(L, diag::err_incomplete_enum) << Context.getCanonicalTagType(EnumD);
260 Diag(EnumD->getLocation(), diag::note_declared_at);
261 }
262
263 return true;
264}
265
267 CXXScopeSpec &SS) {
268 SS.MakeGlobal(Context, CCLoc);
269 return false;
270}
271
273 SourceLocation ColonColonLoc,
274 CXXScopeSpec &SS) {
275 if (getCurLambda()) {
276 Diag(SuperLoc, diag::err_super_in_lambda_unsupported);
277 return true;
278 }
279
280 CXXRecordDecl *RD = nullptr;
281 for (Scope *S = getCurScope(); S; S = S->getParent()) {
282 if (S->isFunctionScope()) {
283 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(S->getEntity()))
284 RD = MD->getParent();
285 break;
286 }
287 if (S->isClassScope()) {
288 RD = cast<CXXRecordDecl>(S->getEntity());
289 break;
290 }
291 }
292
293 if (!RD) {
294 Diag(SuperLoc, diag::err_invalid_super_scope);
295 return true;
296 } else if (RD->getNumBases() == 0) {
297 Diag(SuperLoc, diag::err_no_base_classes) << RD->getName();
298 return true;
299 }
300
301 SS.MakeMicrosoftSuper(Context, RD, SuperLoc, ColonColonLoc);
302 return false;
303}
304
306 bool *IsExtension) {
307 if (!SD)
308 return false;
309
310 SD = SD->getUnderlyingDecl();
311
312 // Namespace and namespace aliases are fine.
313 if (isa<NamespaceDecl>(SD))
314 return true;
315
316 if (!isa<TypeDecl>(SD))
317 return false;
318
319 // Determine whether we have a class (or, in C++11, an enum) or
320 // a typedef thereof. If so, build the nested-name-specifier.
321 if (const TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(SD)) {
322 if (TD->getUnderlyingType()->isRecordType())
323 return true;
324 if (TD->getUnderlyingType()->isEnumeralType()) {
325 if (Context.getLangOpts().CPlusPlus11)
326 return true;
327 if (IsExtension)
328 *IsExtension = true;
329 }
330 } else if (isa<RecordDecl>(SD)) {
331 return true;
332 } else if (isa<EnumDecl>(SD)) {
333 if (Context.getLangOpts().CPlusPlus11)
334 return true;
335 if (IsExtension)
336 *IsExtension = true;
337 }
338 if (auto *TD = dyn_cast<TagDecl>(SD)) {
339 if (TD->isDependentType())
340 return true;
341 } else if (Context.getCanonicalTypeDeclType(cast<TypeDecl>(SD))
342 ->isDependentType()) {
343 return true;
344 }
345
346 return false;
347}
348
350 if (!S)
351 return nullptr;
352
354 const Type *T = NNS.getAsType();
355 if ((NNS = T->getPrefix()))
356 continue;
357
358 const auto *DNT = dyn_cast<DependentNameType>(T);
359 if (!DNT)
360 break;
361
362 LookupResult Found(*this, DNT->getIdentifier(), SourceLocation(),
364 LookupName(Found, S);
365 assert(!Found.isAmbiguous() && "Cannot handle ambiguities here yet");
366
367 if (!Found.isSingleResult())
368 return nullptr;
369
370 NamedDecl *Result = Found.getFoundDecl();
372 return Result;
373 }
374 return nullptr;
375}
376
377namespace {
378
379// Callback to only accept typo corrections that can be a valid C++ member
380// initializer: either a non-static field member or a base class.
381class NestedNameSpecifierValidatorCCC final
383public:
384 explicit NestedNameSpecifierValidatorCCC(Sema &SRef)
385 : SRef(SRef) {}
386
387 bool ValidateCandidate(const TypoCorrection &candidate) override {
388 return SRef.isAcceptableNestedNameSpecifier(candidate.getCorrectionDecl());
389 }
390
391 std::unique_ptr<CorrectionCandidateCallback> clone() override {
392 return std::make_unique<NestedNameSpecifierValidatorCCC>(*this);
393 }
394
395 private:
396 Sema &SRef;
397};
398
399}
400
402 bool EnteringContext, CXXScopeSpec &SS,
403 NamedDecl *ScopeLookupResult,
404 bool ErrorRecoveryLookup,
405 bool *IsCorrectedToColon,
406 bool OnlyNamespace) {
407 if (IdInfo.Identifier->isEditorPlaceholder())
408 return true;
409 LookupResult Found(*this, IdInfo.Identifier, IdInfo.IdentifierLoc,
410 OnlyNamespace ? LookupNamespaceName
412 QualType ObjectType = GetTypeFromParser(IdInfo.ObjectType);
413
414 // Determine where to perform name lookup
415 DeclContext *LookupCtx = nullptr;
416 bool isDependent = false;
417 if (IsCorrectedToColon)
418 *IsCorrectedToColon = false;
419 if (!ObjectType.isNull()) {
420 // This nested-name-specifier occurs in a member access expression, e.g.,
421 // x->B::f, and we are looking into the type of the object.
422 assert(!SS.isSet() && "ObjectType and scope specifier cannot coexist");
423 LookupCtx = computeDeclContext(ObjectType);
424 isDependent = ObjectType->isDependentType();
425 } else if (SS.isSet()) {
426 // This nested-name-specifier occurs after another nested-name-specifier,
427 // so look into the context associated with the prior nested-name-specifier.
428 LookupCtx = computeDeclContext(SS, EnteringContext);
429 isDependent = isDependentScopeSpecifier(SS);
430 Found.setContextRange(SS.getRange());
431 }
432
433 bool ObjectTypeSearchedInScope = false;
434 if (LookupCtx) {
435 // Perform "qualified" name lookup into the declaration context we
436 // computed, which is either the type of the base of a member access
437 // expression or the declaration context associated with a prior
438 // nested-name-specifier.
439
440 // The declaration context must be complete.
441 if (!LookupCtx->isDependentContext() &&
442 RequireCompleteDeclContext(SS, LookupCtx))
443 return true;
444
445 LookupQualifiedName(Found, LookupCtx);
446
447 if (!ObjectType.isNull() && Found.empty()) {
448 // C++ [basic.lookup.classref]p4:
449 // If the id-expression in a class member access is a qualified-id of
450 // the form
451 //
452 // class-name-or-namespace-name::...
453 //
454 // the class-name-or-namespace-name following the . or -> operator is
455 // looked up both in the context of the entire postfix-expression and in
456 // the scope of the class of the object expression. If the name is found
457 // only in the scope of the class of the object expression, the name
458 // shall refer to a class-name. If the name is found only in the
459 // context of the entire postfix-expression, the name shall refer to a
460 // class-name or namespace-name. [...]
461 //
462 // Qualified name lookup into a class will not find a namespace-name,
463 // so we do not need to diagnose that case specifically. However,
464 // this qualified name lookup may find nothing. In that case, perform
465 // unqualified name lookup in the given scope (if available) or
466 // reconstruct the result from when name lookup was performed at template
467 // definition time.
468 if (S)
469 LookupName(Found, S);
470 else if (ScopeLookupResult)
471 Found.addDecl(ScopeLookupResult);
472
473 ObjectTypeSearchedInScope = true;
474 }
475 } else if (!isDependent) {
476 // Perform unqualified name lookup in the current scope.
477 LookupName(Found, S);
478 }
479
480 if (Found.isAmbiguous())
481 return true;
482
483 // If we performed lookup into a dependent context and did not find anything,
484 // that's fine: just build a dependent nested-name-specifier.
485 if (Found.empty() && isDependent &&
486 !(LookupCtx && LookupCtx->isRecord() &&
487 (!cast<CXXRecordDecl>(LookupCtx)->hasDefinition() ||
488 !cast<CXXRecordDecl>(LookupCtx)->hasAnyDependentBases()))) {
489 // Don't speculate if we're just trying to improve error recovery.
490 if (ErrorRecoveryLookup)
491 return true;
492
493 // We were not able to compute the declaration context for a dependent
494 // base object type or prior nested-name-specifier, so this
495 // nested-name-specifier refers to an unknown specialization. Just build
496 // a dependent nested-name-specifier.
497
498 TypeLocBuilder TLB;
499
502 auto DTNL = TLB.push<DependentNameTypeLoc>(DTN);
504 DTNL.setNameLoc(IdInfo.IdentifierLoc);
505 DTNL.setQualifierLoc(SS.getWithLocInContext(Context));
506
507 SS.clear();
508 SS.Make(Context, TLB.getTypeLocInContext(Context, DTN), IdInfo.CCLoc);
509 return false;
510 }
511
512 if (Found.empty() && !ErrorRecoveryLookup) {
513 // If identifier is not found as class-name-or-namespace-name, but is found
514 // as other entity, don't look for typos.
515 LookupResult R(*this, Found.getLookupNameInfo(), LookupOrdinaryName);
516 if (LookupCtx)
517 LookupQualifiedName(R, LookupCtx);
518 else if (S && !isDependent)
519 LookupName(R, S);
520 if (!R.empty()) {
521 // Don't diagnose problems with this speculative lookup.
523 // The identifier is found in ordinary lookup. If correction to colon is
524 // allowed, suggest replacement to ':'.
525 if (IsCorrectedToColon) {
526 *IsCorrectedToColon = true;
527 Diag(IdInfo.CCLoc, diag::err_nested_name_spec_is_not_class)
528 << IdInfo.Identifier << getLangOpts().CPlusPlus
529 << FixItHint::CreateReplacement(IdInfo.CCLoc, ":");
530 if (NamedDecl *ND = R.getAsSingle<NamedDecl>())
531 Diag(ND->getLocation(), diag::note_declared_at);
532 return true;
533 }
534 // Replacement '::' -> ':' is not allowed, just issue respective error.
535 Diag(R.getNameLoc(), OnlyNamespace
536 ? unsigned(diag::err_expected_namespace_name)
537 : unsigned(diag::err_expected_class_or_namespace))
538 << IdInfo.Identifier << getLangOpts().CPlusPlus;
539 if (NamedDecl *ND = R.getAsSingle<NamedDecl>())
540 Diag(ND->getLocation(), diag::note_entity_declared_at)
541 << IdInfo.Identifier;
542 return true;
543 }
544 }
545
546 if (Found.empty() && !ErrorRecoveryLookup && !getLangOpts().MSVCCompat) {
547 // We haven't found anything, and we're not recovering from a
548 // different kind of error, so look for typos.
549 DeclarationName Name = Found.getLookupName();
550 Found.clear();
551 NestedNameSpecifierValidatorCCC CCC(*this);
552 if (TypoCorrection Corrected = CorrectTypo(
553 Found.getLookupNameInfo(), Found.getLookupKind(), S, &SS, CCC,
554 CorrectTypoKind::ErrorRecovery, LookupCtx, EnteringContext)) {
555 if (LookupCtx) {
556 bool DroppedSpecifier =
557 Corrected.WillReplaceSpecifier() &&
558 Name.getAsString() == Corrected.getAsString(getLangOpts());
559 if (DroppedSpecifier)
560 SS.clear();
561 diagnoseTypo(Corrected, PDiag(diag::err_no_member_suggest)
562 << Name << LookupCtx << DroppedSpecifier
563 << SS.getRange());
564 } else
565 diagnoseTypo(Corrected, PDiag(diag::err_undeclared_var_use_suggest)
566 << Name);
567
568 if (Corrected.getCorrectionSpecifier())
569 SS.MakeTrivial(Context, Corrected.getCorrectionSpecifier(),
570 SourceRange(Found.getNameLoc()));
571
572 if (NamedDecl *ND = Corrected.getFoundDecl())
573 Found.addDecl(ND);
574 Found.setLookupName(Corrected.getCorrection());
575 } else {
576 Found.setLookupName(IdInfo.Identifier);
577 }
578 }
579
580 NamedDecl *SD =
581 Found.isSingleResult() ? Found.getRepresentativeDecl() : nullptr;
582 bool IsExtension = false;
583 bool AcceptSpec = isAcceptableNestedNameSpecifier(SD, &IsExtension);
584 if (!AcceptSpec && IsExtension) {
585 AcceptSpec = true;
586 Diag(IdInfo.IdentifierLoc, diag::ext_nested_name_spec_is_enum);
587 }
588 if (AcceptSpec) {
589 if (!ObjectType.isNull() && !ObjectTypeSearchedInScope &&
591 // C++03 [basic.lookup.classref]p4:
592 // [...] If the name is found in both contexts, the
593 // class-name-or-namespace-name shall refer to the same entity.
594 //
595 // We already found the name in the scope of the object. Now, look
596 // into the current scope (the scope of the postfix-expression) to
597 // see if we can find the same name there. As above, if there is no
598 // scope, reconstruct the result from the template instantiation itself.
599 //
600 // Note that C++11 does *not* perform this redundant lookup.
601 NamedDecl *OuterDecl;
602 if (S) {
603 LookupResult FoundOuter(*this, IdInfo.Identifier, IdInfo.IdentifierLoc,
605 LookupName(FoundOuter, S);
606 OuterDecl = FoundOuter.getAsSingle<NamedDecl>();
607 } else
608 OuterDecl = ScopeLookupResult;
609
610 if (isAcceptableNestedNameSpecifier(OuterDecl) &&
611 OuterDecl->getCanonicalDecl() != SD->getCanonicalDecl() &&
612 (!isa<TypeDecl>(OuterDecl) || !isa<TypeDecl>(SD) ||
614 Context.getCanonicalTypeDeclType(cast<TypeDecl>(OuterDecl)),
615 Context.getCanonicalTypeDeclType(cast<TypeDecl>(SD))))) {
616 if (ErrorRecoveryLookup)
617 return true;
618
619 Diag(IdInfo.IdentifierLoc,
620 diag::err_nested_name_member_ref_lookup_ambiguous)
621 << IdInfo.Identifier;
622 Diag(SD->getLocation(), diag::note_ambig_member_ref_object_type)
623 << ObjectType;
624 Diag(OuterDecl->getLocation(), diag::note_ambig_member_ref_scope);
625
626 // Fall through so that we'll pick the name we found in the object
627 // type, since that's probably what the user wanted anyway.
628 }
629 }
630
631 if (auto *TD = dyn_cast_or_null<TypedefNameDecl>(SD))
632 MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
633
634 // If we're just performing this lookup for error-recovery purposes,
635 // don't extend the nested-name-specifier. Just return now.
636 if (ErrorRecoveryLookup)
637 return false;
638
639 // The use of a nested name specifier may trigger deprecation warnings.
640 DiagnoseUseOfDecl(SD, IdInfo.CCLoc);
641
642 if (NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(SD)) {
643 SS.Extend(Context, Namespace, IdInfo.IdentifierLoc, IdInfo.CCLoc);
644 return false;
645 }
646
647 if (NamespaceAliasDecl *Alias = dyn_cast<NamespaceAliasDecl>(SD)) {
648 SS.Extend(Context, Alias, IdInfo.IdentifierLoc, IdInfo.CCLoc);
649 return false;
650 }
651
652 const auto *TD = cast<TypeDecl>(SD->getUnderlyingDecl());
653 if (isa<EnumDecl>(TD))
654 Diag(IdInfo.IdentifierLoc, diag::warn_cxx98_compat_enum_nested_name_spec);
655
656 QualType T;
657 TypeLocBuilder TLB;
658 if (const auto *USD = dyn_cast<UsingShadowDecl>(SD)) {
660 USD);
661 TLB.push<UsingTypeLoc>(T).set(/*ElaboratedKeywordLoc=*/SourceLocation(),
663 IdInfo.IdentifierLoc);
664 } else if (const auto *Tag = dyn_cast<TagDecl>(TD)) {
666 /*OwnsTag=*/false);
667 auto TTL = TLB.push<TagTypeLoc>(T);
669 TTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
670 TTL.setNameLoc(IdInfo.IdentifierLoc);
671 } else if (auto *TN = dyn_cast<TypedefNameDecl>(TD)) {
673 TN);
674 TLB.push<TypedefTypeLoc>(T).set(/*ElaboratedKeywordLoc=*/SourceLocation(),
676 IdInfo.IdentifierLoc);
677 } else if (auto *UD = dyn_cast<UnresolvedUsingTypenameDecl>(TD)) {
679 SS.getScopeRep(), UD);
680 TLB.push<UnresolvedUsingTypeLoc>(T).set(
681 /*ElaboratedKeywordLoc=*/SourceLocation(),
683 } else {
684 assert(SS.isEmpty());
687 }
688 SS.clear();
689 SS.Make(Context, TLB.getTypeLocInContext(Context, T), IdInfo.CCLoc);
690 return false;
691 }
692
693 // Otherwise, we have an error case. If we don't want diagnostics, just
694 // return an error now.
695 if (ErrorRecoveryLookup)
696 return true;
697
698 // If we didn't find anything during our lookup, try again with
699 // ordinary name lookup, which can help us produce better error
700 // messages.
701 if (Found.empty()) {
703 LookupName(Found, S);
704 }
705
706 // In Microsoft mode, if we are within a templated function and we can't
707 // resolve Identifier, then extend the SS with Identifier. This will have
708 // the effect of resolving Identifier during template instantiation.
709 // The goal is to be able to resolve a function call whose
710 // nested-name-specifier is located inside a dependent base class.
711 // Example:
712 //
713 // class C {
714 // public:
715 // static void foo2() { }
716 // };
717 // template <class T> class A { public: typedef C D; };
718 //
719 // template <class T> class B : public A<T> {
720 // public:
721 // void foo() { D::foo2(); }
722 // };
723 if (getLangOpts().MSVCCompat) {
724 DeclContext *DC = LookupCtx ? LookupCtx : CurContext;
725 if (DC->isDependentContext() && DC->isFunctionOrMethod()) {
726 CXXRecordDecl *ContainingClass = dyn_cast<CXXRecordDecl>(DC->getParent());
727 if (ContainingClass && ContainingClass->hasAnyDependentBases()) {
728 Diag(IdInfo.IdentifierLoc,
729 diag::ext_undeclared_unqual_id_with_dependent_base)
730 << IdInfo.Identifier << ContainingClass;
731
732 TypeLocBuilder TLB;
733
734 // Fake up a nested-name-specifier that starts with the
735 // injected-class-name of the enclosing class.
736 // FIXME: This should be done as part of an adjustment, so that this
737 // doesn't get confused with something written in source.
740 ContainingClass, /*OwnsTag=*/false);
741 auto TTL = TLB.push<TagTypeLoc>(Result);
743 TTL.setQualifierLoc(SS.getWithLocInContext(Context));
744 TTL.setNameLoc(IdInfo.IdentifierLoc);
747
748 TLB.clear();
749
750 // Form a DependentNameType.
753 auto DTNL = TLB.push<DependentNameTypeLoc>(DTN);
755 DTNL.setNameLoc(IdInfo.IdentifierLoc);
756 DTNL.setQualifierLoc(SS.getWithLocInContext(Context));
757 SS.clear();
758 SS.Make(Context, TLB.getTypeLocInContext(Context, DTN), IdInfo.CCLoc);
759 return false;
760 }
761 }
762 }
763
764 if (!Found.empty()) {
765 if (TypeDecl *TD = Found.getAsSingle<TypeDecl>()) {
766 QualType T;
767 if (auto *TN = dyn_cast<TypedefNameDecl>(TD)) {
769 SS.getScopeRep(), TN);
770 } else {
771 // FIXME: Enumerate the possibilities here.
772 assert(!isa<TagDecl>(TD));
773 assert(SS.isEmpty());
775 }
776
777 Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace)
778 << T << getLangOpts().CPlusPlus;
779 } else if (Found.getAsSingle<TemplateDecl>()) {
780 ParsedType SuggestedType;
781 DiagnoseUnknownTypeName(IdInfo.Identifier, IdInfo.IdentifierLoc, S, &SS,
782 SuggestedType);
783 } else {
784 Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace)
785 << IdInfo.Identifier << getLangOpts().CPlusPlus;
786 if (NamedDecl *ND = Found.getAsSingle<NamedDecl>())
787 Diag(ND->getLocation(), diag::note_entity_declared_at)
788 << IdInfo.Identifier;
789 }
790 } else if (SS.isSet())
791 Diag(IdInfo.IdentifierLoc, diag::err_no_member) << IdInfo.Identifier
792 << LookupCtx << SS.getRange();
793 else
794 Diag(IdInfo.IdentifierLoc, diag::err_undeclared_var_use)
795 << IdInfo.Identifier;
796
797 return true;
798}
799
801 bool EnteringContext, CXXScopeSpec &SS,
802 bool *IsCorrectedToColon,
803 bool OnlyNamespace) {
804 if (SS.isInvalid())
805 return true;
806
807 return BuildCXXNestedNameSpecifier(S, IdInfo, EnteringContext, SS,
808 /*ScopeLookupResult=*/nullptr, false,
809 IsCorrectedToColon, OnlyNamespace);
810}
811
813 const DeclSpec &DS,
814 SourceLocation ColonColonLoc) {
816 return true;
817
819
821 if (T.isNull())
822 return true;
823
824 if (!T->isDependentType() && !isa<TagType>(T.getCanonicalType())) {
825 Diag(DS.getTypeSpecTypeLoc(), diag::err_expected_class_or_namespace)
826 << T << getLangOpts().CPlusPlus;
827 return true;
828 }
829
830 assert(SS.isEmpty());
831
832 TypeLocBuilder TLB;
833 DecltypeTypeLoc DecltypeTL = TLB.push<DecltypeTypeLoc>(T);
834 DecltypeTL.setDecltypeLoc(DS.getTypeSpecTypeLoc());
835 DecltypeTL.setRParenLoc(DS.getTypeofParensRange().getEnd());
836 SS.Make(Context, TLB.getTypeLocInContext(Context, T), ColonColonLoc);
837 return false;
838}
839
841 const DeclSpec &DS,
842 SourceLocation ColonColonLoc,
843 QualType Type) {
845 return true;
846
848
849 if (Type.isNull())
850 return true;
851
852 assert(SS.isEmpty());
853
854 TypeLocBuilder TLB;
856 cast<PackIndexingType>(Type.getTypePtr())->getPattern(),
857 DS.getBeginLoc());
860 SS.Make(Context, TLB.getTypeLocInContext(Context, Type), ColonColonLoc);
861 return false;
862}
863
865 NestedNameSpecInfo &IdInfo,
866 bool EnteringContext) {
867 if (SS.isInvalid())
868 return false;
869
870 return !BuildCXXNestedNameSpecifier(S, IdInfo, EnteringContext, SS,
871 /*ScopeLookupResult=*/nullptr, true);
872}
873
875 CXXScopeSpec &SS,
876 SourceLocation TemplateKWLoc,
877 TemplateTy OpaqueTemplate,
878 SourceLocation TemplateNameLoc,
879 SourceLocation LAngleLoc,
880 ASTTemplateArgsPtr TemplateArgsIn,
881 SourceLocation RAngleLoc,
882 SourceLocation CCLoc,
883 bool EnteringContext) {
884 if (SS.isInvalid())
885 return true;
886
887 TemplateName Template = OpaqueTemplate.get();
888
889 // Translate the parser's template argument list in our AST format.
890 TemplateArgumentListInfo TemplateArgs(LAngleLoc, RAngleLoc);
891 translateTemplateArguments(TemplateArgsIn, TemplateArgs);
892
893 DependentTemplateName *DTN = Template.getAsDependentTemplateName();
894 if (DTN && DTN->getName().getIdentifier()) {
895 // Handle a dependent template specialization for which we cannot resolve
896 // the template name.
897 assert(DTN->getQualifier() == SS.getScopeRep());
900 {SS.getScopeRep(), DTN->getName().getIdentifier(),
901 TemplateKWLoc.isValid()},
902 TemplateArgs.arguments());
903
904 // Create source-location information for this type.
905 TypeLocBuilder Builder;
910 SpecTL.setTemplateKeywordLoc(TemplateKWLoc);
911 SpecTL.setTemplateNameLoc(TemplateNameLoc);
912 SpecTL.setLAngleLoc(LAngleLoc);
913 SpecTL.setRAngleLoc(RAngleLoc);
914 for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
915 SpecTL.setArgLocInfo(I, TemplateArgs[I].getLocInfo());
916
917 SS.clear();
918 SS.Make(Context, Builder.getTypeLocInContext(Context, T), CCLoc);
919 return false;
920 }
921
922 // If we assumed an undeclared identifier was a template name, try to
923 // typo-correct it now.
924 if (Template.getAsAssumedTemplateName() &&
925 resolveAssumedTemplateNameAsType(S, Template, TemplateNameLoc))
926 return true;
927
928 TemplateDecl *TD = Template.getAsTemplateDecl();
929 if (Template.getAsOverloadedTemplate() || DTN ||
930 isa<FunctionTemplateDecl>(TD) || isa<VarTemplateDecl>(TD)) {
931 SourceRange R(TemplateNameLoc, RAngleLoc);
932 if (SS.getRange().isValid())
933 R.setBegin(SS.getRange().getBegin());
934
935 Diag(CCLoc, diag::err_non_type_template_in_nested_name_specifier)
936 << isa_and_nonnull<VarTemplateDecl>(TD) << Template << R;
938 return true;
939 }
940
941 // We were able to resolve the template name to an actual template.
942 // Build an appropriate nested-name-specifier.
944 TemplateNameLoc, TemplateArgs);
945 if (T.isNull())
946 return true;
947
948 // Alias template specializations can produce types which are not valid
949 // nested name specifiers.
950 if (!T->isDependentType() && !isa<TagType>(T.getCanonicalType())) {
951 Diag(TemplateNameLoc, diag::err_nested_name_spec_non_tag) << T;
953 return true;
954 }
955
956 // Provide source-location information for the template specialization type.
957 TypeLocBuilder TLB;
959 /*ElaboratedKeywordLoc=*/SourceLocation(),
960 SS.getWithLocInContext(Context), TemplateKWLoc, TemplateNameLoc,
961 TemplateArgs);
962
963 SS.clear();
964 SS.Make(Context, TLB.getTypeLocInContext(Context, T), CCLoc);
965 return false;
966}
967
968namespace {
969 /// A structure that stores a nested-name-specifier annotation,
970 /// including both the nested-name-specifier
971 struct NestedNameSpecifierAnnotation {
972 NestedNameSpecifier NNS = std::nullopt;
973 };
974}
975
977 if (SS.isEmpty() || SS.isInvalid())
978 return nullptr;
979
980 void *Mem = Context.Allocate(
981 (sizeof(NestedNameSpecifierAnnotation) + SS.location_size()),
982 alignof(NestedNameSpecifierAnnotation));
983 NestedNameSpecifierAnnotation *Annotation
984 = new (Mem) NestedNameSpecifierAnnotation;
985 Annotation->NNS = SS.getScopeRep();
986 memcpy(Annotation + 1, SS.location_data(), SS.location_size());
987 return Annotation;
988}
989
991 SourceRange AnnotationRange,
992 CXXScopeSpec &SS) {
993 if (!AnnotationPtr) {
994 SS.SetInvalid(AnnotationRange);
995 return;
996 }
997
998 NestedNameSpecifierAnnotation *Annotation
999 = static_cast<NestedNameSpecifierAnnotation *>(AnnotationPtr);
1000 SS.Adopt(NestedNameSpecifierLoc(Annotation->NNS, Annotation + 1));
1001}
1002
1004 assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
1005
1006 // Don't enter a declarator context when the current context is an Objective-C
1007 // declaration.
1008 if (isa<ObjCContainerDecl>(CurContext) || isa<ObjCMethodDecl>(CurContext))
1009 return false;
1010
1011 // There are only two places a well-formed program may qualify a
1012 // declarator: first, when defining a namespace or class member
1013 // out-of-line, and second, when naming an explicitly-qualified
1014 // friend function. The latter case is governed by
1015 // C++03 [basic.lookup.unqual]p10:
1016 // In a friend declaration naming a member function, a name used
1017 // in the function declarator and not part of a template-argument
1018 // in a template-id is first looked up in the scope of the member
1019 // function's class. If it is not found, or if the name is part of
1020 // a template-argument in a template-id, the look up is as
1021 // described for unqualified names in the definition of the class
1022 // granting friendship.
1023 // i.e. we don't push a scope unless it's a class member.
1024
1025 switch (SS.getScopeRep().getKind()) {
1028 // These are always namespace scopes. We never want to enter a
1029 // namespace scope from anything but a file context.
1031
1034 // These are never namespace scopes.
1035 return true;
1036
1038 llvm_unreachable("unexpected null nested name specifier");
1039 }
1040
1041 llvm_unreachable("Invalid NestedNameSpecifier::Kind!");
1042}
1043
1045 assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
1046
1047 if (SS.isInvalid()) return true;
1048
1049 DeclContext *DC = computeDeclContext(SS, true);
1050 if (!DC) return true;
1051
1052 // Before we enter a declarator's context, we need to make sure that
1053 // it is a complete declaration context.
1054 if (!DC->isDependentContext() && RequireCompleteDeclContext(SS, DC))
1055 return true;
1056
1058
1059 // Rebuild the nested name specifier for the new scope.
1060 if (DC->isDependentContext())
1062
1063 return false;
1064}
1065
1067 assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
1068 if (SS.isInvalid())
1069 return;
1070 assert(!SS.isInvalid() && computeDeclContext(SS, true) &&
1071 "exiting declarator scope we never really entered");
1073}
Defines the clang::ASTContext interface.
const Decl * D
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
llvm::MachO::Record Record
Definition: MachO.h:31
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.
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1201
QualType getDependentTemplateSpecializationType(ElaboratedTypeKeyword Keyword, const DependentTemplateStorage &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:2851
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2867
QualType getUsingType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const UsingShadowDecl *D, QualType UnderlyingType=QualType()) const
const LangOptions & getLangOpts() const
Definition: ASTContext.h:894
QualType getDependentNameType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier NNS, const IdentifierInfo *Name) const
QualType getTypeDeclType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TypeDecl *Decl) const
CanQualType getCanonicalTypeDeclType(const TypeDecl *TD) const
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:814
QualType getTypedefType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TypedefNameDecl *Decl, QualType UnderlyingType=QualType(), std::optional< bool > TypeMatchesDeclOrNone=std::nullopt) const
Return the unique reference to the type for the specified typedef-name decl.
QualType getTagType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const TagDecl *TD, bool OwnsTag) const
QualType getUnresolvedUsingType(ElaboratedTypeKeyword Keyword, NestedNameSpecifier Qualifier, const UnresolvedUsingTypenameDecl *D) const
CanQualType getCanonicalTagType(const TagDecl *TD) const
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2129
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:600
unsigned getNumBases() const
Retrieves the number of base classes of this class.
Definition: DeclCXX.h:602
bool hasDefinition() const
Definition: DeclCXX.h:561
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:73
void Make(ASTContext &Context, TypeLoc TL, SourceLocation ColonColonLoc)
Make a nested-name-specifier of the form 'type::'.
Definition: DeclSpec.cpp:51
char * location_data() const
Retrieve the data associated with the source-location information.
Definition: DeclSpec.h:206
SourceLocation getLastQualifierNameLoc() const
Retrieve the location of the name in the last qualifier in this nested name specifier.
Definition: DeclSpec.cpp:116
void MakeTrivial(ASTContext &Context, NestedNameSpecifier Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
Definition: DeclSpec.cpp:97
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:75
bool isSet() const
Deprecated.
Definition: DeclSpec.h:198
ArrayRef< TemplateParameterList * > getTemplateParamLists() const
Definition: DeclSpec.h:89
NestedNameSpecifier getScopeRep() const
Retrieve the representation of the nested-name-specifier.
Definition: DeclSpec.h:94
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
Definition: DeclSpec.cpp:123
void SetInvalid(SourceRange R)
Indicate that this nested-name-specifier is invalid.
Definition: DeclSpec.h:188
unsigned location_size() const
Retrieve the size of the data associated with source-location information.
Definition: DeclSpec.h:210
void Extend(ASTContext &Context, NamespaceBaseDecl *Namespace, SourceLocation NamespaceLoc, SourceLocation ColonColonLoc)
Extend the current nested-name-specifier by another nested-name-specifier component of the form 'name...
Definition: DeclSpec.cpp:62
bool isInvalid() const
An error occurred during parsing of the scope specifier.
Definition: DeclSpec.h:183
void MakeMicrosoftSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)
Turns this (empty) nested-name-specifier into '__super' nested-name-specifier.
Definition: DeclSpec.cpp:85
bool isEmpty() const
No scope specifier.
Definition: DeclSpec.h:178
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Definition: DeclSpec.cpp:103
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:1449
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:2109
bool isFileContext() const
Definition: DeclBase.h:2180
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1358
bool isRecord() const
Definition: DeclBase.h:2189
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:2022
bool isFunctionOrMethod() const
Definition: DeclBase.h:2161
Captures information about "declaration specifiers".
Definition: DeclSpec.h:217
TST getTypeSpecType() const
Definition: DeclSpec.h:507
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclSpec.h:545
static const TST TST_typename_pack_indexing
Definition: DeclSpec.h:283
SourceLocation getEllipsisLoc() const
Definition: DeclSpec.h:593
Expr * getRepAsExpr() const
Definition: DeclSpec.h:525
static const TST TST_decltype
Definition: DeclSpec.h:281
SourceLocation getTypeSpecTypeLoc() const
Definition: DeclSpec.h:552
static const TST TST_error
Definition: DeclSpec.h:298
SourceRange getTypeofParensRange() const
Definition: DeclSpec.h:562
SourceLocation getLocation() const
Definition: DeclBase.h:439
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:978
The name of a declaration.
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:2271
void setDecltypeLoc(SourceLocation Loc)
Definition: TypeLoc.h:2268
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2561
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:2631
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2651
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2618
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2675
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2667
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:2683
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:2659
IdentifierOrOverloadedOperator getName() const
Definition: TemplateName.h:609
NestedNameSpecifier getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:607
Represents an enum.
Definition: Decl.h:4004
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition: Decl.h:4267
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition: Decl.cpp:5033
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:139
bool isEditorPlaceholder() const
Return true if this identifier is an editor placeholder.
Represents the results of name lookup.
Definition: Lookup.h:147
DeclClass * getAsSingle() const
Definition: Lookup.h:558
bool empty() const
Return true if no decls were found.
Definition: Lookup.h:362
SourceLocation getNameLoc() const
Gets the location of the identifier.
Definition: Lookup.h:666
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
Definition: Lookup.h:636
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:614
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
Definition: DeclTemplate.h:636
This represents a decl that may have a name.
Definition: Decl.h:273
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition: Decl.h:486
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:300
Represents a C++ namespace alias.
Definition: DeclCXX.h:3195
NamespaceDecl * getNamespace()
Definition: DeclCXX.cpp:3222
Represent a C++ namespace.
Definition: Decl.h:591
A C++ nested-name-specifier augmented with source location information.
Represents a C++ nested name specifier, such as "\::std::vector<int>::".
CXXRecordDecl * getAsMicrosoftSuper() const
NamespaceAndPrefix getAsNamespaceAndPrefix() const
bool isDependent() const
Whether this nested name specifier refers to a dependent type or not.
@ MicrosoftSuper
Microsoft's '__super' specifier, stored as a CXXRecordDecl* of the class it appeared in.
@ Global
The global specifier '::'. There is no stored value.
@ Type
A type, stored as a Type*.
@ Namespace
A namespace-like entity, stored as a NamespaceBaseDecl*.
PtrTy get() const
Definition: Ownership.h:81
void setEllipsisLoc(SourceLocation Loc)
Definition: TypeLoc.h:2296
A (possibly-)qualified type.
Definition: TypeBase.h:937
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: TypeBase.h:1004
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:41
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: SemaBase.cpp:61
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
Definition: SemaBase.cpp:33
Sema & SemaRef
Definition: SemaBase.h:40
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:850
bool hasReachableDefinition(NamedDecl *D, NamedDecl **Suggested, bool OnlyNeedComplete=false)
Determine if D has a reachable definition.
Definition: SemaType.cpp:9378
Scope * getCurScope() const
Retrieve the parser's current scope.
Definition: Sema.h:1113
@ LookupOrdinaryName
Ordinary name lookup, which finds ordinary names (functions, variables, typedefs, etc....
Definition: Sema.h:9281
@ LookupNestedNameSpecifierName
Look up of a name that precedes the '::' scope resolution operator in C++.
Definition: Sema.h:9300
@ LookupNamespaceName
Look up a namespace name within a C++ using directive or namespace alias definition,...
Definition: Sema.h:9304
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)
QualType CheckTemplateIdType(ElaboratedTypeKeyword Keyword, TemplateName Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &TemplateArgs)
ASTContext & Context
Definition: Sema.h:1276
ASTContext & getASTContext() const
Definition: Sema.h:918
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:911
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...
NamedDecl * FindFirstQualifierInScope(Scope *S, NestedNameSpecifier NNS)
If the given nested-name-specifier begins with a bare identifier (e.g., Base::), perform name lookup ...
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:2557
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:20409
CXXRecordDecl * getCurrentInstantiationOf(NestedNameSpecifier NNS)
If the given nested name specifier refers to the current instantiation, return the declaration that c...
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:1433
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:1411
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, bool ForDefaultArgumentSubstitution=false)
Retrieve the template argument list(s) that should be used to instantiate the definition of 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.
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:1398
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.
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:218
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:9813
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:9241
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:2773
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:714
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
A trivial tuple used to represent a source range.
void setBegin(SourceLocation b)
SourceLocation getEnd() const
SourceLocation getBegin() const
bool isValid() const
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3714
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition: Decl.h:3829
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3809
TagDecl * getDefinitionOrSelf() const
Definition: Decl.h:3891
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:810
TagDecl * getOriginalDecl() const
Definition: TypeBase.h:6441
A convenient class for passing around template argument information.
Definition: TemplateBase.h:634
ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:661
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:396
Represents a C++ template name within the type system.
Definition: TemplateName.h:222
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:74
unsigned getDepth() const
Get the depth of this template parameter list in the set of template parameter lists.
Represents a declaration of a type.
Definition: Decl.h:3510
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.
void clear()
Resets this builder to the newly-initialized state.
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:556
The base class of the type hierarchy.
Definition: TypeBase.h:1833
TagDecl * castAsTagDecl() const
Definition: Type.h:71
NestedNameSpecifier getPrefix() const
If this type represents a qualified-id, this returns its nested name specifier.
Definition: Type.cpp:1928
TagDecl * getAsTagDecl() const
Retrieves the TagDecl that this type refers to, either because the type is a TagType or because it is...
Definition: Type.h:65
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: TypeBase.h:2800
QualType getCanonicalTypeInternal() const
Definition: TypeBase.h:3137
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3559
Wrapper for source info for typedefs.
Definition: TypeLoc.h:782
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:787
Wrapper for source info for types used via transparent aliases.
Definition: TypeLoc.h:790
The JSON file list parser is used to communicate input to InstallAPI.
@ CPlusPlus
Definition: LangStandard.h:55
@ CPlusPlus11
Definition: LangStandard.h:56
@ Result
The result type of a method or function.
@ Template
We are parsing a template declaration.
const FunctionProtoType * T
@ TSK_ExplicitSpecialization
This template specialization was declared or defined by an explicit specialization (C++ [temp....
Definition: Specifiers.h:198
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
Definition: Specifiers.h:194
@ None
No keyword precedes the qualified type name.
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
Definition: TemplateName.h:559
const NamespaceBaseDecl * Namespace
Keeps information about an identifier in a nested-name-spec.
Definition: Sema.h:3268
IdentifierInfo * Identifier
The identifier preceding the '::'.
Definition: Sema.h:3274
SourceLocation IdentifierLoc
The location of the identifier.
Definition: Sema.h:3277
SourceLocation CCLoc
The location of the '::'.
Definition: Sema.h:3280
ParsedType ObjectType
The type of the object, if we're parsing nested-name-specifier in a member access expression.
Definition: Sema.h:3271