clang 17.0.0git
SemaCXXScopeSpec.cpp
Go to the documentation of this file.
1//===--- SemaCXXScopeSpec.cpp - Semantic Analysis for C++ scope specifiers-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements C++ semantic analysis for scope specifiers.
10//
11//===----------------------------------------------------------------------===//
12
13#include "TypeLocBuilder.h"
16#include "clang/AST/ExprCXX.h"
19#include "clang/Sema/DeclSpec.h"
20#include "clang/Sema/Lookup.h"
22#include "clang/Sema/Template.h"
23#include "llvm/ADT/STLExtras.h"
24using namespace clang;
25
26/// Find the current instantiation that associated with the given type.
28 DeclContext *CurContext) {
29 if (T.isNull())
30 return nullptr;
31
32 const Type *Ty = T->getCanonicalTypeInternal().getTypePtr();
33 if (const RecordType *RecordTy = dyn_cast<RecordType>(Ty)) {
34 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordTy->getDecl());
35 if (!Record->isDependentContext() ||
36 Record->isCurrentInstantiation(CurContext))
37 return Record;
38
39 return nullptr;
40 } else if (isa<InjectedClassNameType>(Ty))
41 return cast<InjectedClassNameType>(Ty)->getDecl();
42 else
43 return nullptr;
44}
45
46/// Compute the DeclContext that is associated with the given type.
47///
48/// \param T the type for which we are attempting to find a DeclContext.
49///
50/// \returns the declaration context represented by the type T,
51/// or NULL if the declaration context cannot be computed (e.g., because it is
52/// dependent and not the current instantiation).
54 if (!T->isDependentType())
55 if (const TagType *Tag = T->getAs<TagType>())
56 return Tag->getDecl();
57
58 return ::getCurrentInstantiationOf(T, CurContext);
59}
60
61/// Compute the DeclContext that is associated with the given
62/// scope specifier.
63///
64/// \param SS the C++ scope specifier as it appears in the source
65///
66/// \param EnteringContext when true, we will be entering the context of
67/// this scope specifier, so we can retrieve the declaration context of a
68/// class template or class template partial specialization even if it is
69/// not the current instantiation.
70///
71/// \returns the declaration context represented by the scope specifier @p SS,
72/// or NULL if the declaration context cannot be computed (e.g., because it is
73/// dependent and not the current instantiation).
75 bool EnteringContext) {
76 if (!SS.isSet() || SS.isInvalid())
77 return nullptr;
78
80 if (NNS->isDependent()) {
81 // If this nested-name-specifier refers to the current
82 // instantiation, return its DeclContext.
84 return Record;
85
86 if (EnteringContext) {
87 const Type *NNSType = NNS->getAsType();
88 if (!NNSType) {
89 return nullptr;
90 }
91
92 // Look through type alias templates, per C++0x [temp.dep.type]p1.
93 NNSType = Context.getCanonicalType(NNSType);
94 if (const TemplateSpecializationType *SpecType
95 = NNSType->getAs<TemplateSpecializationType>()) {
96 // We are entering the context of the nested name specifier, so try to
97 // match the nested name specifier to either a primary class template
98 // or a class template partial specialization.
100 = dyn_cast_or_null<ClassTemplateDecl>(
101 SpecType->getTemplateName().getAsTemplateDecl())) {
103 Context.getCanonicalType(QualType(SpecType, 0));
104
105 // FIXME: The fallback on the search of partial
106 // specialization using ContextType should be eventually removed since
107 // it doesn't handle the case of constrained template parameters
108 // correctly. Currently removing this fallback would change the
109 // diagnostic output for invalid code in a number of tests.
110 ClassTemplatePartialSpecializationDecl *PartialSpec = nullptr;
111 ArrayRef<TemplateParameterList *> TemplateParamLists =
113 if (!TemplateParamLists.empty()) {
114 unsigned Depth = ClassTemplate->getTemplateParameters()->getDepth();
115 auto L = find_if(TemplateParamLists,
116 [Depth](TemplateParameterList *TPL) {
117 return TPL->getDepth() == Depth;
118 });
119 if (L != TemplateParamLists.end()) {
120 void *Pos = nullptr;
121 PartialSpec = ClassTemplate->findPartialSpecialization(
122 SpecType->template_arguments(), *L, Pos);
123 }
124 } else {
125 PartialSpec = ClassTemplate->findPartialSpecialization(ContextType);
126 }
127
128 if (PartialSpec) {
129 // A declaration of the partial specialization must be visible.
130 // We can always recover here, because this only happens when we're
131 // entering the context, and that can't happen in a SFINAE context.
132 assert(!isSFINAEContext() && "partial specialization scope "
133 "specifier in SFINAE context?");
134 if (!hasReachableDefinition(PartialSpec))
137 true);
138 return PartialSpec;
139 }
140
141 // If the type of the nested name specifier is the same as the
142 // injected class name of the named class template, we're entering
143 // into that class template definition.
144 QualType Injected =
145 ClassTemplate->getInjectedClassNameSpecialization();
146 if (Context.hasSameType(Injected, ContextType))
147 return ClassTemplate->getTemplatedDecl();
148 }
149 } else if (const RecordType *RecordT = NNSType->getAs<RecordType>()) {
150 // The nested name specifier refers to a member of a class template.
151 return RecordT->getDecl();
152 }
153 }
154
155 return nullptr;
156 }
157
158 switch (NNS->getKind()) {
160 llvm_unreachable("Dependent nested-name-specifier has no DeclContext");
161
163 return NNS->getAsNamespace();
164
166 return NNS->getAsNamespaceAlias()->getNamespace();
167
170 const TagType *Tag = NNS->getAsType()->getAs<TagType>();
171 assert(Tag && "Non-tag type in nested-name-specifier");
172 return Tag->getDecl();
173 }
174
177
179 return NNS->getAsRecordDecl();
180 }
181
182 llvm_unreachable("Invalid NestedNameSpecifier::Kind!");
183}
184
186 if (!SS.isSet() || SS.isInvalid())
187 return false;
188
189 return SS.getScopeRep()->isDependent();
190}
191
192/// If the given nested name specifier refers to the current
193/// instantiation, return the declaration that corresponds to that
194/// current instantiation (C++0x [temp.dep.type]p1).
195///
196/// \param NNS a dependent nested name specifier.
198 assert(getLangOpts().CPlusPlus && "Only callable in C++");
199 assert(NNS->isDependent() && "Only dependent nested-name-specifier allowed");
200
201 if (!NNS->getAsType())
202 return nullptr;
203
204 QualType T = QualType(NNS->getAsType(), 0);
205 return ::getCurrentInstantiationOf(T, CurContext);
206}
207
208/// Require that the context specified by SS be complete.
209///
210/// If SS refers to a type, this routine checks whether the type is
211/// complete enough (or can be made complete enough) for name lookup
212/// into the DeclContext. A type that is not yet completed can be
213/// considered "complete enough" if it is a class/struct/union/enum
214/// that is currently being defined. Or, if we have a type that names
215/// a class template specialization that is not a complete type, we
216/// will attempt to instantiate that class template.
218 DeclContext *DC) {
219 assert(DC && "given null context");
220
221 TagDecl *tag = dyn_cast<TagDecl>(DC);
222
223 // If this is a dependent type, then we consider it complete.
224 // FIXME: This is wrong; we should require a (visible) definition to
225 // exist in this case too.
226 if (!tag || tag->isDependentContext())
227 return false;
228
229 // Grab the tag definition, if there is one.
231 tag = type->getAsTagDecl();
232
233 // If we're currently defining this type, then lookup into the
234 // type is okay: don't complain that it isn't complete yet.
235 if (tag->isBeingDefined())
236 return false;
237
239 if (loc.isInvalid()) loc = SS.getRange().getBegin();
240
241 // The type must be complete.
242 if (RequireCompleteType(loc, type, diag::err_incomplete_nested_name_spec,
243 SS.getRange())) {
244 SS.SetInvalid(SS.getRange());
245 return true;
246 }
247
248 if (auto *EnumD = dyn_cast<EnumDecl>(tag))
249 // Fixed enum types and scoped enum instantiations are complete, but they
250 // aren't valid as scopes until we see or instantiate their definition.
251 return RequireCompleteEnumDecl(EnumD, loc, &SS);
252
253 return false;
254}
255
256/// Require that the EnumDecl is completed with its enumerators defined or
257/// instantiated. SS, if provided, is the ScopeRef parsed.
258///
260 CXXScopeSpec *SS) {
261 if (EnumD->isCompleteDefinition()) {
262 // If we know about the definition but it is not visible, complain.
263 NamedDecl *SuggestedDef = nullptr;
264 if (!hasReachableDefinition(EnumD, &SuggestedDef,
265 /*OnlyNeedComplete*/ false)) {
266 // If the user is going to see an error here, recover by making the
267 // definition visible.
268 bool TreatAsComplete = !isSFINAEContext();
270 /*Recover*/ TreatAsComplete);
271 return !TreatAsComplete;
272 }
273 return false;
274 }
275
276 // Try to instantiate the definition, if this is a specialization of an
277 // enumeration temploid.
278 if (EnumDecl *Pattern = EnumD->getInstantiatedFromMemberEnum()) {
281 if (InstantiateEnum(L, EnumD, Pattern,
284 if (SS)
285 SS->SetInvalid(SS->getRange());
286 return true;
287 }
288 return false;
289 }
290 }
291
292 if (SS) {
293 Diag(L, diag::err_incomplete_nested_name_spec)
294 << QualType(EnumD->getTypeForDecl(), 0) << SS->getRange();
295 SS->SetInvalid(SS->getRange());
296 } else {
297 Diag(L, diag::err_incomplete_enum) << QualType(EnumD->getTypeForDecl(), 0);
298 Diag(EnumD->getLocation(), diag::note_declared_at);
299 }
300
301 return true;
302}
303
305 CXXScopeSpec &SS) {
306 SS.MakeGlobal(Context, CCLoc);
307 return false;
308}
309
311 SourceLocation ColonColonLoc,
312 CXXScopeSpec &SS) {
313 if (getCurLambda()) {
314 Diag(SuperLoc, diag::err_super_in_lambda_unsupported);
315 return true;
316 }
317
318 CXXRecordDecl *RD = nullptr;
319 for (Scope *S = getCurScope(); S; S = S->getParent()) {
320 if (S->isFunctionScope()) {
321 if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(S->getEntity()))
322 RD = MD->getParent();
323 break;
324 }
325 if (S->isClassScope()) {
326 RD = cast<CXXRecordDecl>(S->getEntity());
327 break;
328 }
329 }
330
331 if (!RD) {
332 Diag(SuperLoc, diag::err_invalid_super_scope);
333 return true;
334 } else if (RD->getNumBases() == 0) {
335 Diag(SuperLoc, diag::err_no_base_classes) << RD->getName();
336 return true;
337 }
338
339 SS.MakeSuper(Context, RD, SuperLoc, ColonColonLoc);
340 return false;
341}
342
343/// Determines whether the given declaration is an valid acceptable
344/// result for name lookup of a nested-name-specifier.
345/// \param SD Declaration checked for nested-name-specifier.
346/// \param IsExtension If not null and the declaration is accepted as an
347/// extension, the pointed variable is assigned true.
349 bool *IsExtension) {
350 if (!SD)
351 return false;
352
353 SD = SD->getUnderlyingDecl();
354
355 // Namespace and namespace aliases are fine.
356 if (isa<NamespaceDecl>(SD))
357 return true;
358
359 if (!isa<TypeDecl>(SD))
360 return false;
361
362 // Determine whether we have a class (or, in C++11, an enum) or
363 // a typedef thereof. If so, build the nested-name-specifier.
364 QualType T = Context.getTypeDeclType(cast<TypeDecl>(SD));
365 if (T->isDependentType())
366 return true;
367 if (const TypedefNameDecl *TD = dyn_cast<TypedefNameDecl>(SD)) {
368 if (TD->getUnderlyingType()->isRecordType())
369 return true;
370 if (TD->getUnderlyingType()->isEnumeralType()) {
371 if (Context.getLangOpts().CPlusPlus11)
372 return true;
373 if (IsExtension)
374 *IsExtension = true;
375 }
376 } else if (isa<RecordDecl>(SD)) {
377 return true;
378 } else if (isa<EnumDecl>(SD)) {
379 if (Context.getLangOpts().CPlusPlus11)
380 return true;
381 if (IsExtension)
382 *IsExtension = true;
383 }
384
385 return false;
386}
387
388/// If the given nested-name-specifier begins with a bare identifier
389/// (e.g., Base::), perform name lookup for that identifier as a
390/// nested-name-specifier within the given scope, and return the result of that
391/// name lookup.
393 if (!S || !NNS)
394 return nullptr;
395
396 while (NNS->getPrefix())
397 NNS = NNS->getPrefix();
398
400 return nullptr;
401
402 LookupResult Found(*this, NNS->getAsIdentifier(), SourceLocation(),
404 LookupName(Found, S);
405 assert(!Found.isAmbiguous() && "Cannot handle ambiguities here yet");
406
407 if (!Found.isSingleResult())
408 return nullptr;
409
410 NamedDecl *Result = Found.getFoundDecl();
412 return Result;
413
414 return nullptr;
415}
416
418 NestedNameSpecInfo &IdInfo) {
419 QualType ObjectType = GetTypeFromParser(IdInfo.ObjectType);
420 LookupResult Found(*this, IdInfo.Identifier, IdInfo.IdentifierLoc,
422
423 // Determine where to perform name lookup
424 DeclContext *LookupCtx = nullptr;
425 bool isDependent = 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 long into the context associated with the prior nested-name-specifier.
435 LookupCtx = computeDeclContext(SS, false);
436 isDependent = isDependentScopeSpecifier(SS);
437 Found.setContextRange(SS.getRange());
438 }
439
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 false;
450
451 LookupQualifiedName(Found, LookupCtx);
452 } else if (isDependent) {
453 return false;
454 } else {
455 LookupName(Found, S);
456 }
457 Found.suppressDiagnostics();
458
459 return Found.getAsSingle<NamespaceDecl>();
460}
461
462namespace {
463
464// Callback to only accept typo corrections that can be a valid C++ member
465// initializer: either a non-static field member or a base class.
466class NestedNameSpecifierValidatorCCC final
468public:
469 explicit NestedNameSpecifierValidatorCCC(Sema &SRef)
470 : SRef(SRef) {}
471
472 bool ValidateCandidate(const TypoCorrection &candidate) override {
473 return SRef.isAcceptableNestedNameSpecifier(candidate.getCorrectionDecl());
474 }
475
476 std::unique_ptr<CorrectionCandidateCallback> clone() override {
477 return std::make_unique<NestedNameSpecifierValidatorCCC>(*this);
478 }
479
480 private:
481 Sema &SRef;
482};
483
484}
485
486/// Build a new nested-name-specifier for "identifier::", as described
487/// by ActOnCXXNestedNameSpecifier.
488///
489/// \param S Scope in which the nested-name-specifier occurs.
490/// \param IdInfo Parser information about an identifier in the
491/// nested-name-spec.
492/// \param EnteringContext If true, enter the context specified by the
493/// nested-name-specifier.
494/// \param SS Optional nested name specifier preceding the identifier.
495/// \param ScopeLookupResult Provides the result of name lookup within the
496/// scope of the nested-name-specifier that was computed at template
497/// definition time.
498/// \param ErrorRecoveryLookup Specifies if the method is called to improve
499/// error recovery and what kind of recovery is performed.
500/// \param IsCorrectedToColon If not null, suggestion of replace '::' -> ':'
501/// are allowed. The bool value pointed by this parameter is set to
502/// 'true' if the identifier is treated as if it was followed by ':',
503/// not '::'.
504/// \param OnlyNamespace If true, only considers namespaces in lookup.
505///
506/// This routine differs only slightly from ActOnCXXNestedNameSpecifier, in
507/// that it contains an extra parameter \p ScopeLookupResult, which provides
508/// the result of name lookup within the scope of the nested-name-specifier
509/// that was computed at template definition time.
510///
511/// If ErrorRecoveryLookup is true, then this call is used to improve error
512/// recovery. This means that it should not emit diagnostics, it should
513/// just return true on failure. It also means it should only return a valid
514/// scope if it *knows* that the result is correct. It should not return in a
515/// dependent context, for example. Nor will it extend \p SS with the scope
516/// specifier.
518 bool EnteringContext, CXXScopeSpec &SS,
519 NamedDecl *ScopeLookupResult,
520 bool ErrorRecoveryLookup,
521 bool *IsCorrectedToColon,
522 bool OnlyNamespace) {
523 if (IdInfo.Identifier->isEditorPlaceholder())
524 return true;
525 LookupResult Found(*this, IdInfo.Identifier, IdInfo.IdentifierLoc,
526 OnlyNamespace ? LookupNamespaceName
528 QualType ObjectType = GetTypeFromParser(IdInfo.ObjectType);
529
530 // Determine where to perform name lookup
531 DeclContext *LookupCtx = nullptr;
532 bool isDependent = false;
533 if (IsCorrectedToColon)
534 *IsCorrectedToColon = false;
535 if (!ObjectType.isNull()) {
536 // This nested-name-specifier occurs in a member access expression, e.g.,
537 // x->B::f, and we are looking into the type of the object.
538 assert(!SS.isSet() && "ObjectType and scope specifier cannot coexist");
539 LookupCtx = computeDeclContext(ObjectType);
540 isDependent = ObjectType->isDependentType();
541 } else if (SS.isSet()) {
542 // This nested-name-specifier occurs after another nested-name-specifier,
543 // so look into the context associated with the prior nested-name-specifier.
544 LookupCtx = computeDeclContext(SS, EnteringContext);
545 isDependent = isDependentScopeSpecifier(SS);
546 Found.setContextRange(SS.getRange());
547 }
548
549 bool ObjectTypeSearchedInScope = false;
550 if (LookupCtx) {
551 // Perform "qualified" name lookup into the declaration context we
552 // computed, which is either the type of the base of a member access
553 // expression or the declaration context associated with a prior
554 // nested-name-specifier.
555
556 // The declaration context must be complete.
557 if (!LookupCtx->isDependentContext() &&
558 RequireCompleteDeclContext(SS, LookupCtx))
559 return true;
560
561 LookupQualifiedName(Found, LookupCtx);
562
563 if (!ObjectType.isNull() && Found.empty()) {
564 // C++ [basic.lookup.classref]p4:
565 // If the id-expression in a class member access is a qualified-id of
566 // the form
567 //
568 // class-name-or-namespace-name::...
569 //
570 // the class-name-or-namespace-name following the . or -> operator is
571 // looked up both in the context of the entire postfix-expression and in
572 // the scope of the class of the object expression. If the name is found
573 // only in the scope of the class of the object expression, the name
574 // shall refer to a class-name. If the name is found only in the
575 // context of the entire postfix-expression, the name shall refer to a
576 // class-name or namespace-name. [...]
577 //
578 // Qualified name lookup into a class will not find a namespace-name,
579 // so we do not need to diagnose that case specifically. However,
580 // this qualified name lookup may find nothing. In that case, perform
581 // unqualified name lookup in the given scope (if available) or
582 // reconstruct the result from when name lookup was performed at template
583 // definition time.
584 if (S)
585 LookupName(Found, S);
586 else if (ScopeLookupResult)
587 Found.addDecl(ScopeLookupResult);
588
589 ObjectTypeSearchedInScope = true;
590 }
591 } else if (!isDependent) {
592 // Perform unqualified name lookup in the current scope.
593 LookupName(Found, S);
594 }
595
596 if (Found.isAmbiguous())
597 return true;
598
599 // If we performed lookup into a dependent context and did not find anything,
600 // that's fine: just build a dependent nested-name-specifier.
601 if (Found.empty() && isDependent &&
602 !(LookupCtx && LookupCtx->isRecord() &&
603 (!cast<CXXRecordDecl>(LookupCtx)->hasDefinition() ||
604 !cast<CXXRecordDecl>(LookupCtx)->hasAnyDependentBases()))) {
605 // Don't speculate if we're just trying to improve error recovery.
606 if (ErrorRecoveryLookup)
607 return true;
608
609 // We were not able to compute the declaration context for a dependent
610 // base object type or prior nested-name-specifier, so this
611 // nested-name-specifier refers to an unknown specialization. Just build
612 // a dependent nested-name-specifier.
613 SS.Extend(Context, IdInfo.Identifier, IdInfo.IdentifierLoc, IdInfo.CCLoc);
614 return false;
615 }
616
617 if (Found.empty() && !ErrorRecoveryLookup) {
618 // If identifier is not found as class-name-or-namespace-name, but is found
619 // as other entity, don't look for typos.
621 if (LookupCtx)
622 LookupQualifiedName(R, LookupCtx);
623 else if (S && !isDependent)
624 LookupName(R, S);
625 if (!R.empty()) {
626 // Don't diagnose problems with this speculative lookup.
628 // The identifier is found in ordinary lookup. If correction to colon is
629 // allowed, suggest replacement to ':'.
630 if (IsCorrectedToColon) {
631 *IsCorrectedToColon = true;
632 Diag(IdInfo.CCLoc, diag::err_nested_name_spec_is_not_class)
633 << IdInfo.Identifier << getLangOpts().CPlusPlus
634 << FixItHint::CreateReplacement(IdInfo.CCLoc, ":");
635 if (NamedDecl *ND = R.getAsSingle<NamedDecl>())
636 Diag(ND->getLocation(), diag::note_declared_at);
637 return true;
638 }
639 // Replacement '::' -> ':' is not allowed, just issue respective error.
640 Diag(R.getNameLoc(), OnlyNamespace
641 ? unsigned(diag::err_expected_namespace_name)
642 : unsigned(diag::err_expected_class_or_namespace))
643 << IdInfo.Identifier << getLangOpts().CPlusPlus;
644 if (NamedDecl *ND = R.getAsSingle<NamedDecl>())
645 Diag(ND->getLocation(), diag::note_entity_declared_at)
646 << IdInfo.Identifier;
647 return true;
648 }
649 }
650
651 if (Found.empty() && !ErrorRecoveryLookup && !getLangOpts().MSVCCompat) {
652 // We haven't found anything, and we're not recovering from a
653 // different kind of error, so look for typos.
654 DeclarationName Name = Found.getLookupName();
655 Found.clear();
656 NestedNameSpecifierValidatorCCC CCC(*this);
657 if (TypoCorrection Corrected = CorrectTypo(
658 Found.getLookupNameInfo(), Found.getLookupKind(), S, &SS, CCC,
659 CTK_ErrorRecovery, LookupCtx, EnteringContext)) {
660 if (LookupCtx) {
661 bool DroppedSpecifier =
662 Corrected.WillReplaceSpecifier() &&
663 Name.getAsString() == Corrected.getAsString(getLangOpts());
664 if (DroppedSpecifier)
665 SS.clear();
666 diagnoseTypo(Corrected, PDiag(diag::err_no_member_suggest)
667 << Name << LookupCtx << DroppedSpecifier
668 << SS.getRange());
669 } else
670 diagnoseTypo(Corrected, PDiag(diag::err_undeclared_var_use_suggest)
671 << Name);
672
673 if (Corrected.getCorrectionSpecifier())
674 SS.MakeTrivial(Context, Corrected.getCorrectionSpecifier(),
675 SourceRange(Found.getNameLoc()));
676
677 if (NamedDecl *ND = Corrected.getFoundDecl())
678 Found.addDecl(ND);
679 Found.setLookupName(Corrected.getCorrection());
680 } else {
681 Found.setLookupName(IdInfo.Identifier);
682 }
683 }
684
685 NamedDecl *SD =
686 Found.isSingleResult() ? Found.getRepresentativeDecl() : nullptr;
687 bool IsExtension = false;
688 bool AcceptSpec = isAcceptableNestedNameSpecifier(SD, &IsExtension);
689 if (!AcceptSpec && IsExtension) {
690 AcceptSpec = true;
691 Diag(IdInfo.IdentifierLoc, diag::ext_nested_name_spec_is_enum);
692 }
693 if (AcceptSpec) {
694 if (!ObjectType.isNull() && !ObjectTypeSearchedInScope &&
696 // C++03 [basic.lookup.classref]p4:
697 // [...] If the name is found in both contexts, the
698 // class-name-or-namespace-name shall refer to the same entity.
699 //
700 // We already found the name in the scope of the object. Now, look
701 // into the current scope (the scope of the postfix-expression) to
702 // see if we can find the same name there. As above, if there is no
703 // scope, reconstruct the result from the template instantiation itself.
704 //
705 // Note that C++11 does *not* perform this redundant lookup.
706 NamedDecl *OuterDecl;
707 if (S) {
708 LookupResult FoundOuter(*this, IdInfo.Identifier, IdInfo.IdentifierLoc,
710 LookupName(FoundOuter, S);
711 OuterDecl = FoundOuter.getAsSingle<NamedDecl>();
712 } else
713 OuterDecl = ScopeLookupResult;
714
715 if (isAcceptableNestedNameSpecifier(OuterDecl) &&
716 OuterDecl->getCanonicalDecl() != SD->getCanonicalDecl() &&
717 (!isa<TypeDecl>(OuterDecl) || !isa<TypeDecl>(SD) ||
719 Context.getTypeDeclType(cast<TypeDecl>(OuterDecl)),
720 Context.getTypeDeclType(cast<TypeDecl>(SD))))) {
721 if (ErrorRecoveryLookup)
722 return true;
723
724 Diag(IdInfo.IdentifierLoc,
725 diag::err_nested_name_member_ref_lookup_ambiguous)
726 << IdInfo.Identifier;
727 Diag(SD->getLocation(), diag::note_ambig_member_ref_object_type)
728 << ObjectType;
729 Diag(OuterDecl->getLocation(), diag::note_ambig_member_ref_scope);
730
731 // Fall through so that we'll pick the name we found in the object
732 // type, since that's probably what the user wanted anyway.
733 }
734 }
735
736 if (auto *TD = dyn_cast_or_null<TypedefNameDecl>(SD))
737 MarkAnyDeclReferenced(TD->getLocation(), TD, /*OdrUse=*/false);
738
739 // If we're just performing this lookup for error-recovery purposes,
740 // don't extend the nested-name-specifier. Just return now.
741 if (ErrorRecoveryLookup)
742 return false;
743
744 // The use of a nested name specifier may trigger deprecation warnings.
745 DiagnoseUseOfDecl(SD, IdInfo.CCLoc);
746
747 if (NamespaceDecl *Namespace = dyn_cast<NamespaceDecl>(SD)) {
748 SS.Extend(Context, Namespace, IdInfo.IdentifierLoc, IdInfo.CCLoc);
749 return false;
750 }
751
752 if (NamespaceAliasDecl *Alias = dyn_cast<NamespaceAliasDecl>(SD)) {
753 SS.Extend(Context, Alias, IdInfo.IdentifierLoc, IdInfo.CCLoc);
754 return false;
755 }
756
757 QualType T =
758 Context.getTypeDeclType(cast<TypeDecl>(SD->getUnderlyingDecl()));
759
760 if (T->isEnumeralType())
761 Diag(IdInfo.IdentifierLoc, diag::warn_cxx98_compat_enum_nested_name_spec);
762
763 TypeLocBuilder TLB;
764 if (const auto *USD = dyn_cast<UsingShadowDecl>(SD)) {
765 T = Context.getUsingType(USD, T);
767 } else if (isa<InjectedClassNameType>(T)) {
768 InjectedClassNameTypeLoc InjectedTL
770 InjectedTL.setNameLoc(IdInfo.IdentifierLoc);
771 } else if (isa<RecordType>(T)) {
772 RecordTypeLoc RecordTL = TLB.push<RecordTypeLoc>(T);
773 RecordTL.setNameLoc(IdInfo.IdentifierLoc);
774 } else if (isa<TypedefType>(T)) {
775 TypedefTypeLoc TypedefTL = TLB.push<TypedefTypeLoc>(T);
776 TypedefTL.setNameLoc(IdInfo.IdentifierLoc);
777 } else if (isa<EnumType>(T)) {
778 EnumTypeLoc EnumTL = TLB.push<EnumTypeLoc>(T);
779 EnumTL.setNameLoc(IdInfo.IdentifierLoc);
780 } else if (isa<TemplateTypeParmType>(T)) {
781 TemplateTypeParmTypeLoc TemplateTypeTL
783 TemplateTypeTL.setNameLoc(IdInfo.IdentifierLoc);
784 } else if (isa<UnresolvedUsingType>(T)) {
785 UnresolvedUsingTypeLoc UnresolvedTL
787 UnresolvedTL.setNameLoc(IdInfo.IdentifierLoc);
788 } else if (isa<SubstTemplateTypeParmType>(T)) {
791 TL.setNameLoc(IdInfo.IdentifierLoc);
792 } else if (isa<SubstTemplateTypeParmPackType>(T)) {
795 TL.setNameLoc(IdInfo.IdentifierLoc);
796 } else {
797 llvm_unreachable("Unhandled TypeDecl node in nested-name-specifier");
798 }
799
801 IdInfo.CCLoc);
802 return false;
803 }
804
805 // Otherwise, we have an error case. If we don't want diagnostics, just
806 // return an error now.
807 if (ErrorRecoveryLookup)
808 return true;
809
810 // If we didn't find anything during our lookup, try again with
811 // ordinary name lookup, which can help us produce better error
812 // messages.
813 if (Found.empty()) {
815 LookupName(Found, S);
816 }
817
818 // In Microsoft mode, if we are within a templated function and we can't
819 // resolve Identifier, then extend the SS with Identifier. This will have
820 // the effect of resolving Identifier during template instantiation.
821 // The goal is to be able to resolve a function call whose
822 // nested-name-specifier is located inside a dependent base class.
823 // Example:
824 //
825 // class C {
826 // public:
827 // static void foo2() { }
828 // };
829 // template <class T> class A { public: typedef C D; };
830 //
831 // template <class T> class B : public A<T> {
832 // public:
833 // void foo() { D::foo2(); }
834 // };
835 if (getLangOpts().MSVCCompat) {
836 DeclContext *DC = LookupCtx ? LookupCtx : CurContext;
837 if (DC->isDependentContext() && DC->isFunctionOrMethod()) {
838 CXXRecordDecl *ContainingClass = dyn_cast<CXXRecordDecl>(DC->getParent());
839 if (ContainingClass && ContainingClass->hasAnyDependentBases()) {
840 Diag(IdInfo.IdentifierLoc,
841 diag::ext_undeclared_unqual_id_with_dependent_base)
842 << IdInfo.Identifier << ContainingClass;
843 SS.Extend(Context, IdInfo.Identifier, IdInfo.IdentifierLoc,
844 IdInfo.CCLoc);
845 return false;
846 }
847 }
848 }
849
850 if (!Found.empty()) {
851 if (TypeDecl *TD = Found.getAsSingle<TypeDecl>()) {
852 Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace)
853 << Context.getTypeDeclType(TD) << getLangOpts().CPlusPlus;
854 } else if (Found.getAsSingle<TemplateDecl>()) {
855 ParsedType SuggestedType;
856 DiagnoseUnknownTypeName(IdInfo.Identifier, IdInfo.IdentifierLoc, S, &SS,
857 SuggestedType);
858 } else {
859 Diag(IdInfo.IdentifierLoc, diag::err_expected_class_or_namespace)
860 << IdInfo.Identifier << getLangOpts().CPlusPlus;
861 if (NamedDecl *ND = Found.getAsSingle<NamedDecl>())
862 Diag(ND->getLocation(), diag::note_entity_declared_at)
863 << IdInfo.Identifier;
864 }
865 } else if (SS.isSet())
866 Diag(IdInfo.IdentifierLoc, diag::err_no_member) << IdInfo.Identifier
867 << LookupCtx << SS.getRange();
868 else
869 Diag(IdInfo.IdentifierLoc, diag::err_undeclared_var_use)
870 << IdInfo.Identifier;
871
872 return true;
873}
874
876 bool EnteringContext, CXXScopeSpec &SS,
877 bool *IsCorrectedToColon,
878 bool OnlyNamespace) {
879 if (SS.isInvalid())
880 return true;
881
882 return BuildCXXNestedNameSpecifier(S, IdInfo, EnteringContext, SS,
883 /*ScopeLookupResult=*/nullptr, false,
884 IsCorrectedToColon, OnlyNamespace);
885}
886
888 const DeclSpec &DS,
889 SourceLocation ColonColonLoc) {
891 return true;
892
894
896 if (T.isNull())
897 return true;
898
899 if (!T->isDependentType() && !T->getAs<TagType>()) {
900 Diag(DS.getTypeSpecTypeLoc(), diag::err_expected_class_or_namespace)
901 << T << getLangOpts().CPlusPlus;
902 return true;
903 }
904
905 TypeLocBuilder TLB;
906 DecltypeTypeLoc DecltypeTL = TLB.push<DecltypeTypeLoc>(T);
907 DecltypeTL.setDecltypeLoc(DS.getTypeSpecTypeLoc());
908 DecltypeTL.setRParenLoc(DS.getTypeofParensRange().getEnd());
910 ColonColonLoc);
911 return false;
912}
913
914/// IsInvalidUnlessNestedName - This method is used for error recovery
915/// purposes to determine whether the specified identifier is only valid as
916/// a nested name specifier, for example a namespace name. It is
917/// conservatively correct to always return false from this method.
918///
919/// The arguments are the same as those passed to ActOnCXXNestedNameSpecifier.
921 NestedNameSpecInfo &IdInfo,
922 bool EnteringContext) {
923 if (SS.isInvalid())
924 return false;
925
926 return !BuildCXXNestedNameSpecifier(S, IdInfo, EnteringContext, SS,
927 /*ScopeLookupResult=*/nullptr, true);
928}
929
931 CXXScopeSpec &SS,
932 SourceLocation TemplateKWLoc,
933 TemplateTy OpaqueTemplate,
934 SourceLocation TemplateNameLoc,
935 SourceLocation LAngleLoc,
936 ASTTemplateArgsPtr TemplateArgsIn,
937 SourceLocation RAngleLoc,
938 SourceLocation CCLoc,
939 bool EnteringContext) {
940 if (SS.isInvalid())
941 return true;
942
943 TemplateName Template = OpaqueTemplate.get();
944
945 // Translate the parser's template argument list in our AST format.
946 TemplateArgumentListInfo TemplateArgs(LAngleLoc, RAngleLoc);
947 translateTemplateArguments(TemplateArgsIn, TemplateArgs);
948
950 if (DTN && DTN->isIdentifier()) {
951 // Handle a dependent template specialization for which we cannot resolve
952 // the template name.
953 assert(DTN->getQualifier() == SS.getScopeRep());
955 ETK_None, DTN->getQualifier(), DTN->getIdentifier(),
956 TemplateArgs.arguments());
957
958 // Create source-location information for this type.
959 TypeLocBuilder Builder;
964 SpecTL.setTemplateKeywordLoc(TemplateKWLoc);
965 SpecTL.setTemplateNameLoc(TemplateNameLoc);
966 SpecTL.setLAngleLoc(LAngleLoc);
967 SpecTL.setRAngleLoc(RAngleLoc);
968 for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
969 SpecTL.setArgLocInfo(I, TemplateArgs[I].getLocInfo());
970
971 SS.Extend(Context, TemplateKWLoc, Builder.getTypeLocInContext(Context, T),
972 CCLoc);
973 return false;
974 }
975
976 // If we assumed an undeclared identifier was a template name, try to
977 // typo-correct it now.
978 if (Template.getAsAssumedTemplateName() &&
979 resolveAssumedTemplateNameAsType(S, Template, TemplateNameLoc))
980 return true;
981
982 TemplateDecl *TD = Template.getAsTemplateDecl();
983 if (Template.getAsOverloadedTemplate() || DTN ||
984 isa<FunctionTemplateDecl>(TD) || isa<VarTemplateDecl>(TD)) {
985 SourceRange R(TemplateNameLoc, RAngleLoc);
986 if (SS.getRange().isValid())
987 R.setBegin(SS.getRange().getBegin());
988
989 Diag(CCLoc, diag::err_non_type_template_in_nested_name_specifier)
990 << (TD && isa<VarTemplateDecl>(TD)) << Template << R;
991 NoteAllFoundTemplates(Template);
992 return true;
993 }
994
995 // We were able to resolve the template name to an actual template.
996 // Build an appropriate nested-name-specifier.
997 QualType T = CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
998 if (T.isNull())
999 return true;
1000
1001 // Alias template specializations can produce types which are not valid
1002 // nested name specifiers.
1003 if (!T->isDependentType() && !T->getAs<TagType>()) {
1004 Diag(TemplateNameLoc, diag::err_nested_name_spec_non_tag) << T;
1005 NoteAllFoundTemplates(Template);
1006 return true;
1007 }
1008
1009 // Provide source-location information for the template specialization type.
1010 TypeLocBuilder Builder;
1012 = Builder.push<TemplateSpecializationTypeLoc>(T);
1013 SpecTL.setTemplateKeywordLoc(TemplateKWLoc);
1014 SpecTL.setTemplateNameLoc(TemplateNameLoc);
1015 SpecTL.setLAngleLoc(LAngleLoc);
1016 SpecTL.setRAngleLoc(RAngleLoc);
1017 for (unsigned I = 0, N = TemplateArgs.size(); I != N; ++I)
1018 SpecTL.setArgLocInfo(I, TemplateArgs[I].getLocInfo());
1019
1020
1021 SS.Extend(Context, TemplateKWLoc, Builder.getTypeLocInContext(Context, T),
1022 CCLoc);
1023 return false;
1024}
1025
1026namespace {
1027 /// A structure that stores a nested-name-specifier annotation,
1028 /// including both the nested-name-specifier
1029 struct NestedNameSpecifierAnnotation {
1031 };
1032}
1033
1035 if (SS.isEmpty() || SS.isInvalid())
1036 return nullptr;
1037
1038 void *Mem = Context.Allocate(
1039 (sizeof(NestedNameSpecifierAnnotation) + SS.location_size()),
1040 alignof(NestedNameSpecifierAnnotation));
1041 NestedNameSpecifierAnnotation *Annotation
1042 = new (Mem) NestedNameSpecifierAnnotation;
1043 Annotation->NNS = SS.getScopeRep();
1044 memcpy(Annotation + 1, SS.location_data(), SS.location_size());
1045 return Annotation;
1046}
1047
1049 SourceRange AnnotationRange,
1050 CXXScopeSpec &SS) {
1051 if (!AnnotationPtr) {
1052 SS.SetInvalid(AnnotationRange);
1053 return;
1054 }
1055
1056 NestedNameSpecifierAnnotation *Annotation
1057 = static_cast<NestedNameSpecifierAnnotation *>(AnnotationPtr);
1058 SS.Adopt(NestedNameSpecifierLoc(Annotation->NNS, Annotation + 1));
1059}
1060
1062 assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
1063
1064 // Don't enter a declarator context when the current context is an Objective-C
1065 // declaration.
1066 if (isa<ObjCContainerDecl>(CurContext) || isa<ObjCMethodDecl>(CurContext))
1067 return false;
1068
1069 NestedNameSpecifier *Qualifier = SS.getScopeRep();
1070
1071 // There are only two places a well-formed program may qualify a
1072 // declarator: first, when defining a namespace or class member
1073 // out-of-line, and second, when naming an explicitly-qualified
1074 // friend function. The latter case is governed by
1075 // C++03 [basic.lookup.unqual]p10:
1076 // In a friend declaration naming a member function, a name used
1077 // in the function declarator and not part of a template-argument
1078 // in a template-id is first looked up in the scope of the member
1079 // function's class. If it is not found, or if the name is part of
1080 // a template-argument in a template-id, the look up is as
1081 // described for unqualified names in the definition of the class
1082 // granting friendship.
1083 // i.e. we don't push a scope unless it's a class member.
1084
1085 switch (Qualifier->getKind()) {
1089 // These are always namespace scopes. We never want to enter a
1090 // namespace scope from anything but a file context.
1092
1097 // These are never namespace scopes.
1098 return true;
1099 }
1100
1101 llvm_unreachable("Invalid NestedNameSpecifier::Kind!");
1102}
1103
1104/// ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global
1105/// scope or nested-name-specifier) is parsed, part of a declarator-id.
1106/// After this method is called, according to [C++ 3.4.3p3], names should be
1107/// looked up in the declarator-id's scope, until the declarator is parsed and
1108/// ActOnCXXExitDeclaratorScope is called.
1109/// The 'SS' should be a non-empty valid CXXScopeSpec.
1111 assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
1112
1113 if (SS.isInvalid()) return true;
1114
1115 DeclContext *DC = computeDeclContext(SS, true);
1116 if (!DC) return true;
1117
1118 // Before we enter a declarator's context, we need to make sure that
1119 // it is a complete declaration context.
1120 if (!DC->isDependentContext() && RequireCompleteDeclContext(SS, DC))
1121 return true;
1122
1124
1125 // Rebuild the nested name specifier for the new scope.
1126 if (DC->isDependentContext())
1128
1129 return false;
1130}
1131
1132/// ActOnCXXExitDeclaratorScope - Called when a declarator that previously
1133/// invoked ActOnCXXEnterDeclaratorScope(), is finished. 'SS' is the same
1134/// CXXScopeSpec that was passed to ActOnCXXEnterDeclaratorScope as well.
1135/// Used to indicate that names should revert to being looked up in the
1136/// defining scope.
1138 assert(SS.isSet() && "Parser passed invalid CXXScopeSpec.");
1139 if (SS.isInvalid())
1140 return;
1141 assert(!SS.isInvalid() && computeDeclContext(SS, true) &&
1142 "exiting declarator scope we never really entered");
1144}
Defines the clang::ASTContext interface.
Defines the C++ template declaration subclasses.
Defines the clang::Expr interface and subclasses for C++ expressions.
Implements a partial diagnostic that can be emitted anwyhere in a DiagnosticBuilder stream.
static CXXRecordDecl * getCurrentInstantiationOf(QualType T, DeclContext *CurContext)
Find the current instantiation that associated with the given type.
enum clang::format::@1178::AnnotatingParser::Context::@327 ContextType
__DEVICE__ void * memcpy(void *__a, const void *__b, size_t __c)
QualType getUsingType(const UsingShadowDecl *Found, QualType Underlying) const
TranslationUnitDecl * getTranslationUnitDecl() const
Definition: ASTContext.h:1060
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:2505
bool hasSameType(QualType T1, QualType T2) const
Determine whether the given types T1 and T2 are equivalent.
Definition: ASTContext.h:2521
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:1559
const LangOptions & getLangOpts() const
Definition: ASTContext.h:762
void * Allocate(size_t Size, unsigned Align=8) const
Definition: ASTContext.h:705
Represents a static or instance method of a struct/union/class.
Definition: DeclCXX.h:2018
Represents a C++ struct/union/class.
Definition: DeclCXX.h:254
bool hasAnyDependentBases() const
Determine whether this class has any dependent base classes which are not the current instantiation.
Definition: DeclCXX.cpp:566
unsigned getNumBases() const
Retrieves the number of base classes of this class.
Definition: DeclCXX.h:596
Represents a C++ nested-name-specifier or a global scope specifier.
Definition: DeclSpec.h:73
char * location_data() const
Retrieve the data associated with the source-location information.
Definition: DeclSpec.h:235
void MakeTrivial(ASTContext &Context, NestedNameSpecifier *Qualifier, SourceRange R)
Make a new nested-name-specifier from incomplete source-location information.
Definition: DeclSpec.cpp:126
SourceLocation getLastQualifierNameLoc() const
Retrieve the location of the name in the last qualifier in this nested name specifier.
Definition: DeclSpec.cpp:145
SourceRange getRange() const
Definition: DeclSpec.h:79
void MakeGlobal(ASTContext &Context, SourceLocation ColonColonLoc)
Turn this (empty) nested-name-specifier into the global nested-name-specifier '::'.
Definition: DeclSpec.cpp:104
bool isSet() const
Deprecated.
Definition: DeclSpec.h:227
ArrayRef< TemplateParameterList * > getTemplateParamLists() const
Definition: DeclSpec.h:89
NestedNameSpecifierLoc getWithLocInContext(ASTContext &Context) const
Retrieve a nested-name-specifier with location information, copied into the given AST context.
Definition: DeclSpec.cpp:152
NestedNameSpecifier * getScopeRep() const
Retrieve the representation of the nested-name-specifier.
Definition: DeclSpec.h:94
void SetInvalid(SourceRange R)
Indicate that this nested-name-specifier is invalid.
Definition: DeclSpec.h:217
unsigned location_size() const
Retrieve the size of the data associated with source-location information.
Definition: DeclSpec.h:239
void MakeSuper(ASTContext &Context, CXXRecordDecl *RD, SourceLocation SuperLoc, SourceLocation ColonColonLoc)
Turns this (empty) nested-name-specifier into '__super' nested-name-specifier.
Definition: DeclSpec.cpp:114
void Extend(ASTContext &Context, SourceLocation TemplateKWLoc, TypeLoc TL, SourceLocation ColonColonLoc)
Extend the current nested-name-specifier by another nested-name-specifier component of the form 'type...
Definition: DeclSpec.cpp:54
bool isInvalid() const
An error occurred during parsing of the scope specifier.
Definition: DeclSpec.h:212
bool isEmpty() const
No scope specifier.
Definition: DeclSpec.h:207
void Adopt(NestedNameSpecifierLoc Other)
Adopt an existing nested-name-specifier (with source-range information).
Definition: DeclSpec.cpp:132
Declaration of a class template.
Base class for callback objects used by Sema::CorrectTypo to check the validity of a potential typo c...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
Definition: DeclBase.h:1393
DeclContext * getParent()
getParent - Returns the containing DeclContext.
Definition: DeclBase.h:1933
bool isFileContext() const
Definition: DeclBase.h:2003
bool isDependentContext() const
Determines whether this context is dependent on a template parameter.
Definition: DeclBase.cpp:1186
bool isRecord() const
Definition: DeclBase.h:2012
DeclContext * getRedeclContext()
getRedeclContext - Retrieve the context in which an entity conflicts with other entities of the same ...
Definition: DeclBase.cpp:1841
bool isFunctionOrMethod() const
Definition: DeclBase.h:1985
Captures information about "declaration specifiers".
Definition: DeclSpec.h:246
TST getTypeSpecType() const
Definition: DeclSpec.h:511
Expr * getRepAsExpr() const
Definition: DeclSpec.h:529
static const TST TST_decltype
Definition: DeclSpec.h:310
SourceLocation getTypeSpecTypeLoc() const
Definition: DeclSpec.h:549
static const TST TST_error
Definition: DeclSpec.h:322
SourceRange getTypeofParensRange() const
Definition: DeclSpec.h:559
SourceLocation getLocation() const
Definition: DeclBase.h:432
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
Definition: DeclBase.h:943
The name of a declaration.
void setRParenLoc(SourceLocation Loc)
Definition: TypeLoc.h:2040
void setDecltypeLoc(SourceLocation Loc)
Definition: TypeLoc.h:2037
Represents a dependent template name that cannot be resolved prior to template instantiation.
Definition: TemplateName.h:488
bool isIdentifier() const
Determine whether this template name refers to an identifier.
Definition: TemplateName.h:547
NestedNameSpecifier * getQualifier() const
Return the nested name specifier that qualifies this name.
Definition: TemplateName.h:544
const IdentifierInfo * getIdentifier() const
Returns the identifier to which this template name refers.
Definition: TemplateName.h:550
void setQualifierLoc(NestedNameSpecifierLoc QualifierLoc)
Definition: TypeLoc.h:2419
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2439
void setElaboratedKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:2407
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2463
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:2455
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:2471
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:2447
Represents an enum.
Definition: Decl.h:3720
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this enumeration is an instantiation of a member enumeration of a class template specialization,...
Definition: Decl.h:3979
EnumDecl * getInstantiatedFromMemberEnum() const
Returns the enumeration (declared within the template) from which this enumeration type was instantia...
Definition: Decl.cpp:4653
Wrapper for source info for enum types.
Definition: TypeLoc.h:737
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:693
Represents the results of name lookup.
Definition: Lookup.h:46
LLVM_ATTRIBUTE_REINITIALIZES void clear()
Clears out any current state.
Definition: Lookup.h:580
DeclClass * getAsSingle() const
Definition: Lookup.h:533
void setContextRange(SourceRange SR)
Sets a 'context' source range.
Definition: Lookup.h:619
void addDecl(NamedDecl *D)
Add a declaration to these results with its natural access.
Definition: Lookup.h:452
void setLookupName(DeclarationName Name)
Sets the name to look up.
Definition: Lookup.h:248
bool empty() const
Return true if no decls were found.
Definition: Lookup.h:339
SourceLocation getNameLoc() const
Gets the location of the identifier.
Definition: Lookup.h:632
NamedDecl * getFoundDecl() const
Fetch the unique decl found by this lookup.
Definition: Lookup.h:543
bool isAmbiguous() const
Definition: Lookup.h:301
bool isSingleResult() const
Determines if this names a single result which is not an unresolved value using decl.
Definition: Lookup.h:308
Sema::LookupNameKind getLookupKind() const
Gets the kind of lookup to perform.
Definition: Lookup.h:253
NamedDecl * getRepresentativeDecl() const
Fetches a representative decl. Useful for lazy diagnostics.
Definition: Lookup.h:550
void suppressDiagnostics()
Suppress the diagnostics that would normally fire because of this lookup.
Definition: Lookup.h:609
DeclarationName getLookupName() const
Gets the name to look up.
Definition: Lookup.h:243
const DeclarationNameInfo & getLookupNameInfo() const
Gets the name info to look up.
Definition: Lookup.h:233
Provides information a specialization of a member of a class template, which may be a member function...
Definition: DeclTemplate.h:629
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine what kind of template specialization this is.
Definition: DeclTemplate.h:651
This represents a decl that may have a name.
Definition: Decl.h:247
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
Definition: Decl.h:457
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:274
Represents a C++ namespace alias.
Definition: DeclCXX.h:3057
NamespaceDecl * getNamespace()
Retrieve the namespace declaration aliased by this directive.
Definition: DeclCXX.h:3129
Represent a C++ namespace.
Definition: Decl.h:542
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
A (possibly-)qualified type.
Definition: Type.h:736
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:803
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6649
Wrapper for source info for record types.
Definition: TypeLoc.h:729
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:4835
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:41
Sema - This implements semantic analysis and AST building for C.
Definition: Sema.h:356
bool hasReachableDefinition(NamedDecl *D, NamedDecl **Suggested, bool OnlyNeedComplete=false)
Determine if D has a reachable definition.
Definition: SemaType.cpp:8912
Scope * getCurScope() const
Retrieve the parser's current scope.
Definition: Sema.h:13794
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:4293
@ LookupNestedNameSpecifierName
Look up of a name that precedes the '::' scope resolution operator in C++.
Definition: Sema.h:4312
@ LookupNamespaceName
Look up a namespace name within a C++ using directive or namespace alias definition,...
Definition: Sema.h:4316
SemaDiagnosticBuilder Diag(SourceLocation Loc, unsigned DiagID, bool DeferHint=false)
Emit a diagnostic.
Definition: Sema.cpp:1884
MultiLevelTemplateArgumentList getTemplateInstantiationArgs(const NamedDecl *D, bool Final=false, const TemplateArgumentList *Innermost=nullptr, bool RelativeToPrimary=false, const FunctionDecl *Pattern=nullptr, bool ForConstraintInstantiation=false, bool SkipForSpecialization=false)
Retrieve the template argument list(s) that should be used to instantiate the definition of the given...
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:407
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:1645
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:2354
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:20122
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:1414
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...
void diagnoseMissingImport(SourceLocation Loc, 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...
DeclContext * CurContext
CurContext - This is the current declaration context of parsing.
Definition: Sema.h:419
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.
bool isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS, NestedNameSpecInfo &IdInfo)
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:1379
DeclContext * computeDeclContext(QualType T)
Compute the DeclContext that is associated with the given type.
QualType CheckTemplateIdType(TemplateName Template, SourceLocation TemplateLoc, TemplateArgumentListInfo &TemplateArgs)
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:222
@ CTK_ErrorRecovery
Definition: Sema.h:4531
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:9347
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:8773
PartialDiagnostic PDiag(unsigned DiagID=0)
Build a partial diagnostic.
Definition: SemaInternal.h:24
bool LookupQualifiedName(LookupResult &R, DeclContext *LookupCtx, bool InUnqualifiedLookup=false)
Perform qualified name lookup into a given context.
bool isDependentScopeSpecifier(const CXXScopeSpec &SS)
bool ActOnCXXEnterDeclaratorScope(Scope *S, CXXScopeSpec &SS)
ActOnCXXEnterDeclaratorScope - Called when a C++ scope specifier (global scope or nested-name-specifi...
bool resolveAssumedTemplateNameAsType(Scope *S, TemplateName &Name, SourceLocation NameLoc, bool Diagnose=true)
bool InstantiateEnum(SourceLocation PointOfInstantiation, EnumDecl *Instantiation, EnumDecl *Pattern, const MultiLevelTemplateArgumentList &TemplateArgs, TemplateSpecializationKind TSK)
Instantiate the definition of an enum from a given pattern.
bool LookupName(LookupResult &R, Scope *S, bool AllowBuiltinCreation=false, bool ForceNoCPlusPlus=false)
Perform unqualified name lookup starting from a given scope.
static QualType GetTypeFromParser(ParsedType Ty, TypeSourceInfo **TInfo=nullptr)
Definition: SemaType.cpp:3121
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:720
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:852
Wrapper for substituted template type parameters.
Definition: TypeLoc.h:845
Represents the declaration of a struct/union/class/enum.
Definition: Decl.h:3440
bool isBeingDefined() const
Return true if this decl is currently being defined.
Definition: Decl.h:3563
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
Definition: Decl.h:3543
TagDecl * getDecl() const
Definition: Type.cpp:3610
A convenient class for passing around template argument information.
Definition: TemplateBase.h:590
llvm::ArrayRef< TemplateArgumentLoc > arguments() const
Definition: TemplateBase.h:618
The base class of all kinds of template declarations (e.g., class, function, etc.).
Definition: DeclTemplate.h:407
Represents a C++ template name within the type system.
Definition: TemplateName.h:202
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known.
DependentTemplateName * getAsDependentTemplateName() const
Retrieve the underlying dependent template name structure, if any.
OverloadedTemplateStorage * getAsOverloadedTemplate() const
Retrieve the underlying, overloaded function template declarations that this template name refers to,...
AssumedTemplateStorage * getAsAssumedTemplateName() const
Retrieve information on a name that has been assumed to be a template-name in order to permit a call ...
Stores a list of template parameters for a TemplateDecl and its derived classes.
Definition: DeclTemplate.h:73
unsigned getDepth() const
Get the depth of this template parameter list in the set of template parameter lists.
void setArgLocInfo(unsigned i, TemplateArgumentLocInfo AI)
Definition: TypeLoc.h:1640
void setTemplateKeywordLoc(SourceLocation Loc)
Definition: TypeLoc.h:1616
void setTemplateNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:1657
void setLAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1624
void setRAngleLoc(SourceLocation Loc)
Definition: TypeLoc.h:1632
Represents a type template specialization; the template must be a class template, a type alias templa...
Definition: Type.h:5377
Wrapper for template type parameters.
Definition: TypeLoc.h:746
Represents a declaration of a type.
Definition: Decl.h:3248
const Type * getTypeForDecl() const
Definition: Decl.h:3272
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 setNameLoc(SourceLocation Loc)
Definition: TypeLoc.h:527
The base class of the type hierarchy.
Definition: Type.h:1566
bool isEnumeralType() const
Definition: Type.h:7004
bool isDependentType() const
Whether this type is a dependent type, meaning that its definition somehow depends on a template para...
Definition: Type.h:2317
QualType getCanonicalTypeInternal() const
Definition: Type.h:2597
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7424
Base class for declarations which introduce a typedef-name.
Definition: Decl.h:3290
Wrapper for source info for typedefs.
Definition: TypeLoc.h:681
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:704
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
@ CPlusPlus
Definition: LangStandard.h:53
@ CPlusPlus11
Definition: LangStandard.h:54
@ Result
The result type of a method or function.
@ TSK_ExplicitSpecialization
This template specialization was declared or defined by an explicit specialization (C++ [temp....
Definition: Specifiers.h:186
@ TSK_ImplicitInstantiation
This template specialization was implicitly instantiated from a template.
Definition: Specifiers.h:182
@ ETK_None
No keyword precedes the qualified type name.
Definition: Type.h:5601
Keeps information about an identifier in a nested-name-spec.
Definition: Sema.h:6931
IdentifierInfo * Identifier
The identifier preceding the '::'.
Definition: Sema.h:6937
SourceLocation IdentifierLoc
The location of the identifier.
Definition: Sema.h:6940
SourceLocation CCLoc
The location of the '::'.
Definition: Sema.h:6943
ParsedType ObjectType
The type of the object, if we're parsing nested-name-specifier in a member access expression.
Definition: Sema.h:6934