Lines Matching +full:oe +full:- +full:extra +full:- +full:delay

1 //===--------------------- SemaLookup.cpp - Name Lookup  ------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements name lookup for C, C++, Objective-C, and
10 // Objective-C++.
12 //===----------------------------------------------------------------------===//
112 // both the using-directive and the nominated namespace.
113 DeclContext *InnermostFileDC = InnermostFileScope->getEntity();
114 assert(InnermostFileDC && InnermostFileDC->isFileContext());
116 for (; S; S = S->getParent()) {
118 // A using-directive shall not appear in class scope, but may
120 DeclContext *Ctx = S->getEntity();
121 if (Ctx && Ctx->isFileContext()) {
123 } else if (!Ctx || Ctx->isFunctionOrMethod()) {
124 for (auto *I : S->using_directives())
149 DeclContext *NS = UD->getNominatedNamespace();
163 for (auto *UD : DC->using_directives()) {
164 DeclContext *NS = UD->getNominatedNamespace();
180 // The using-directive is transitive: if a scope contains a
181 // using-directive that nominates a second namespace that itself
182 // contains using-directives, the effect is as if the
183 // using-directives from the second namespace also appeared in
188 DeclContext *Common = UD->getNominatedNamespace();
189 while (!Common->Encloses(EffectiveDC))
190 Common = Common->getParent();
191 Common = Common->getPrimaryContext();
193 list.push_back(UnqualUsingEntry(UD->getNominatedNamespace(), Common));
206 DC->getPrimaryContext(),
308 // operators, make sure that the implicitly-declared new and delete
325 if (unsigned BuiltinID = Id->getBuiltinID()) {
338 isa<FunctionTemplateDecl>((*begin())->getUnderlyingDecl())));
357 // For function-local declarations, use that function as the context. This
360 if (const DeclContext *DC = D->getLexicalDeclContext();
361 DC->isFunctionOrMethod())
366 return D->getDeclContext()->getRedeclContext();
380 const auto *DUnderlying = D->getUnderlyingDecl();
381 const auto *EUnderlying = Existing->getUnderlyingDecl();
390 // class-name in a destructor declaration.
391 if (DUnderlying->getCanonicalDecl() != EUnderlying->getCanonicalDecl()) {
405 unsigned DMin = DFD->getMinRequiredArguments();
406 unsigned EMin = EFD->getMinRequiredArguments();
417 unsigned DMin = DTD->getTemplateParameters()->getMinRequiredArguments();
418 unsigned EMin = ETD->getTemplateParameters()->getMinRequiredArguments();
427 for (unsigned I = DMin, N = DTD->getTemplateParameters()->size();
430 ETD->getTemplateParameters()->getParam(I)) &&
432 DTD->getTemplateParameters()->getParam(I)))
441 if (EVD->getType()->isIncompleteType() &&
442 !DVD->getType()->isIncompleteType()) {
457 for (const Decl *Prev = DUnderlying->getPreviousDecl(); Prev;
458 Prev = Prev->getPreviousDecl())
470 // the same variable, non-static data member, or enumerator, or all refer
478 D = D->getUnderlyingDecl();
498 const NamedDecl *D = (*Decls.begin())->getUnderlyingDecl();
506 // Don't do any extra resolution if we've already resolved as ambiguous.
522 const NamedDecl *D = Decls[I]->getUnderlyingDecl();
523 D = cast<NamedDecl>(D->getCanonicalDecl());
527 if ((D->isInvalidDecl() || isa<HLSLBufferDecl>(D)) &&
528 N - RemovedDecls.count() > 1) {
543 if (canHideTag(OtherDecl) && !OtherDecl->isInvalidDecl() &&
544 getContextForScopeMatching(OtherDecl)->Equals(
567 ExistingI = UniqueResult.first->second;
571 // For non-type declarations, check for a prior lookup result naming this
577 ExistingI = UniqueResult.first->second;
616 if (D->isPlaceholderVar(getSema().getLangOpts()) &&
637 Decls[I] = Decls[--N];
659 for (DeclContext::lookup_iterator DI = I->Decls, DE = DI.end(); DI != DE;
666 Paths->swap(P);
674 Paths->swap(P);
687 (*I)->print(Out, 2);
695 D->dump();
809 /// non-null <Index, Len> pair, then the name is referencing an OpenCL
881 FTy->isFunctionProtoType());
882 NewOpenCLBuiltin->setImplicit();
888 for (unsigned IParm = 0, e = FP->getNumParams(); IParm != e; ++IParm) {
891 nullptr, FP->getParamType(IParm), nullptr, SC_None, nullptr);
892 Parm->setScopeInfo(0, IParm);
895 NewOpenCLBuiltin->setParams(ParmList);
899 NewOpenCLBuiltin->addAttr(PureAttr::CreateImplicit(Context));
901 NewOpenCLBuiltin->addAttr(ConstAttr::CreateImplicit(Context));
903 NewOpenCLBuiltin->addAttr(ConvergentAttr::CreateImplicit(Context));
906 NewOpenCLBuiltin->addAttr(OverloadableAttr::CreateImplicit(Context));
939 auto Index = isOpenCLBuiltin(II->getName());
941 InsertOCLBuiltinDeclarationsFromTable(*this, R, II, Index.first - 1,
951 RISCV().IntrinsicManager->InitIntrinsicList();
953 if (RISCV().IntrinsicManager->CreateIntrinsicIfFound(R, II, PP))
958 if (unsigned BuiltinID = II->getBuiltinID()) {
1000 if (!Class->getDefinition() || Class->isDependentContext())
1004 return !Class->isBeingDefined();
1012 if (Class->needsImplicitDefaultConstructor())
1016 if (Class->needsImplicitCopyConstructor())
1020 if (Class->needsImplicitCopyAssignment())
1025 if (Class->needsImplicitMoveConstructor())
1029 if (Class->needsImplicitMoveAssignment())
1034 if (Class->needsImplicitDestructor())
1038 /// Determine whether this is the name of an implicitly-declared
1068 if (Record->getDefinition() && CanDeclareSpecialMemberFunction(Record)) {
1070 if (Record->needsImplicitDefaultConstructor())
1072 if (Record->needsImplicitCopyConstructor())
1075 Record->needsImplicitMoveConstructor())
1082 if (Record->getDefinition() && Record->needsImplicitDestructor() &&
1092 if (Record->getDefinition() && CanDeclareSpecialMemberFunction(Record)) {
1094 if (Record->needsImplicitCopyAssignment())
1097 Record->needsImplicitMoveAssignment())
1123 DeclContext::lookup_result DR = DC->lookup(R.getLookupName());
1131 if (!Found && DC->isTranslationUnit() && S.LookupBuiltin(R))
1136 R.getLookupName().getCXXNameType()->isDependentType() ||
1145 if (!Record->isCompleteDefinition())
1152 R.getLookupName().getCXXNameType()->getContainedDeducedType();
1155 ContainedDeducedType && ContainedDeducedType->isUndeducedType())
1158 for (CXXRecordDecl::conversion_iterator U = Record->conversion_begin(),
1159 UEnd = Record->conversion_end(); U != UEnd; ++U) {
1188 = ConvTemplate->getTemplatedDecl()->getType()->getAs<FunctionProtoType>();
1194 FunctionProtoType::ExtProtoInfo EPI = ConvProto->getExtProtoInfo();
1218 assert(NS && NS->isFileContext() && "CppNamespaceLookup() requires namespace!");
1235 if (DeclContext *Ctx = S->getEntity())
1236 return Ctx->isFileContext();
1244 for (Scope *OuterS = S->getParent(); OuterS; OuterS = OuterS->getParent())
1245 if (DeclContext *DC = OuterS->getLookupEntity())
1277 // If this is the name of an implicitly-declared special member function,
1280 for (Scope *PreS = S; PreS; PreS = PreS->getParent())
1281 if (DeclContext *DC = PreS->getEntity())
1286 // The component name of an unqualified-id is dependent if
1287 // - it is a conversion-function-id whose conversion-type-id
1289 // - it is operator= and the current class is a templated entity, or
1290 // - the unqualified-id is the postfix-expression in a dependent call.
1292 Name.getCXXNameType()->isDependentType()) {
1306 // We don't consider using-directives, as per 7.3.4.p1 [namespace.udir]
1309 // both the using-directive and the nominated namespace.
1330 for (; S && !isNamespaceOrTranslationUnitScope(S); S = S->getParent()) {
1333 for (; I != IEnd && S->isDeclScope(*I); ++I) {
1336 !(*I)->isTemplateParameter()) {
1341 // out-of-scope.
1342 if (!LeftStartingScope && !Initial->isDeclScope(*I))
1347 if (LeftStartingScope && !((*I)->hasLinkage())) {
1361 if (S->isClassScope())
1362 if (auto *Record = dyn_cast_if_present<CXXRecordDecl>(S->getEntity()))
1367 if (NameKind == LookupLocalFriendName && !S->isClassScope()) {
1372 // innermost enclosing non-class scope.
1376 if (DeclContext *Ctx = S->getLookupEntity()) {
1378 for (; Ctx && !Ctx->Equals(OuterCtx); Ctx = Ctx->getLookupParent()) {
1381 // non-transparent context.
1382 if (Ctx->isTransparentContext())
1388 if (Ctx->isFunctionOrMethod()) {
1389 // If we have an Objective-C instance method, look for ivars
1392 if (Method->isInstanceMethod() && Name.getAsIdentifierInfo())
1393 if (ObjCInterfaceDecl *Class = Method->getClassInterface()) {
1395 if (ObjCIvarDecl *Ivar = Class->lookupInstanceVariable(
1412 if (Ctx->isFileContext()) {
1416 for (DeclContext *UCtx = Ctx; UCtx; UCtx = UCtx->getParent()) {
1417 if (UCtx->isTransparentContext())
1428 InnermostFileScope = InnermostFileScope->getParent();
1465 // nominated namespaces by those using-directives.
1483 for (; S; S = S->getParent()) {
1486 for (; I != IEnd && S->isDeclScope(*I); ++I) {
1497 if (Found && S->isTemplateParamScope()) {
1502 DeclContext *Ctx = S->getLookupEntity();
1505 for (; Ctx && !Ctx->Equals(OuterCtx); Ctx = Ctx->getLookupParent()) {
1508 // non-transparent context.
1509 if (Ctx->isTransparentContext())
1513 // template parameter scope for an out-of-line definition, also
1515 if (!(Found && S->isTemplateParamScope())) {
1516 assert(Ctx->isFileContext() &&
1519 // Look into context considering using-directives.
1529 if (R.isForRedeclaration() && !Ctx->isTransparentContext())
1534 if (R.isForRedeclaration() && Ctx && !Ctx->isTransparentContext())
1546 ND->setVisibleDespiteOwningModule();
1551 for (auto *Param : *TD->getTemplateParameters())
1560 if (FunctionDecl *Pattern = FD->getTemplateInstantiationPattern())
1563 if (CXXRecordDecl *Pattern = RD->getTemplateInstantiationPattern())
1566 if (auto *Pattern = ED->getTemplateInstantiationPattern())
1569 if (VarDecl *Pattern = VD->getTemplateInstantiationPattern())
1575 DeclContext *Context = Entity->getLexicalDeclContext();
1576 if (Context->isFileContext())
1613 if (M->isGlobalModule())
1658 if (!D->hasDefaultArgument())
1663 auto &DefaultArg = D->getDefaultArgStorage();
1669 Modules->push_back(S.getOwningModule(NonConstD));
1711 for (auto *Redecl : D->redecls()) {
1722 Modules->push_back(R->getOwningModule());
1740 return RD->getTemplateSpecializationKind() ==
1743 return FD->getTemplateSpecializationKind() ==
1746 return VD->getTemplateSpecializationKind() ==
1769 assert(isa<CXXRecordDecl>(D->getDeclContext()) &&
1780 // FIXME: What about MS-style explicit specializations declared within a
1782 return D->getLexicalDeclContext()->isFileContext();
1810 assert(!D->isUnconditionallyVisible() &&
1818 D->isInvisibleOutsideTheOwningModule()))
1825 return DC->isFileContext() || isa<LinkageSpecDecl>(DC) ||
1831 DeclContext *DC = D->getLexicalDeclContext();
1841 if (D->isTemplateParameter()) {
1844 if (const auto *TD = DCD->getDescribedTemplate()) {
1845 TemplateParameterList *TPL = TD->getTemplateParameters();
1847 SearchDefinitions = Index >= TPL->size() || TPL->getParam(Index) != D;
1859 else if (D->isModulePrivate()) {
1860 // A module-private declaration is only acceptable if an enclosing lexical
1868 DC = DC->getLexicalParent();
1881 D->setVisibleDespiteOwningModule();
1895 // The module might be ordinarily visible. For a module-private query, that
1900 // For a query which is not module-private, that means it is in our visible
1908 // Find the extra places where we need to look.
1920 if (M->isGlobalModule() && LookupModules.count(M->getTopLevelModule()))
1923 // For a module-private query, that's everywhere we get to look.
1929 return LookupM->isModuleVisible(M);
1942 if (DeclModule->isHeaderLikeModule())
1945 if (!D->isInAnotherModuleUnit())
1951 // - D is not discarded ([module.global.frag]), appears in a translation unit
1955 // A declaration that's discarded in the GMF should be module-private.
1956 if (D->isModulePrivate())
1967 // it contains a declaration (possibly a module-declaration) that imports U
1977 if (DeclModule->getTopLevelModule()->isModuleInterfaceUnit())
1999 // Non-imported module:
2008 assert(D->isExternallyDeclarable() &&
2009 "should not have hidden, non-externally-declarable result here");
2028 return New->isExternallyDeclarable();
2043 for (auto *RD : D->redecls()) {
2044 // Don't bother with extra checks if we already know this one isn't visible.
2052 if (ND->isInIdentifierNamespace(IDNS) &&
2084 auto *Key = ND->getCanonicalDecl();
2100 if (D->isUnconditionallyVisible())
2109 if (D->isUnconditionallyVisible())
2124 if (auto *DeductionGuide = ND->getDeclName().getCXXDeductionGuideTemplate())
2133 // (See https://github.com/llvm/llvm-project/issues/59601)
2140 FD && FD->isReservedGlobalPlacementOperator())
2143 auto *DC = ND->getDeclContext();
2146 if (DC->isFileContext())
2162 // auto b = e1; // Should be error. namespace-scope name e1 is not visible
2183 // Unqualified name lookup in C/Objective-C is purely lexical, so
2186 // Find the nearest non-transparent declaration scope.
2187 while (!(S->getFlags() & Scope::DeclScope) ||
2188 (S->getEntity() && S->getEntity()->isTransparentContext()))
2189 S = S->getParent();
2207 // out-of-scope.
2208 if (!LeftStartingScope && !S->isDeclScope(*I))
2213 if (LeftStartingScope && !((*I)->hasLinkage())) {
2229 while (S && !S->isDeclScope(D))
2230 S = S->getParent();
2241 DC = (*I)->getDeclContext()->getRedeclContext();
2247 if (!S->isDeclScope(*LastI))
2252 = (*LastI)->getDeclContext()->getRedeclContext();
2253 if (!LastDC->Equals(DC))
2283 return (ExternalSource && ExternalSource->LookupUnqualified(R, S));
2290 /// Given X::m (where X is a user-declared namespace), or given \::m
2293 /// namespaces nominated by using-directives in X and its used
2294 /// namespaces, except that using-directives are ignored in any
2298 /// ill-formed. Otherwise, if S has exactly one member, or if the
2299 /// context of the reference is a using-declaration
2302 /// declaration to be chosen from S, the program is ill-formed.
2309 /// enumerator or a set of functions, the non-type name hides the
2312 /// different namespaces), the program is ill-formed.
2315 assert(StartDC->isFileContext() && "start context is not a file context");
2318 // their "using-children" to the queue.
2326 // with its using-children.
2327 for (auto *I : StartDC->using_directives()) {
2328 NamespaceDecl *ND = I->getNominatedNamespace()->getFirstDecl();
2375 for (auto *I : ND->using_directives()) {
2376 NamespaceDecl *Nom = I->getNominatedNamespace();
2401 LookupCtx->isDependentContext() ||
2402 cast<TagDecl>(LookupCtx)->isCompleteDefinition() ||
2403 cast<TagDecl>(LookupCtx)->isBeingDefined()) &&
2411 : oldVal(ctx->shouldUseQualifiedLookup()), Context(ctx) {
2412 ctx->setUseQualifiedLookup();
2415 Context->setUseQualifiedLookup(oldVal);
2421 // if it's a dependent conversion-function-id or operator= where the current
2426 // - it is a conversion-function-id whose conversion-type-id
2428 // - [...]
2429 // - its lookup context is the current instantiation and it
2431 // - [...]
2434 Name.getCXXNameType()->isDependentType()) {
2450 // declarator-id is a qualified-id, given that the qualified-id
2452 // nested-name-specifier unqualified-id
2453 // the unqualified-id shall name a member of the namespace
2454 // designated by the nested-name-specifier.
2460 if (LookupCtx->isFileContext())
2465 if (!LookupRec || !LookupRec->getDefinition())
2477 // dependent base classes, then we either have to delay lookup until
2480 if (!InUnqualifiedLookup && LookupRec->isDependentContext() &&
2481 LookupRec->hasAnyDependentBases()) {
2493 CXXBasePath &Path) -> bool {
2494 CXXRecordDecl *BaseRecord = Specifier->getType()->getAsCXXRecordDecl();
2495 // Drop leading non-matching lookup results from the declaration list so
2497 for (Path.Decls = BaseRecord->lookup(Name).begin();
2499 if ((*Path.Decls)->isInIdentifierNamespace(IDNS))
2507 if (!LookupRec->lookupInBases(BaseCallback, Paths))
2514 // sub-objects of the same type, or the set has a nonstatic member
2515 // and includes members from distinct sub-objects, there is an
2516 // ambiguity and the program is ill-formed. Otherwise that set is
2525 if ((*I)->isInIdentifierNamespace(IDNS) && (*I)->isCXXInstanceMember())
2539 auto Next = [&](Iterator &It, Iterator End) -> Result {
2542 if (!ND->isInIdentifierNamespace(IDNS))
2546 // A lookup that finds an injected-class-name (10.2) can result in
2548 // more than one base class). If all of the injected-class-names
2550 // template, and if the name is used as a template-name, the
2558 // type declarations (including injected-class-names) are replaced by
2560 if (const TypeDecl *TD = dyn_cast<TypeDecl>(ND->getUnderlyingDecl())) {
2565 return ND->getUnderlyingDecl()->getCanonicalDecl();
2591 if (!It->second) {
2592 It->second = true;
2603 const CXXBasePathElement &PathElement = Path->back();
2607 SubobjectAccess = std::min(SubobjectAccess, Path->Access);
2609 // Determine whether we're looking at a distinct sub-object or not.
2612 SubobjectType = Context.getCanonicalType(PathElement.Base->getType());
2618 Context.getCanonicalType(PathElement.Base->getType())) {
2625 if (HasOnlyStaticMembers(Path->Decls) &&
2626 HasSameDeclarations(Paths.begin()->Decls, Path->Decls))
2643 if (HasOnlyStaticMembers(Path->Decls))
2658 (*I)->getAccess());
2669 if (NNS && NNS->getKind() == NestedNameSpecifier::Super)
2670 return LookupInSuper(R, NNS->getAsRecordDecl());
2680 if (SS && SS->isInvalid())
2687 // This nested-name-specifier occurs in a member access expression, e.g.,
2688 // x->B::f, and we are looking into the type of the object.
2689 assert((!SS || SS->isEmpty()) &&
2692 IsDependent = !DC && ObjectType->isDependentType();
2693 assert(((!DC && ObjectType->isDependentType()) ||
2694 !ObjectType->isIncompleteType() || !ObjectType->getAs<TagType>() ||
2695 ObjectType->castAs<TagType>()->isBeingDefined()) &&
2697 } else if (SS && SS->isNotEmpty()) {
2698 // This nested-name-specifier occurs after another nested-name-specifier,
2699 // so long into the context associated with the prior nested-name-specifier.
2702 if (!DC->isDependentContext() && RequireCompleteDeclContext(*SS, DC))
2704 R.setContextRange(SS->getRange());
2708 if (NestedNameSpecifier *NNS = SS->getScopeRep();
2709 NNS->getKind() == NestedNameSpecifier::Super)
2710 return LookupInSuper(R, NNS->getAsRecordDecl());
2731 // The access-control rules we use here are essentially the rules for
2735 for (const auto &BaseSpec : Class->bases()) {
2737 BaseSpec.getType()->castAs<RecordType>()->getDecl());
2769 QualType SubobjectType = Paths->front().back().Base->getType();
2774 DeclContext::lookup_iterator Found = Paths->front().Decls;
2776 cast<CXXMethodDecl>(*Found)->isStatic())
2779 Diag((*Found)->getLocation(), diag::note_ambiguous_member_found);
2789 for (CXXBasePaths::paths_iterator Path = Paths->begin(),
2790 PathEnd = Paths->end();
2792 const NamedDecl *D = *Path->Decls;
2793 if (!D->isInIdentifierNamespace(Result.getIdentifierNamespace()))
2796 if (const auto *TD = dyn_cast<TypedefNameDecl>(D->getUnderlyingDecl()))
2797 Diag(D->getLocation(), diag::note_ambiguous_member_type_found)
2798 << TD->getUnderlyingType();
2799 else if (const auto *TD = dyn_cast<TypeDecl>(D->getUnderlyingDecl()))
2800 Diag(D->getLocation(), diag::note_ambiguous_member_type_found)
2803 Diag(D->getLocation(), diag::note_ambiguous_member_found);
2817 Diag(TD->getLocation(), diag::note_hidden_tag);
2822 Diag(D->getLocation(), diag::note_hiding_object);
2838 Diag(D->getLocation(), diag::note_reference_placeholder) << D;
2839 if (DC != nullptr && DC != D->getDeclContext())
2841 DC = D->getDeclContext();
2850 Diag(D->getLocation(), diag::note_ambiguous_candidate) << D;
2900 // We additionally skip inline namespaces. The innermost non-inline namespace
2903 while (!Ctx->isFileContext() || Ctx->isInlineNamespace())
2904 Ctx = Ctx->getParent();
2906 Namespaces.insert(Ctx->getPrimaryContext());
2909 // Add the associated classes and namespaces for argument-dependent
2915 // -- [...] ;
2935 DeclContext *Ctx = ClassTemplate->getDeclContext();
2949 // [Note: non-type template arguments do not contribute to the set of
2960 // Add the associated classes and namespaces for argument-dependent lookup
2967 if (Class->getDeclName() == Result.S.VAListTagName)
2972 // -- If T is a class type (including unions), its associated
2979 DeclContext *Ctx = Class->getDeclContext();
2986 // -- If T is a template-id, its associated namespaces and classes are
2993 // arguments are defined. [Note: non-type template arguments do not
2997 DeclContext *Ctx = Spec->getSpecializedTemplate()->getDeclContext();
3003 const TemplateArgumentList &TemplateArgs = Spec->getTemplateArgs();
3027 for (const auto &Base : Class->bases()) {
3028 const RecordType *BaseType = Base.getType()->getAs<RecordType>();
3034 // the classes and namespaces of known non-dependent arguments.
3037 CXXRecordDecl *BaseDecl = cast<CXXRecordDecl>(BaseType->getDecl());
3040 DeclContext *BaseCtx = BaseDecl->getDeclContext();
3044 if (BaseDecl->bases_begin() != BaseDecl->bases_end())
3052 // argument-dependent lookup with an argument of type T
3063 // argument). Typedef names and using-declarations used to specify
3068 const Type *T = Ty->getCanonicalTypeInternal().getTypePtr();
3071 switch (T->getTypeClass()) {
3086 // -- If T is a pointer to U or an array of U, its associated
3089 T = cast<PointerType>(T)->getPointeeType().getTypePtr();
3094 T = cast<ArrayType>(T)->getElementType().getTypePtr();
3097 // -- If T is a fundamental type, its associated sets of
3102 // -- If T is a class type (including unions), its associated
3109 cast<CXXRecordDecl>(cast<RecordType>(T)->getDecl());
3114 // -- If T is an enumeration type, its associated namespace
3119 EnumDecl *Enum = cast<EnumType>(T)->getDecl();
3121 DeclContext *Ctx = Enum->getDeclContext();
3131 // -- If T is a function type, its associated namespaces and
3136 for (const auto &Arg : Proto->param_types())
3143 T = FnType->getReturnType().getTypePtr();
3147 // -- If T is a pointer to a member function of a class X, its
3152 // -- If T is a pointer to a data member of class X, its
3160 Queue.push_back(MemberPtr->getClass());
3163 T = MemberPtr->getPointeeType().getTypePtr();
3169 T = cast<BlockPointerType>(T)->getPointeeType().getTypePtr();
3176 T = cast<ReferenceType>(T)->getPointeeType().getTypePtr();
3187 // Non-deduced auto types only get here for error cases.
3192 // If T is an Objective-C object or interface type, or a pointer to an
3204 T = cast<AtomicType>(T)->getValueType().getTypePtr();
3207 T = cast<PipeType>(T)->getElementType().getTypePtr();
3241 if (Arg->getType() != Context.OverloadTy) {
3242 addAssociatedClassesAndNamespaces(Result, Arg->getType());
3251 // classes and namespaces associated with its (non-dependent)
3253 OverloadExpr *OE = OverloadExpr::find(Arg).Expression;
3255 for (const NamedDecl *D : OE->decls()) {
3257 const FunctionDecl *FDecl = D->getUnderlyingDecl()->getAsFunction();
3261 addAssociatedClassesAndNamespaces(Result, FDecl->getType());
3278 // -- The set of non-member candidates is the result of the
3297 RD = RD->getDefinition();
3305 "parameter-less special members can't have qualified arguments");
3308 SourceLocation LookupLoc = RD->getLocation();
3332 if (RD->needsImplicitDestructor()) {
3333 runWithSufficientStackSpace(RD->getLocation(), [&] {
3337 CXXDestructorDecl *DD = RD->getDestructor();
3338 Result->setMethod(DD);
3339 Result->setKind(DD && !DD->isDeleted()
3358 if (RD->needsImplicitDefaultConstructor()) {
3359 runWithSufficientStackSpace(RD->getLocation(), [&] {
3367 if (RD->needsImplicitCopyConstructor()) {
3368 runWithSufficientStackSpace(RD->getLocation(), [&] {
3372 if (getLangOpts().CPlusPlus11 && RD->needsImplicitMoveConstructor()) {
3373 runWithSufficientStackSpace(RD->getLocation(), [&] {
3379 if (RD->needsImplicitCopyAssignment()) {
3380 runWithSufficientStackSpace(RD->getLocation(), [&] {
3384 if (getLangOpts().CPlusPlus11 && RD->needsImplicitMoveAssignment()) {
3385 runWithSufficientStackSpace(RD->getLocation(), [&] {
3431 DeclContext::lookup_result R = RD->lookup(Name);
3440 Result->setMethod(nullptr);
3441 Result->setKind(SpecialMemberOverloadResult::NoMemberOrDeleted);
3450 if (CandDecl->isInvalidDecl())
3455 if (CXXMethodDecl *M = dyn_cast<CXXMethodDecl>(Cand->getUnderlyingDecl())) {
3468 dyn_cast<FunctionTemplateDecl>(Cand->getUnderlyingDecl())) {
3490 Result->setMethod(cast<CXXMethodDecl>(Best->Function));
3491 Result->setKind(SpecialMemberOverloadResult::Success);
3495 Result->setMethod(cast<CXXMethodDecl>(Best->Function));
3496 Result->setKind(SpecialMemberOverloadResult::NoMemberOrDeleted);
3500 Result->setMethod(nullptr);
3501 Result->setKind(SpecialMemberOverloadResult::Ambiguous);
3505 Result->setMethod(nullptr);
3506 Result->setKind(SpecialMemberOverloadResult::NoMemberOrDeleted);
3524 "non-const, non-volatile qualifiers for copy ctor arg");
3544 runWithSufficientStackSpace(Class->getLocation(), [&] {
3545 if (Class->needsImplicitDefaultConstructor())
3547 if (Class->needsImplicitCopyConstructor())
3549 if (getLangOpts().CPlusPlus11 && Class->needsImplicitMoveConstructor())
3556 return Class->lookup(Name);
3563 "non-const, non-volatile qualifiers for copy assignment arg");
3565 "non-const, non-volatile qualifiers for copy assignment this");
3579 "non-const, non-volatile qualifiers for copy assignment this");
3616 D = USD->getTargetDecl();
3619 if (D->isInvalidDecl()) {
3630 if (FD->getNumParams() == 1 &&
3631 FD->getParamDecl(0)->getType()->getAs<PointerType>())
3633 else if (FD->getNumParams() == ArgTys.size()) {
3636 QualType ParamTy = FD->getParamDecl(ArgIdx)->getType();
3645 TemplateParameterList *Params = FD->getTemplateParameters();
3646 if (Params->size() == 1) {
3648 if (!Params->getParam(0)->isTemplateParameterPack() && !StringLit) {
3649 // Implied but not stated: user-defined integer and floating literals
3657 // is a well-formed template argument for the template parameter.
3663 Params->getParam(0), Arg, FD, R.getNameLoc(), R.getNameLoc(),
3706 // Per C++20 [lex.ext]p5, we prefer the template form over the non-template
3722 NoteOverloadCandidate(D, D->getUnderlyingDecl()->getAsFunction());
3748 NamedDecl *&Old = Decls[cast<NamedDecl>(New->getCanonicalDecl())];
3758 FunctionDecl *OldFD = Old->getAsFunction();
3759 FunctionDecl *NewFD = New->getAsFunction();
3763 Cursor = Cursor->getPreviousDecl();
3804 // -- Any using-directives in the associated namespace are
3807 // -- Any namespace-scope friend functions declared in
3813 // -- are exported, are attached to a named module M, do not appear
3815 // have the same innermost enclosing non-inline namespace scope as
3817 DeclContext::lookup_result R = NS->lookup(Name);
3821 Underlying = USD->getTargetDecl();
3827 // The declaration is visible to argument-dependent lookup if either
3831 for (D = D->getMostRecentDecl(); D;
3832 D = cast_or_null<NamedDecl>(D->getPreviousDecl())) {
3833 if (D->getIdentifierNamespace() & Decl::IDNS_Ordinary) {
3842 if (D->isInExportDeclContext()) {
3843 Module *FM = D->getOwningModule();
3848 assert(FM && FM->isNamedModule() && !FM->isPrivateModule() &&
3852 if (D->isInAnotherModuleUnit() &&
3854 // ... and have the same innermost enclosing non-inline
3857 if (E->getOwningModule() != FM)
3861 DeclContext *Ctx = E->getDeclContext();
3862 while (!Ctx->isFileContext() || Ctx->isInlineNamespace())
3863 Ctx = Ctx->getParent();
3870 } else if (D->getFriendObjectKind()) {
3871 auto *RD = cast<CXXRecordDecl>(D->getLexicalDeclContext());
3873 // Argument-dependent lookup finds all declarations of functions and
3875 // - ...
3876 // - are declared as a friend ([class.friend]) of any class with a
3895 //----------------------------------------------------------------------------
3897 //----------------------------------------------------------------------------
3946 ShadowMaps.back()[ND->getDeclName()].push_back(ND);
3969 unsigned IDNS = ND->getIdentifierNamespace();
3973 ShadowMap::iterator Pos = SM->find(ND->getDeclName());
3974 if (Pos == SM->end())
3977 for (auto *D : Pos->second) {
3978 // A tag declaration does not hide a non-tag declaration.
3979 if (D->hasTagIdentifierNamespace() &&
3985 if (((D->getIdentifierNamespace() & Decl::IDNS_ObjCProtocol)
3987 D->getIdentifierNamespace() != IDNS)
3993 if (D->getUnderlyingDecl()->isFunctionOrFunctionTemplate() &&
3994 ND->getUnderlyingDecl()->isFunctionOrFunctionTemplate() &&
4001 cast<UsingShadowDecl>(ND)->getIntroducer() == D)
4027 // Find the first namespace or translation-unit scope.
4029 S = S->getParent();
4063 if (Visited.visitedContext(Ctx->getPrimaryContext()))
4078 std::unique_ptr<IdentifierIterator> Iter(External->getIdentifiers());
4079 for (StringRef Name = Iter->Next(); !Name.empty();
4080 Name = Iter->Next())
4105 // We sometimes skip loading namespace-level results (they tend to be huge).
4110 Load ? Ctx->lookups()
4111 : Ctx->noload_lookups(/*PreserveInternalState=*/false))
4131 for (auto *I : Ctx->using_directives()) {
4134 lookupInDeclContext(I->getNominatedNamespace(), Result,
4141 if (!Record->hasDefinition())
4144 for (const auto &B : Record->bases()) {
4148 if (BaseType->isDependentType()) {
4154 const auto *TST = BaseType->getAs<TemplateSpecializationType>();
4157 TemplateName TN = TST->getTemplateName();
4162 RD = TD->getTemplatedDecl();
4164 const auto *Record = BaseType->getAs<RecordType>();
4167 RD = Record->getDecl();
4177 // void f(C *c) { c->### }
4183 // c->B::member
4187 // c->A::member
4196 // Traverse the contexts of Objective-C classes.
4199 for (auto *Cat : IFace->visible_categories()) {
4206 for (auto *I : IFace->all_referenced_protocols()) {
4213 if (IFace->getSuperClass()) {
4215 lookupInDeclContext(IFace->getSuperClass(), Result, QualifiedNameLookup,
4221 if (IFace->getImplementation()) {
4223 lookupInDeclContext(IFace->getImplementation(), Result,
4227 for (auto *I : Protocol->protocols()) {
4233 for (auto *I : Category->protocols()) {
4240 if (Category->getImplementation()) {
4242 lookupInDeclContext(Category->getImplementation(), Result,
4257 if (!S->getEntity() ||
4258 (!S->getParent() && !Visited.alreadyVisitedContext(S->getEntity())) ||
4259 (S->getEntity())->isFunctionOrMethod()) {
4263 SmallVector<Decl *, 8> ScopeDecls(S->decls().begin(), S->decls().end());
4273 DeclContext *Entity = S->getLookupEntity();
4280 for (DeclContext *Ctx = Entity; Ctx && !Ctx->Equals(OuterCtx);
4281 Ctx = Ctx->getLookupParent()) {
4283 if (Method->isInstanceMethod()) {
4288 if (ObjCInterfaceDecl *IFace = Method->getClassInterface()) {
4296 // to for Objective-C methods; the next context will be the
4301 if (Ctx->isFunctionOrMethod())
4307 } else if (!S->getParent()) {
4313 // However, doing so would force the normal C++ name-lookup code to look
4335 lookupInScope(S->getParent(), Result, UDirs);
4380 if (Res && Res->getDeclContext() != CurContext)
4385 Scope *S = CurScope->getFnParent();
4392 //===----------------------------------------------------------------------===//
4394 //===----------------------------------------------------------------------===//
4437 } else if (!AnyVisibleDecls && !(*DI)->isModulePrivate())
4455 if (NestedNameSpecifier *Prefix = NNS->getPrefix())
4462 switch (NNS->getKind()) {
4464 II = NNS->getAsIdentifier();
4468 if (NNS->getAsNamespace()->isAnonymousNamespace())
4470 II = NNS->getAsNamespace()->getIdentifier();
4474 II = NNS->getAsNamespaceAlias()->getIdentifier();
4479 II = QualType(NNS->getAsType(), 0).getBaseTypeIdentifier();
4500 IdentifierInfo *Name = ND->getIdentifier();
4509 FoundName(Name->getName());
4526 // Use a simple length-based heuristic to determine the minimum possible
4528 StringRef TypoStr = Typo->getName();
4529 unsigned MinED = abs((int)Name.size() - (int)TypoStr.size());
4534 // edit-distance algorithm can short-circuit.
4548 StringRef TypoStr = Typo->getName();
4549 StringRef Name = Correction.getCorrectionAsIdentifierInfo()->getName();
4580 if (D->isDeprecated())
4582 D = llvm::dyn_cast_or_null<NamespaceDecl>(D->getDeclContext());
4594 IsDeprecated(RI->getFoundDecl()),
4595 RI->getAsString(SemaRef.getLangOpts())};
4618 (SS && SS->isValid()) ? SS->getScopeRep() : nullptr) {
4619 if (const Type *T = NNS->getAsType())
4620 SSIsTemplate = T->getTypeClass() == Type::TemplateSpecialization;
4622 // Do not transform this into an iterator-based loop. The loop body can
4628 if (CXXRecordDecl *CD = TI->getAsCXXRecordDecl()) {
4629 CD = CD->getCanonicalDecl();
4630 if (!CD->isDependentType() && !CD->isAnonymousStructOrUnion() &&
4631 !CD->isUnion() && CD->getIdentifier() &&
4633 (CD->isBeingDefined() || CD->isCompleteDefinition()))
4646 if (DI->second.empty()) {
4651 auto RI = DI->second.begin();
4652 if (RI->second.empty()) {
4653 DI->second.erase(RI);
4658 TypoCorrection TC = RI->second.pop_back_val();
4674 CorrectionValidator->IsObjCIvarLookup,
4718 unsigned TypoLen = Typo->getName().size();
4722 const Type *NSType = NSI.NameSpecifier->getAsType();
4728 if (CXXRecordDecl *NSDecl = NSType ? NSType->getAsCXXRecordDecl() :
4730 if (NSDecl->getIdentifier() == QR.getCorrectionAsIdentifierInfo())
4758 if (SS && SS->isValid()) {
4762 SS->getScopeRep()->print(OldOStream, SemaRef.getPrintingPolicy());
4763 OldOStream << Typo->getName();
4773 NSType ? NSType->getAsCXXRecordDecl()
4799 CurScopeSpec ? CurScopeSpec->getScopeRep() : nullptr) {
4801 NNS->print(SpecifierOStream, Context.getPrintingPolicy());
4810 CurContextIdentifiers.push_back(ND->getIdentifier());
4820 DeclContext *Start) -> DeclContextList {
4823 for (DeclContext *DC = Start->getPrimaryContext(); DC != nullptr;
4824 DC = DC->getLookupParent()) {
4826 if (!DC->isInlineNamespace() && !DC->isTransparentContext() &&
4827 !(ND && ND->isAnonymousNamespace()))
4828 Chain.push_back(DC->getPrimaryContext());
4842 NNS = NestedNameSpecifier::Create(Context, NNS, RD->isTemplateDecl(),
4843 RD->getTypeForDecl());
4869 // Rebuild the NestedNameSpecifier as a globally-qualified specifier.
4875 IdentifierInfo *Name = ND->getIdentifier();
4882 NNS->print(SpecifierOStream, Context.getPrintingPolicy());
4887 // Rebuild the NestedNameSpecifier as a globally-qualified specifier.
4926 if (ObjCIvarDecl *Ivar = Class->lookupInstanceVariable(Name)) {
4933 if (ObjCPropertyDecl *Prop = Class->FindPropertyDeclaration(
4952 if (Method->isInstanceMethod() && Method->getClassInterface() &&
4955 Res.getFoundDecl()->isDefinedOutsideFunctionOrMethod()))) {
4957 = Method->getClassInterface()->lookupInstanceVariable(Name)) {
4982 // Add type-specifier keywords to the set of results.
4987 // storage-specifiers as well
5051 cast<CXXMethodDecl>(SemaRef.CurContext)->isInstance())
5080 if (S && S->getBreakParent())
5083 if (S && S->getContinueParent())
5087 !SemaRef.getCurFunction()->SwitchStack.empty()) {
5097 if (S && S->isClassScope()) {
5130 if (getLangOpts().MSVCCompat && CurContext->isDependentContext() &&
5141 if (SS && SS->isInvalid())
5149 if (S && S->isInObjcMethodScope() && Typo == getSuperIdentifier())
5155 locs->second.count(TypoName.getLoc()))
5161 if ((getLangOpts().AltiVec || getLangOpts().ZVector) && Typo->isStr("vector"))
5177 getModuleLoader().lookupMissingImports(Typo->getName(),
5184 // initially stack-allocated.
5190 // Perform name lookup to find visible, similarly-named entities.
5198 for (auto *I : OPT->quals())
5201 } else if (SS && SS->isSet()) {
5215 (IsUnqualifiedLookup || (SS && SS->isSet()));
5220 // FIXME: Re-add the ability to skip very unlikely potential corrections.
5222 Consumer->FoundName(I.getKey());
5225 // FIXME: Re-add the ability to skip very unlikely potential corrections.
5228 std::unique_ptr<IdentifierIterator> Iter(External->getIdentifiers());
5230 StringRef Name = Iter->Next();
5234 Consumer->FoundName(Name);
5240 *Consumer->getCorrectionValidator(),
5241 SS && SS->isNotEmpty());
5246 // Load any externally-known namespaces.
5250 ExternalSource->ReadKnownNamespaces(ExternalKnownNamespaces);
5255 Consumer->addNamespaces(KnownNamespaces);
5274 ExternalSource->CorrectTypo(TypoName, LookupKind, S, SS, CCC,
5294 if (Consumer->empty())
5299 unsigned ED = Consumer->getBestEditDistance(true);
5300 unsigned TypoLen = Typo->getName().size();
5304 TypoCorrection BestTC = Consumer->getNextCorrection();
5305 TypoCorrection SecondBestTC = Consumer->getNextCorrection();
5333 // Prefer 'super' when we're completing in a message-receiver
5371 ExternalTypo = ExternalSource->CorrectTypo(
5372 TypoName, LookupKind, S, SS, *Consumer->getCorrectionValidator(),
5375 Consumer->addCorrection(ExternalTypo);
5378 if (!Consumer || Consumer->empty())
5383 unsigned ED = Consumer->getBestEditDistance(true);
5385 if (!ExternalTypo && ED > 0 && Typo->getName().size() / ED < 3)
5401 CorrectionName = CDecl->getDeclName();
5408 CorrectionNameSpec->print(PrefixOStream, PrintingPolicy(LO));
5430 D = FTD->getTemplatedDecl();
5432 if (Method->isStatic())
5466 NamedDecl *ND = C->getUnderlyingDecl();
5468 FD = FTD->getTemplatedDecl();
5474 QualType ValType = cast<ValueDecl>(ND)->getType();
5477 if (ValType->isAnyPointerType() || ValType->isReferenceType())
5478 ValType = ValType->getPointeeType();
5479 if (const FunctionProtoType *FPT = ValType->getAs<FunctionProtoType>())
5480 if (FPT->getNumParams() == NumArgs)
5485 // A typo for a function-style cast can look like a function call in C++.
5488 CurContext->getParentASTContext().getLangOpts().CPlusPlus)
5494 if (!FD || !(FD->getNumParams() >= NumArgs &&
5495 FD->getMinRequiredArguments() <= NumArgs))
5498 // If the current candidate is a non-static C++ method, skip the candidate
5499 // unless the method being corrected--or the current DeclContext, if the
5500 // function being corrected is not a method--is a method in the same class
5503 if (MemberFn || !MD->isStatic()) {
5506 ? dyn_cast_if_present<CXXMethodDecl>(MemberFn->getMemberDecl())
5509 CurMD ? CurMD->getParent()->getCanonicalDecl() : nullptr;
5510 const CXXRecordDecl *RD = MD->getParent()->getCanonicalDecl();
5511 if (!CurRD || (CurRD != RD && !CurRD->isDerivedFrom(RD)))
5531 return VD->getDefinition();
5533 return FD->getDefinition();
5535 return TD->getDefinition();
5537 return ID->getDefinition();
5539 return PD->getDefinition();
5541 if (const NamedDecl *TTD = TD->getTemplatedDecl())
5562 diagnoseMissingImport(Loc, Def, Def->getLocation(), OwningModules, MIK,
5582 // See https://github.com/llvm/llvm-project/issues/73893. It is generally
5589 // -fdiagnostics-show-note-include-stack. We don't care how this
5598 if (M->isExplicitGlobalModule() || M->isPrivateModule())
5604 // Try to find a suitable header-name to #include.
5611 getHeaderNameForHeader(PP, *Header, FE->tryGetRealPathName());
5630 auto GetModuleNameForDiagnostic = [this](const Module *M) -> std::string {
5631 if (M->isModuleMapModule())
5632 return M->getFullModuleName();
5634 if (M->isImplicitGlobalModule())
5635 M = M->getTopLevelModule();
5641 return M->getTopLevelModuleName().str();
5643 return M->getPrimaryModuleInterfaceName().str();
5701 FD && FD->getBuiltinID() &&
5703 Correction.getCorrectionRange().getBegin() == FD->getBeginLoc()) {
5708 Diag(ChosenDecl->getLocation(), PrevNote)
5711 // Add any extra diagnostics.
5735 return Entry->second;
5753 E->dump();
5761 if (cast<Decl>(CurContext)->getOwningModuleForLinkage())