diff options
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/SemaCXXScopeSpec.cpp | 15 | ||||
-rw-r--r-- | clang/lib/Sema/SemaCodeComplete.cpp | 17 | ||||
-rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 17 |
3 files changed, 24 insertions, 25 deletions
diff --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp b/clang/lib/Sema/SemaCXXScopeSpec.cpp index f943a10deb4..f7aace625a9 100644 --- a/clang/lib/Sema/SemaCXXScopeSpec.cpp +++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp @@ -291,8 +291,10 @@ bool Sema::isAcceptableNestedNameSpecifier(const NamedDecl *SD, if (!SD) return false; + SD = SD->getUnderlyingDecl(); + // Namespace and namespace aliases are fine. - if (isa<NamespaceDecl>(SD) || isa<NamespaceAliasDecl>(SD)) + if (isa<NamespaceDecl>(SD)) return true; if (!isa<TypeDecl>(SD)) @@ -396,10 +398,7 @@ bool Sema::isNonTypeNestedNameSpecifier(Scope *S, CXXScopeSpec &SS, } Found.suppressDiagnostics(); - if (NamedDecl *ND = Found.getAsSingle<NamedDecl>()) - return isa<NamespaceDecl>(ND) || isa<NamespaceAliasDecl>(ND); - - return false; + return Found.getAsSingle<NamespaceDecl>(); } namespace { @@ -615,7 +614,8 @@ bool Sema::BuildCXXNestedNameSpecifier(Scope *S, } } - NamedDecl *SD = Found.getAsSingle<NamedDecl>(); + NamedDecl *SD = + Found.isSingleResult() ? Found.getRepresentativeDecl() : nullptr; bool IsExtension = false; bool AcceptSpec = isAcceptableNestedNameSpecifier(SD, &IsExtension); if (!AcceptSpec && IsExtension) { @@ -687,7 +687,8 @@ bool Sema::BuildCXXNestedNameSpecifier(Scope *S, return false; } - QualType T = Context.getTypeDeclType(cast<TypeDecl>(SD)); + QualType T = + Context.getTypeDeclType(cast<TypeDecl>(SD->getUnderlyingDecl())); TypeLocBuilder TLB; if (isa<InjectedClassNameType>(T)) { InjectedClassNameTypeLoc InjectedTL diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp index 5aa5fc5ebde..21cf6258514 100644 --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -494,6 +494,7 @@ bool ResultBuilder::isInterestingDecl(const NamedDecl *ND, bool &AsNestedNameSpecifier) const { AsNestedNameSpecifier = false; + auto *Named = ND; ND = ND->getUnderlyingDecl(); // Skip unnamed entities. @@ -526,14 +527,14 @@ bool ResultBuilder::isInterestingDecl(const NamedDecl *ND, return false; if (Filter == &ResultBuilder::IsNestedNameSpecifier || - ((isa<NamespaceDecl>(ND) || isa<NamespaceAliasDecl>(ND)) && + (isa<NamespaceDecl>(ND) && Filter != &ResultBuilder::IsNamespace && Filter != &ResultBuilder::IsNamespaceOrAlias && Filter != nullptr)) AsNestedNameSpecifier = true; // Filter out any unwanted results. - if (Filter && !(this->*Filter)(ND)) { + if (Filter && !(this->*Filter)(Named)) { // Check whether it is interesting as a nested-name-specifier. if (AllowNestedNameSpecifiers && SemaRef.getLangOpts().CPlusPlus && IsNestedNameSpecifier(ND) && @@ -1142,14 +1143,12 @@ bool ResultBuilder::IsNamespace(const NamedDecl *ND) const { /// \brief Determines whether the given declaration is a namespace or /// namespace alias. bool ResultBuilder::IsNamespaceOrAlias(const NamedDecl *ND) const { - return isa<NamespaceDecl>(ND) || isa<NamespaceAliasDecl>(ND); + return isa<NamespaceDecl>(ND->getUnderlyingDecl()); } /// \brief Determines whether the given declaration is a type. bool ResultBuilder::IsType(const NamedDecl *ND) const { - if (const UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(ND)) - ND = Using->getTargetDecl(); - + ND = ND->getUnderlyingDecl(); return isa<TypeDecl>(ND) || isa<ObjCInterfaceDecl>(ND); } @@ -1157,11 +1156,9 @@ bool ResultBuilder::IsType(const NamedDecl *ND) const { /// "." or "->". Only value declarations, nested name specifiers, and /// using declarations thereof should show up. bool ResultBuilder::IsMember(const NamedDecl *ND) const { - if (const UsingShadowDecl *Using = dyn_cast<UsingShadowDecl>(ND)) - ND = Using->getTargetDecl(); - + ND = ND->getUnderlyingDecl(); return isa<ValueDecl>(ND) || isa<FunctionTemplateDecl>(ND) || - isa<ObjCPropertyDecl>(ND); + isa<ObjCPropertyDecl>(ND); } static bool isObjCReceiverType(ASTContext &C, QualType T) { diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 634e699056e..b4d6175622d 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -7198,7 +7198,8 @@ Decl *Sema::ActOnStartNamespaceDef(Scope *NamespcScope, // as if by qualified name lookup. LookupResult R(*this, II, IdentLoc, LookupOrdinaryName, ForRedeclaration); LookupQualifiedName(R, CurContext->getRedeclContext()); - NamedDecl *PrevDecl = R.getAsSingle<NamedDecl>(); + NamedDecl *PrevDecl = + R.isSingleResult() ? R.getRepresentativeDecl() : nullptr; PrevNS = dyn_cast_or_null<NamespaceDecl>(PrevDecl); if (PrevNS) { @@ -7579,9 +7580,9 @@ Decl *Sema::ActOnUsingDirective(Scope *S, } if (!R.empty()) { - NamedDecl *Named = R.getFoundDecl(); - assert((isa<NamespaceDecl>(Named) || isa<NamespaceAliasDecl>(Named)) - && "expected namespace decl"); + NamedDecl *Named = R.getRepresentativeDecl(); + NamespaceDecl *NS = R.getAsSingle<NamespaceDecl>(); + assert(NS && "expected namespace decl"); // The use of a nested name specifier may trigger deprecation warnings. DiagnoseUseOfDecl(Named, IdentLoc); @@ -7598,7 +7599,6 @@ Decl *Sema::ActOnUsingDirective(Scope *S, // Find enclosing context containing both using-directive and // nominated namespace. - NamespaceDecl *NS = getNamespaceDecl(Named); DeclContext *CommonAncestor = cast<DeclContext>(NS); while (CommonAncestor && !CommonAncestor->Encloses(CurContext)) CommonAncestor = CommonAncestor->getParent(); @@ -8669,7 +8669,7 @@ Decl *Sema::ActOnNamespaceAliasDef(Scope *S, SourceLocation NamespaceLoc, } } assert(!R.isAmbiguous() && !R.empty()); - NamedDecl *ND = R.getFoundDecl(); + NamedDecl *ND = R.getRepresentativeDecl(); // Check if we have a previous declaration with the same name. LookupResult PrevR(*this, Alias, AliasLoc, LookupOrdinaryName, @@ -8689,7 +8689,8 @@ Decl *Sema::ActOnNamespaceAliasDef(Scope *S, SourceLocation NamespaceLoc, // Find the previous declaration and check that we can redeclare it. NamespaceAliasDecl *Prev = nullptr; if (NamedDecl *PrevDecl = PrevR.getAsSingle<NamedDecl>()) { - if (NamespaceAliasDecl *AD = dyn_cast<NamespaceAliasDecl>(PrevDecl)) { + if (NamespaceAliasDecl *AD = + dyn_cast<NamespaceAliasDecl>(PrevR.getRepresentativeDecl())) { // We already have an alias with the same name that points to the same // namespace; check that it matches. if (AD->getNamespace()->Equals(getNamespaceDecl(ND))) { @@ -8697,7 +8698,7 @@ Decl *Sema::ActOnNamespaceAliasDef(Scope *S, SourceLocation NamespaceLoc, } else if (isVisible(PrevDecl)) { Diag(AliasLoc, diag::err_redefinition_different_namespace_alias) << Alias; - Diag(PrevDecl->getLocation(), diag::note_previous_namespace_alias) + Diag(AD->getLocation(), diag::note_previous_namespace_alias) << AD->getNamespace(); return nullptr; } |