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