clang 20.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
32 if (const RecordType *RecordTy = dyn_cast<RecordType>(Ty)) {
33 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordTy->getDecl());
34 if (!Record->isDependentContext() ||
35 Record->isCurrentInstantiation(CurContext))
36 return Record;
37
38 return nullptr;
39 } else if (isa<InjectedClassNameType>(Ty))
40 return cast<InjectedClassNameType>(Ty)->getDecl();
41 else
42 return nullptr;
43}
44
46 if (!T->isDependentType())
47 if (const TagType *Tag = T->getAs<TagType>())
48 return Tag->getDecl();
49
50 return ::getCurrentInstantiationOf(T, CurContext);
51}
52
54 bool EnteringContext) {
55 if (!SS.isSet() || SS.isInvalid())
56 return nullptr;
57
59 if (NNS->isDependent()) {
60 // If this nested-name-specifier refers to the current
61 // instantiation, return its DeclContext.
63 return Record;
64
65 if (EnteringContext) {
66 const Type *NNSType = NNS->getAsType();
67 if (!NNSType) {
68 return nullptr;
69 }
70
71 // Look through type alias templates, per C++0x [temp.dep.type]p1.
72 NNSType = Context.getCanonicalType(NNSType);
73 if (const TemplateSpecializationType *SpecType
74 = NNSType->getAs<TemplateSpecializationType>()) {
75 // We are entering the context of the nested name specifier, so try to
76 // match the nested name specifier to either a primary class template
77 // or a class template partial specialization.
79 = dyn_cast_or_null<ClassTemplateDecl>(
80 SpecType->getTemplateName().getAsTemplateDecl())) {
82 Context.getCanonicalType(QualType(SpecType, 0));
83
84 // FIXME: The fallback on the search of partial
85 // specialization using ContextType should be eventually removed since
86 // it doesn't handle the case of constrained template parameters
87 // correctly. Currently removing this fallback would change the
88 // diagnostic output for invalid code in a number of tests.
89 ClassTemplatePartialSpecializationDecl *PartialSpec = nullptr;
90 ArrayRef<TemplateParameterList *> TemplateParamLists =
92 if (!TemplateParamLists.empty()) {
93 unsigned Depth = ClassTemplate->getTemplateParameters()->getDepth();
94 auto L = find_if(TemplateParamLists,
95 [Depth](TemplateParameterList *TPL) {
96 return TPL->getDepth() == Depth;
97 });
98 if (L != TemplateParamLists.end()) {
99 void *Pos = nullptr;
100 PartialSpec = ClassTemplate->findPartialSpecialization(
101 SpecType->template_arguments(), *L, Pos);
102 }
103 } else {
104 PartialSpec = ClassTemplate->findPartialSpecialization(ContextType);
105 }
106
107 if (PartialSpec) {
108 // A declaration of the partial specialization must be visible.
109 // We can always recover here, because this only happens when we're
110 // entering the context, and that can't happen in a SFINAE context.
111 assert(!isSFINAEContext() && "partial specialization scope "
112 "specifier in SFINAE context?");
113 if (PartialSpec->hasDefinition() &&
114 !hasReachableDefinition(PartialSpec))
117 true);
118 return PartialSpec;
119 }
120
121 // If the type of the nested name specifier is the same as the
122 // injected class name of the named class template, we're entering
123 // into that class template definition.
124 QualType Injected =
125 ClassTemplate->getInjectedClassNameSpecialization();
126 if (Context.hasSameType(Injected, ContextType))
127 return ClassTemplate->getTemplatedDecl();
128 }
129 } else if (const RecordType *RecordT = NNSType->getAs<RecordType>()) {
130 // The nested name specifier refers to a member of a class template.
131 return RecordT->getDecl();
132 }
133 }
134
135 return nullptr;
136 }
137
138 switch (NNS->getKind()) {
140 llvm_unreachable("Dependent nested-name-specifier has no DeclContext");
141
143 return NNS->getAsNamespace();
144
146 return NNS->getAsNamespaceAlias()->getNamespace();
147
150 const TagType *Tag = NNS->getAsType()->getAs<TagType>();
151 assert(Tag && "Non-tag type in nested-name-specifier");
152 return Tag->getDecl();
153 }
154
157
159 return NNS->getAsRecordDecl();
160 }
161
162 llvm_unreachable("Invalid NestedNameSpecifier::Kind!");
163}
164
166 if (!SS.isSet() || SS.isInvalid())
167 return false;
168
169 return SS.getScopeRep()->isDependent();
170}
171
173 assert(getLangOpts().CPlusPlus && "Only callable in C++");
174 assert(NNS->isDependent() && "Only dependent nested-name-specifier allowed");
175
176 if (!NNS->getAsType())
177 return nullptr;
178
179 QualType T = QualType(NNS->getAsType(), 0);
180 return ::getCurrentInstantiationOf(T, CurContext);
181}
182
183/// Require that the context specified by SS be complete.
184///
185/// If SS refers to a type, this routine checks whether the type is
186/// complete enough (or can be made complete enough) for name lookup
187/// into the DeclContext. A type that is not yet completed can be
188/// considered "complete enough" if it is a class/struct/union/enum
189/// that is currently being defined. Or, if we have a type that names
190/// a class template specialization that is not a complete type, we
191/// will attempt to instantiate that class template.
193 DeclContext *DC) {
194 assert(DC && "given null context");
195
196 TagDecl *tag = dyn_cast<TagDecl>(DC);
197
198 // If this is a dependent type, then we consider it complete.
199 // FIXME: This is wrong; we should require a (visible) definition to
200 // exist in this case too.
201 if (!tag || tag->isDependentContext())
202 return false;
203
204 // Grab the tag definition, if there is one.
206 tag = type->getAsTagDecl();
207
208 // If we're currently defining this type, then lookup into the
209 // type is okay: don't complain that it isn't complete yet.
210 if (tag->isBeingDefined())
211 return false;
212
214 if (loc.isInvalid()) loc = SS.getRange().getBegin();
215
216 // The type must be complete.
217 if (RequireCompleteType(loc, type, diag::err_incomplete_nested_name_spec,
218 SS.getRange())) {
219 SS.SetInvalid(SS.getRange());
220 return true;
221 }
222
223 if (auto *EnumD = dyn_cast<EnumDecl>(tag))
224 // Fixed enum types and scoped enum instantiations are complete, but they
225 // aren't valid as scopes until we see or instantiate their definition.
226 return RequireCompleteEnumDecl(EnumD, loc, &SS);
227
228 return false;
229}
230
231/// Require that the EnumDecl is completed with its enumerators defined or
232/// instantiated. SS, if provided, is the ScopeRef parsed.
233///
235 CXXScopeSpec *SS) {
236 if (EnumD->isCompleteDefinition()) {
237 // If we know about the definition but it is not visible, complain.
238 NamedDecl *SuggestedDef = nullptr;
239 if (!hasReachableDefinition(EnumD, &SuggestedDef,
240 /*OnlyNeedComplete*/ false)) {
241 // If the user is going to see an error here, recover by making the
242 // definition visible.
243 bool TreatAsComplete = !isSFINAEContext();
245 /*Recover*/ TreatAsComplete);
246 return !TreatAsComplete;
247 }
248 return false;
249 }
250
251 // Try to instantiate the definition, if this is a specialization of an
252 // enumeration temploid.
253 if (EnumDecl *Pattern = EnumD->getInstantiatedFromMemberEnum()) {
256 if (InstantiateEnum(L, EnumD, Pattern,
259 if (SS)
260 SS->SetInvalid(SS->getRange());
261 return true;
262 }
263 return false;
264 }
265 }
266
267 if (SS) {
268 Diag(L, diag::err_incomplete_nested_name_spec)
269 << QualType(EnumD->getTypeForDecl(), 0) << SS->getRange();
270 SS->SetInvalid(SS->getRange());
271 } else {
272 Diag(L, diag::err_incomplete_enum) << QualType(EnumD->getTypeForDecl(), 0);
273 Diag(EnumD->getLocation(), diag::note_declared_at);
274 }
275
276 return true;
277}
278
280 CXXScopeSpec &SS) {
281 SS.MakeGlobal(Context, CCLoc);
282 return false;
283}
284
286 SourceLocation ColonColonLoc,
287 CXXScopeSpec &SS) {
288 if (getCurLambda()) {
289 Diag(SuperLoc, diag::err_super_in_lambda_unsupported);
290 return true;
291 }
292
293 CXXRecordDecl *RD = nullptr;
294 for (Scope *S = getCurScope(); S; S = S->getParent()) {
295 if (S->isFunctionScope()) {
296 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(S->getEntity()))
297 RD = MD->getParent();
298 break;
299 }
300 if (S->isClassScope()) {
301 RD = cast<CXXRecordDecl>(S->getEntity());
302 break;
303 }
304 }
305
306 if (!RD) {
307 Diag(SuperLoc, diag::err_invalid_super_scope);
308 return true;
309 } else if (RD->getNumBases() == 0) {
310 Diag(SuperLoc, diag::err_no_base_classes) << RD->getName();
311 return true;
312 }
313
314 SS.MakeSuper(Context, RD, SuperLoc, ColonColonLoc);
315 return false;
316}
317
319 bool *IsExtension) {
320 if (!SD)
321 return false;
322
323 SD = SD->getUnderlyingDecl();
324
325 // Namespace and namespace aliases are fine.
326 if (isa<NamespaceDecl>(SD))
327 return true;
328
329 if (!isa<TypeDecl>(SD))
330 return false;
331
332 // Determine whether we have a class (or, in C++11, an enum) or
333 // a typedef thereof. If so, build the nested-name-specifier.
334 QualType T = Context.getTypeDeclType(cast<TypeDecl>(SD));
335 if (T->isDependentType())
336 return true;
337 if (const TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(SD)) {
338 if (TD->getUnderlyingType()->isRecordType())
339 return true;
340 if (TD->getUnderlyingType()->isEnumeralType()) {
341 if (Context.getLangOpts().CPlusPlus11)
342 return true;
343 if (IsExtension)
344 *IsExtension = true;
345 }
346 } else if (isa<RecordDecl>(SD)) {
347 return true;
348 } else if (isa<EnumDecl>(SD)) {
349 if (Context.getLangOpts().CPlusPlus11)
350 return true;
351 if (IsExtension)
352 *IsExtension = true;
353 }
354
355 return false;
356}
357
359 if (!S || !NNS)
360 return nullptr;
361
362 while (NNS->getPrefix())
363 NNS = NNS->getPrefix();
364
366 return nullptr;
367
370 LookupName(Found, S);
371 assert(!Found.isAmbiguous() && "Cannot handle ambiguities here yet");
372
373 if (!Found.isSingleResult())
374 return nullptr;
375
376 NamedDecl *Result = Found.getFoundDecl();
378 return Result;
379
380 return nullptr;
381}
382
383namespace {
384
385// Callback to only accept typo corrections that can be a valid C++ member
386// initializer: either a non-static field member or a base class.
387class NestedNameSpecifierValidatorCCC final
389public:
390 explicit NestedNameSpecifierValidatorCCC(Sema &SRef)
391 : SRef(SRef) {}
392
393 bool ValidateCandidate(const TypoCorrection &candidate) override {
394 return SRef.isAcceptableNestedNameSpecifier(candidate.getCorrectionDecl());
395 }
396
397 std::unique_ptr<CorrectionCandidateCallback> clone() override {
398 return std::make_unique<NestedNameSpecifierValidatorCCC>(*this);
399 }
400
401 private:
402 Sema &SRef;
403};
404
405}
406
408 bool EnteringContext, CXXScopeSpec &SS,
409 NamedDecl *ScopeLookupResult,
410 bool ErrorRecoveryLookup,
411 bool *IsCorrectedToColon,
412 bool OnlyNamespace) {
413 if (IdInfo.Identifier->isEditorPlaceholder())
414 return true;
415 LookupResult Found(*this, IdInfo.Identifier, IdInfo.IdentifierLoc,
416 OnlyNamespace ? LookupNamespaceName
418 QualType ObjectType = GetTypeFromParser(IdInfo.ObjectType);
419
420 // Determine where to perform name lookup
421 DeclContext *LookupCtx = nullptr;
422 bool isDependent = false;
423 if (IsCorrectedToColon)
424 *IsCorrectedToColon = false;
425 if (!ObjectType.isNull()) {
426 // This nested-name-specifier occurs in a member access expression, e.g.,
427 // x->B::f, and we are looking into the type of the object.
428 assert(!SS.isSet() && "ObjectType and scope specifier cannot coexist");
429 LookupCtx = computeDeclContext(ObjectType);
430 isDependent = ObjectType->isDependentType();
431 } else if (SS.isSet()) {
432 // This nested-name-specifier occurs after another nested-name-specifier,
433 // so look into the context associated with the prior nested-name-specifier.
434 LookupCtx = computeDeclContext(SS, EnteringContext);
435 isDependent = isDependentScopeSpecifier(SS);
436 Found.setContextRange(SS.getRange());
437 }
438
439 bool ObjectTypeSearchedInScope = false;
440 if (LookupCtx) {
441 // Perform "qualified" name lookup into the declaration context we
442 // computed, which is either the type of the base of a member access
443 // expression or the declaration context associated with a prior
444 // nested-name-specifier.
445
446 // The declaration context must be complete.
447 if (!LookupCtx->isDependentContext() &&
448 RequireCompleteDeclContext(SS, LookupCtx))
449 return true;
450
451 LookupQualifiedName(Found, LookupCtx);
452
453 if (!ObjectType.isNull() && Found.empty()) {
454 // C++ [basic.lookup.classref]p4:
455 // If the id-expression in a class member access is a qualified-id of
456 // the form
457 //
458 // class-name-or-namespace-name::...
459 //
460 // the class-name-or-namespace-name following the . or -> operator is
461 // looked up both in the context of the entire postfix-expression and in
462 // the scope of the class of the object expression. If the name is found
463 // only in the scope of the class of the object expression, the name
464 // shall refer to a class-name. If the name is found only in the
465 // context of the entire postfix-expression, the name shall refer to a
466 // class-name or namespace-name. [...]
467 //
468 // Qualified name lookup into a class will not find a namespace-name,
469 // so we do not need to diagnose that case specifically. However,
470 // this qualified name lookup may find nothing. In that case, perform
471 // unqualified name lookup in the given scope (if available) or
472 // reconstruct the result from when name lookup was performed at template
473 // definition time.
474 if (S)
475 LookupName(Found, S);
476 else if (ScopeLookupResult)
477 Found.addDecl(ScopeLookupResult);
478
479 ObjectTypeSearchedInScope = true;
480 }
481 } else if (!isDependent) {
482 // Perform unqualified name lookup in the current scope.
483 LookupName(Found, S);
484 }
485
486 if (Found.isAmbiguous())
487 return true;
488
489 // If we performed lookup into a dependent context and did not find anything,
490 // that's fine: just build a dependent nested-name-specifier.
491 if (Found.empty() && isDependent &&
492 !(LookupCtx && LookupCtx->isRecord() &&
493 (!cast<CXXRecordDecl>(LookupCtx)->hasDefinition() ||
494 !cast<CXXRecordDecl>(LookupCtx)->hasAnyDependentBases()))) {
495 // Don't speculate if we're just trying to improve error recovery.
496 if (ErrorRecoveryLookup)
497 return true;
498
499 // We were not able to compute the declaration context for a dependent
500 // base object type or prior nested-name-specifier, so this
501 // nested-name-specifier refers to an unknown specialization. Just build
502 // a dependent nested-name-specifier.
503 SS.Extend(Context, IdInfo.Identifier, IdInfo.IdentifierLoc, IdInfo.CCLoc);
504 return false;
505 }
506
507 if (Found.empty() && !ErrorRecoveryLookup) {
508 // If identifier is not found as class-name-or-namespace-name, but is found
509 // as other entity, don't look for typos.
510 LookupResult R(*this, Found.getLookupNameInfo(), LookupOrdinaryName);
511 if (LookupCtx)
512 LookupQualifiedName(R, LookupCtx);
513 else if (S && !isDependent)
514 LookupName(R, S);
515 if (!R.empty()) {
516 // Don't diagnose problems with this speculative lookup.
518 // The identifier is found in ordinary lookup. If correction to colon is
519 // allowed, suggest replacement to ':'.
520 if (IsCorrectedToColon) {
521 *IsCorrectedToColon = true;
522 Diag(IdInfo.CCLoc, diag::err_nested_name_spec_is_not_class)
523 << IdInfo.Identifier << getLangOpts().CPlusPlus
524 << FixItHint::CreateReplacement(IdInfo.CCLoc, ":");
525 if (NamedDecl *ND = R.getAsSingle<NamedDecl>())
526 Diag(ND->getLocation(), diag::note_declared_at);
527 return true;
528 }
529 // Replacement '::' -> ':' is not allowed, just issue respective error.
530 Diag(R.getNameLoc(), OnlyNamespace
531 ? unsigned(diag::err_expected_namespace_name)
532 : unsigned(diag::err_expected_class_or_namespace))
533 << IdInfo.Identifier << getLangOpts().CPlusPlus;
534 if (NamedDecl *ND = R.getAsSingle<NamedDecl>())
535 Diag(ND->getLocation(), diag::note_entity_declared_at)
536 << IdInfo.Identifier;
537 return true;
538 }
539 }
540
541 if (Found.empty() && !ErrorRecoveryLookup && !getLangOpts().MSVCCompat) {
542 // We haven't found anything, and we're not recovering from a
543 // different kind of error, so look for typos.
544 DeclarationName Name = Found.getLookupName();
545 Found.clear();
546 NestedNameSpecifierValidatorCCC CCC(*this);
547 if (TypoCorrection Corrected = CorrectTypo(
548 Found.getLookupNameInfo(), Found.getLookupKind(), S, &SS, CCC,
549 CTK_ErrorRecovery, LookupCtx, EnteringContext)) {
550 if (LookupCtx) {
551 bool DroppedSpecifier =
552 Corrected.WillReplaceSpecifier() &&
553 Name.getAsString() == Corrected.getAsString(getLangOpts());
554 if (DroppedSpecifier)
555 SS.clear();
556 diagnoseTypo(Corrected, PDiag(diag::err_no_member_suggest)
557 << Name << LookupCtx << DroppedSpecifier
558 << SS.getRange());
559 } else
560 diagnoseTypo(Corrected, PDiag(diag::err_undeclared_var_use_suggest)
561 << Name);
562
563 if (Corrected.getCorrectionSpecifier())
564 SS.MakeTrivial(Context, Corrected.getCorrectionSpecifier(),
565 SourceRange(Found.getNameLoc()));
566
567 if (NamedDecl *ND = Corrected.getFoundDecl())
568 Found.addDecl(ND);
569 Found.setLookupName(Corrected.getCorrection());
570 } else {
571 Found.setLookupName(IdInfo.Identifier);
572 }
573 }
574
575 NamedDecl *SD =
576 Found.isSingleResult() ? Found.getRepresentativeDecl() : nullptr;
577 bool IsExtension = false;
578 bool AcceptSpec = isAcceptableNestedNameSpecifier(SD, &IsExtension);
579 if (!AcceptSpec && IsExtension) {
580 AcceptSpec = true;
581 Diag(IdInfo.IdentifierLoc, diag::ext_nested_name_spec_is_enum);
582 }
583 if (AcceptSpec) {
584 if (!ObjectType.isNull() && !ObjectTypeSearchedInScope &&
586 // C++03 [basic.lookup.classref]p4:
587 // [...] If the name is found in both contexts, the
588 // class-name-or-namespace-name shall refer to the same entity.
589 //
590 // We already found the name in the scope of the object. Now, look
591 // into the current scope (the scope of the postfix-expression) to
592 // see if we can find the same name there. As above, if there is no
593 // scope, reconstruct the result from the template instantiation itself.
594 //
595 // Note that C++11 does *not* perform this redundant lookup.
596 NamedDecl *OuterDecl;
597 if (S) {
598 LookupResult FoundOuter(*this, IdInfo.Identifier, IdInfo.IdentifierLoc,
600 LookupName(FoundOuter, S);
601 OuterDecl = FoundOuter.getAsSingle<NamedDecl>();
602 } else
603 OuterDecl = ScopeLookupResult;
604
605 if (isAcceptableNestedNameSpecifier(OuterDecl) &&
606 OuterDecl->getCanonicalDecl() != SD->getCanonicalDecl() &&
607 (!isa<TypeDecl>(OuterDecl) || !isa<TypeDecl>(SD) ||
609 Context.getTypeDeclType(cast<TypeDecl>(OuterDecl)),
610 Context.getTypeDeclType(cast<TypeDecl>(SD))))) {
611 if (ErrorRecoveryLookup)
612 return true;
613
614 Diag(IdInfo.IdentifierLoc,
615 diag::err_nested_name_member_ref_lookup_ambiguous)
616 << IdInfo.Identifier;
617 Diag(SD->getLocation(), diag::note_ambig_member_ref_object_type)
618 << ObjectType;
619 Diag(OuterDecl->getLocation(), diag::note_ambig_member_ref_scope);
620
621 // Fall through so that we'll pick the name we found in the object
622 // type, since that's probably what the user wanted anyway.
623 }
624 }
625
626 if (auto *TD = dyn_cast_or_null<TypedefNameDecl>(SD))
627 MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
628
629 // If we're just performing this lookup for error-recovery purposes,
630 // don't extend the nested-name-specifier. Just return now.
631 if (ErrorRecoveryLookup)
632 return false;
633
634 // The use of a nested name specifier may trigger deprecation warnings.
635 DiagnoseUseOfDecl(SD, IdInfo.CCLoc);
636
637 if (NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(SD)) {
638 SS.Extend(Context, Namespace, IdInfo.IdentifierLoc, IdInfo.CCLoc);
639 return false;
640 }
641
642 if (NamespaceAliasDecl *Alias = dyn_cast<NamespaceAliasDecl>(SD)) {
643 SS.Extend(Context, Alias, IdInfo.IdentifierLoc, IdInfo.CCLoc);
644 return false;
645 }
646
647 QualType T =
648 Context.getTypeDeclType(cast<TypeDecl>(SD->getUnderlyingDecl()));
649
650 if (T->isEnumeralType())
651 Diag(IdInfo.IdentifierLoc, diag::warn_cxx98_compat_enum_nested_name_spec);
652
653 TypeLocBuilder TLB;
654 if (const auto *USD = dyn_cast<UsingShadowDecl>(SD)) {
655 T = Context.getUsingType(USD, T);
657 } else if (isa<InjectedClassNameType>(T)) {
658 InjectedClassNameTypeLoc InjectedTL
660 InjectedTL.setNameLoc(IdInfo.IdentifierLoc);
661 } else if (isa<RecordType>(T)) {
662 RecordTypeLoc RecordTL = TLB.push<RecordTypeLoc>(T);
663 RecordTL.setNameLoc(IdInfo.IdentifierLoc);
664 } else if (isa<TypedefType>(T)) {
665 TypedefTypeLoc TypedefTL = TLB.push<TypedefTypeLoc>(T);
666 TypedefTL.setNameLoc(IdInfo.IdentifierLoc);
667 } else if (isa<EnumType>(T)) {
668 EnumTypeLoc EnumTL = TLB.push<EnumTypeLoc>(T);
669 EnumTL.setNameLoc(IdInfo.IdentifierLoc);
670 } else if (isa<TemplateTypeParmType>(T)) {
671 TemplateTypeParmTypeLoc TemplateTypeTL
673 TemplateTypeTL.setNameLoc(IdInfo.IdentifierLoc);
674 } else if (isa<UnresolvedUsingType>(T)) {
675 UnresolvedUsingTypeLoc UnresolvedTL
677 UnresolvedTL.setNameLoc(IdInfo.IdentifierLoc);
678 } else if (isa<SubstTemplateTypeParmType>(T)) {
681 TL.setNameLoc(IdInfo.IdentifierLoc);
682 } else if (isa<SubstTemplateTypeParmPackType>(T)) {
685 TL.setNameLoc(IdInfo.IdentifierLoc);
686 } else {
687 llvm_unreachable("Unhandled TypeDecl node in nested-name-specifier");
688 }
689
691 IdInfo.CCLoc);
692 return false;
693 }
694
695 // Otherwise, we have an error case. If we don't want diagnostics, just
696 // return an error now.
697 if (ErrorRecoveryLookup)
698 return true;
699
700 // If we didn't find anything during our lookup, try again with
701 // ordinary name lookup, which can help us produce better error
702 // messages.
703 if (Found.empty()) {
705 LookupName(Found, S);
706 }
707
708 // In Microsoft mode, if we are within a templated function and we can't
709 // resolve Identifier, then extend the SS with Identifier. This will have
710 // the effect of resolving Identifier during template instantiation.
711 // The goal is to be able to resolve a function call whose
712 // nested-name-specifier is located inside a dependent base class.
713 // Example:
714 //
715 // class C {
716 // public:
717 // static void foo2() { }
718 // };
719 // template <class T> class A { public: typedef C D; };
720 //
721 // template <class T> class B : public A<T> {
722 // public:
723 // void foo() { D::foo2(); }
724 // };
725 if (getLangOpts().MSVCCompat) {
726 DeclContext *DC = LookupCtx ? LookupCtx : CurContext;
727 if (DC->isDependentContext() && DC->isFunctionOrMethod()) {
728 CXXRecordDecl *ContainingClass = dyn_cast<CXXRecordDecl>(DC->getParent());
729 if (ContainingClass && ContainingClass->hasAnyDependentBases()) {
730 Diag(IdInfo.IdentifierLoc,
731 diag::ext_undeclared_unqual_id_with_dependent_base)
732 << IdInfo.Identifier << ContainingClass;
733 // Fake up a nested-name-specifier that starts with the
734 // injected-class-name of the enclosing class.
735 QualType T = Context.getTypeDeclType(ContainingClass);
736 TypeLocBuilder TLB;
737 TLB.pushTrivial(Context, T, IdInfo.IdentifierLoc);
738 SS.Extend(Context, /*TemplateKWLoc=*/SourceLocation(),
740 // Add the identifier to form a dependent name.
741 SS.Extend(Context, IdInfo.Identifier, IdInfo.IdentifierLoc,
742 IdInfo.CCLoc);
743 return false;
744 }
745 }
746 }
747
748 if (!Found.empty()) {
749 if (TypeDecl *TD = Found.getAsSingle<TypeDecl>()) {
750 Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace)
751 << Context.getTypeDeclType(TD) << getLangOpts().CPlusPlus;
752 } else if (Found.getAsSingle<TemplateDecl>()) {
753 ParsedType SuggestedType;
754 DiagnoseUnknownTypeName(IdInfo.Identifier, IdInfo.IdentifierLoc, S, &SS,
755 SuggestedType);
756 } else {
757 Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace)
758 << IdInfo.Identifier << getLangOpts().CPlusPlus;
759 if (NamedDecl *ND = Found.getAsSingle<NamedDecl>())
760 Diag(ND->getLocation(), diag::note_entity_declared_at)
761 << IdInfo.Identifier;
762 }
763 } else if (SS.isSet())
764 Diag(IdInfo.IdentifierLoc, diag::err_no_member) << IdInfo.Identifier
765 << LookupCtx << SS.getRange();
766 else
767 Diag(IdInfo.IdentifierLoc, diag::err_undeclared_var_use)
768 << IdInfo.Identifier;
769
770 return true;
771}
772
774 bool EnteringContext, CXXScopeSpec &SS,
775 bool *IsCorrectedToColon,
776 bool OnlyNamespace) {
777 if (SS.isInvalid())
778 return true;
779
780 return BuildCXXNestedNameSpecifier(S, IdInfo, EnteringContext, SS,
781 /*ScopeLookupResult=*/nullptr, false,
782 IsCorrectedToColon, OnlyNamespace);
783}
784
786 const DeclSpec &DS,
787 SourceLocation ColonColonLoc) {
789 return true;
790
792
794 if (T.isNull())
795 return true;
796
797 if (!T->isDependentType() && !T->getAs<TagType>()) {
798 Diag(DS.getTypeSpecTypeLoc(), diag::err_expected_class_or_namespace)
799 << T << getLangOpts().CPlusPlus;
800 return true;
801 }
802
803 TypeLocBuilder TLB;
804 DecltypeTypeLoc DecltypeTL = TLB.push<DecltypeTypeLoc>(T);
805 DecltypeTL.setDecltypeLoc(DS.getTypeSpecTypeLoc());
806 DecltypeTL.setRParenLoc(DS.getTypeofParensRange().getEnd());
808 ColonColonLoc);
809 return false;
810}
811
813 const DeclSpec &DS,
814 SourceLocation ColonColonLoc,
815 QualType Type) {
817 return true;
818
820
821 if (Type.isNull())
822 return true;
823
824 TypeLocBuilder TLB;
826 cast<PackIndexingType>(Type.getTypePtr())->getPattern(),
827 DS.getBeginLoc());
831 ColonColonLoc);
832 return false;
833}
834
836 NestedNameSpecInfo &IdInfo,
837 bool EnteringContext) {
838 if (SS.isInvalid())
839 return false;
840
841 return !BuildCXXNestedNameSpecifier(S, IdInfo, EnteringContext, SS,
842 /*ScopeLookupResult=*/nullptr, true);
843}
844
846 CXXScopeSpec &SS,
847 SourceLocation TemplateKWLoc,
848 TemplateTy OpaqueTemplate,
849 SourceLocation TemplateNameLoc,
850 SourceLocation LAngleLoc,
851 ASTTemplateArgsPtr TemplateArgsIn,
852 SourceLocation RAngleLoc,
853 SourceLocation CCLoc,
854 bool EnteringContext) {
855 if (SS.isInvalid())
856 return true;
857
858 TemplateName Template = OpaqueTemplate.get();
859
860 // Translate the parser's template argument list in our AST format.
861 TemplateArgumentListInfo TemplateArgs(LAngleLoc, RAngleLoc);
862 translateTemplateArguments(TemplateArgsIn, TemplateArgs);
863
865 if (DTN && DTN->isIdentifier()) {
866 // Handle a dependent template specialization for which we cannot resolve
867 // the template name.
868 assert(DTN->getQualifier() == SS.getScopeRep());
871 TemplateArgs.arguments());
872
873 // Create source-location information for this type.
874 TypeLocBuilder Builder;
879 SpecTL.setTemplateKeywordLoc(TemplateKWLoc);
880 SpecTL.setTemplateNameLoc(TemplateNameLoc);
881 SpecTL.setLAngleLoc(LAngleLoc);
882 SpecTL.setRAngleLoc(RAngleLoc);
883 for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
884 SpecTL.setArgLocInfo(I, TemplateArgs[I].getLocInfo());
885
886 SS.Extend(Context, TemplateKWLoc, Builder.getTypeLocInContext(Context, T),
887 CCLoc);
888 return false;
889 }
890
891 // If we assumed an undeclared identifier was a template name, try to
892 // typo-correct it now.
893 if (Template.getAsAssumedTemplateName() &&
894 resolveAssumedTemplateNameAsType(S, Template, TemplateNameLoc))
895 return true;
896
897 TemplateDecl *TD = Template.getAsTemplateDecl();
898 if (Template.getAsOverloadedTemplate() || DTN ||
899 isa<FunctionTemplateDecl>(TD) || isa<VarTemplateDecl>(TD)) {
900 SourceRange R(TemplateNameLoc, RAngleLoc);
901 if (SS.getRange().isValid())
902 R.setBegin(SS.getRange().getBegin());
903
904 Diag(CCLoc, diag::err_non_type_template_in_nested_name_specifier)
905 << isa_and_nonnull<VarTemplateDecl>(TD) << Template << R;
906 NoteAllFoundTemplates(Template);
907 return true;
908 }
909
910 // We were able to resolve the template name to an actual template.
911 // Build an appropriate nested-name-specifier.
912 QualType T = CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
913 if (T.isNull())
914 return true;
915
916 // Alias template specializations can produce types which are not valid
917 // nested name specifiers.
918 if (!T->isDependentType() && !T->getAs<TagType>()) {
919 Diag(TemplateNameLoc, diag::err_nested_name_spec_non_tag) << T;
920 NoteAllFoundTemplates(Template);
921 return true;
922 }
923
924 // Provide source-location information for the template specialization type.
925 TypeLocBuilder Builder;
927 = Builder.push<TemplateSpecializationTypeLoc>(T);
928 SpecTL.setTemplateKeywordLoc(TemplateKWLoc);
929 SpecTL.setTemplateNameLoc(TemplateNameLoc);
930 SpecTL.setLAngleLoc(LAngleLoc);
931 SpecTL.setRAngleLoc(RAngleLoc);
932 for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
933 SpecTL.setArgLocInfo(I, TemplateArgs[I].getLocInfo());
934
935
936 SS.Extend(Context, TemplateKWLoc, Builder.getTypeLocInContext(Context, T),
937 CCLoc);
938 return false;
939}
940
941namespace {
942 /// A structure that stores a nested-name-specifier annotation,
943 /// including both the nested-name-specifier
944 struct NestedNameSpecifierAnnotation {
946 };
947}
948
950 if (SS.isEmpty() || SS.isInvalid())
951 return nullptr;
952
953 void *Mem = Context.Allocate(
954 (sizeof(NestedNameSpecifierAnnotation) + SS.location_size()),
955 alignof(NestedNameSpecifierAnnotation));
956 NestedNameSpecifierAnnotation *Annotation
957 = new (Mem) NestedNameSpecifierAnnotation;
958 Annotation->NNS = SS.getScopeRep();
959 memcpy(Annotation + 1, SS.location_data(), SS.location_size());
960 return Annotation;
961}
962
964 SourceRange AnnotationRange,
965 CXXScopeSpec &SS) {
966 if (!AnnotationPtr) {
967 SS.SetInvalid(AnnotationRange);
968 return;
969 }
970
971 NestedNameSpecifierAnnotation *Annotation
972 = static_cast<NestedNameSpecifierAnnotation *>(AnnotationPtr);
973 SS.Adopt(NestedNameSpecifierLoc(Annotation->NNS, Annotation + 1));
974}
975
977 assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
978
979 // Don't enter a declarator context when the current context is an Objective-C
980 // declaration.
981 if (isa<ObjCContainerDecl>(CurContext) || isa<ObjCMethodDecl>(CurContext))
982 return false;
983
984 NestedNameSpecifier *Qualifier = SS.getScopeRep();
985
986 // There are only two places a well-formed program may qualify a
987 // declarator: first, when defining a namespace or class member
988 // out-of-line, and second, when naming an explicitly-qualified
989 // friend function. The latter case is governed by
990 // C++03 [basic.lookup.unqual]p10:
991 // In a friend declaration naming a member function, a name used
992 // in the function declarator and not part of a template-argument
993 // in a template-id is first looked up in the scope of the member
994 // function's class. If it is not found, or if the name is part of
995 // a template-argument in a template-id, the look up is as
996 // described for unqualified names in the definition of the class
997 // granting friendship.
998 // i.e. we don't push a scope unless it's a class member.
999
1000 switch (Qualifier->getKind()) {
1004 // These are always namespace scopes. We never want to enter a
1005 // namespace scope from anything but a file context.
1007
1012 // These are never namespace scopes.
1013 return true;
1014 }
1015
1016 llvm_unreachable("Invalid NestedNameSpecifier::Kind!");
1017}
1018
1020 assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
1021
1022 if (SS.isInvalid()) return true;
1023
1024 DeclContext *DC = computeDeclContext(SS, true);
1025 if (!DC) return true;
1026
1027 // Before we enter a declarator's context, we need to make sure that
1028 // it is a complete declaration context.
1029 if (!DC->isDependentContext() && RequireCompleteDeclContext(SS, DC))
1030 return true;
1031
1033
1034 // Rebuild the nested name specifier for the new scope.
1035 if (DC->isDependentContext())
1037
1038 return false;
1039}
1040
1042 assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
1043 if (SS.isInvalid())
1044 return;
1045 assert(!SS.isInvalid() && computeDeclContext(SS, true) &&
1046 "exiting declarator scope we never really entered");
1048}
Defines the clang::ASTContext interface.
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.
enum clang::format::@1329::AnnotatingParser::Context::@350 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:1141
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:2716
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2732
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:1703
const LangOptions & getLangOpts() const
Definition: ASTContext.h:834
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:754
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2078
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:607
unsigned getNumBases() const
Retrieves the number of base classes of this class.
Definition: DeclCXX.h:614
bool hasDefinition() const
Definition: DeclCXX.h:572
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:74
char * location_data() const
Retrieve the data associated with the source-location information.
Definition: DeclSpec.h:236
void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
Definition: DeclSpec.cpp:123
SourceLocation getLastQualifierNameLoc() const
Retrieve the location of the name in the last qualifier in this nested name specifier.
Definition: DeclSpec.cpp:142
SourceRange getRange() const
Definition: DeclSpec.h:80
void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc)
Turn this (empty) nested-name-specifier into the global nested-name-specifier '::'.
Definition: DeclSpec.cpp:101
bool isSet() const
Deprecated.
Definition: DeclSpec.h:228
ArrayRef< TemplateParameterList * > getTemplateParamLists() const
Definition: DeclSpec.h:90
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
Definition: DeclSpec.cpp:149
NestedNameSpecifier * getScopeRep() const
Retrieve the representation of the nested-name-specifier.
Definition: DeclSpec.h:95
void SetInvalid(SourceRange R)
Indicate that this nested-name-specifier is invalid.
Definition: DeclSpec.h:218
unsigned location_size() const
Retrieve the size of the data associated with source-location information.
Definition: DeclSpec.h:240
void MakeSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)
Turns this (empty) nested-name-specifier into '__super' nested-name-specifier.
Definition: DeclSpec.cpp:111
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:51
bool isInvalid() const
An error occurred during parsing of the scope specifier.
Definition: DeclSpec.h:213
bool isEmpty() const
No scope specifier.
Definition: DeclSpec.h:208
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Definition: DeclSpec.cpp:129
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:1435
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:2089
bool isFileContext() const
Definition: DeclBase.h:2160
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1334
bool isRecord() const
Definition: DeclBase.h:2169
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1990
bool isFunctionOrMethod() const
Definition: DeclBase.h:2141
Captures information about "declaration specifiers".
Definition: DeclSpec.h:247
TST getTypeSpecType() const
Definition: DeclSpec.h:537
SourceLocation getBeginLoc() const LLVM_READONLY
Definition: DeclSpec.h:575
static const TST TST_typename_pack_indexing
Definition: DeclSpec.h:313
SourceLocation getEllipsisLoc() const
Definition: DeclSpec.h:623
Expr * getRepAsExpr() const
Definition: DeclSpec.h:555
static const TST TST_decltype
Definition: DeclSpec.h:311
SourceLocation getTypeSpecTypeLoc() const
Definition: DeclSpec.h:582
static const TST TST_error
Definition: DeclSpec.h:328
SourceRange getTypeofParensRange() const
Definition: DeclSpec.h:592
SourceLocation getLocation() const
Definition: DeclBase.h:442
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:967
The name of a declaration.
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:2118
void setDecltypeLoc(SourceLocation Loc)
Definition: TypeLoc.h:2115
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:548
bool isIdentifier() const
Determine whether this template name refers to an identifier.
Definition: TemplateName.h:607
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:604
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
Definition: TemplateName.h:610
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:2503
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2523
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2491
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2547
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2539
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:2555
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:2531
Represents an enum.
Definition: Decl.h:3847
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition: Decl.h:4106
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition: Decl.cpp:4961
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:138
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
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:664
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
Definition: Lookup.h:634
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:620
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
Definition: DeclTemplate.h:642
This represents a decl that may have a name.
Definition: Decl.h:253
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition: Decl.h:466
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:280
Represents a C++ namespace alias.
Definition: DeclCXX.h:3138
NamespaceDecl * getNamespace()
Retrieve the namespace declaration aliased by this directive.
Definition: DeclCXX.h:3210
Represent a C++ namespace.
Definition: Decl.h:551
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:2143
A (possibly-)qualified type.
Definition: Type.h:929
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:996
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:7931
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:6072
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:60
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
Definition: SemaBase.cpp:32
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:463
bool hasReachableDefinition(NamedDecl *D, NamedDecl **Suggested, bool OnlyNeedComplete=false)
Determine if D has a reachable definition.
Definition: SemaType.cpp:9207
Scope * getCurScope() const
Retrieve the parser's current scope.
Definition: Sema.h:731
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:8983
@ LookupNestedNameSpecifierName
Look up of a name that precedes the '::' scope resolution operator in C++.
Definition: Sema.h:9002
@ LookupNamespaceName
Look up a namespace name within a C++ using directive or namespace alias definition,...
Definition: Sema.h:9006
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:908
ASTContext & getASTContext() const
Definition: Sema.h:531
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:524
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:2404
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:20059
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:1375
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:1043
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:1340
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:216
@ CTK_ErrorRecovery
Definition: Sema.h:9377
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:9653
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:9068
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:2750
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:681
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:3564
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition: Decl.h:3687
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3667
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:399
Represents a C++ template name within the type system.
Definition: TemplateName.h:220
TemplateDecl * getAsTemplateDecl(bool IgnoreDeduced=false) 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:1718
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1694
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:1735
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1702
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1710
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:6661
Wrapper for template type parameters.
Definition: TypeLoc.h:758
Represents a declaration of a type.
Definition: Decl.h:3370
const Type * getTypeForDecl() const
Definition: Decl.h:3395
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:1828
bool isEnumeralType() const
Definition: Type.h:8290
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2706
QualType getCanonicalTypeInternal() const
Definition: Type.h:2989
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:8731
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3413
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:55
@ CPlusPlus11
Definition: LangStandard.h:56
@ Result
The result type of a method or function.
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.
Keeps information about an identifier in a nested-name-spec.
Definition: Sema.h:2803
IdentifierInfo * Identifier
The identifier preceding the '::'.
Definition: Sema.h:2809
SourceLocation IdentifierLoc
The location of the identifier.
Definition: Sema.h:2812
SourceLocation CCLoc
The location of the '::'.
Definition: Sema.h:2815
ParsedType ObjectType
The type of the object, if we're parsing nested-name-specifier in a member access expression.
Definition: Sema.h:2806