Allow Objective-C entities to be declared within a transparent context
nested in the translation unit. This fixes <rdar://problem/6476070>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@61832 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/IdentifierResolver.cpp b/lib/Sema/IdentifierResolver.cpp
index 18e78a0..08c9bde 100644
--- a/lib/Sema/IdentifierResolver.cpp
+++ b/lib/Sema/IdentifierResolver.cpp
@@ -60,8 +60,7 @@
else
return TUCtx();
- while (Ctx->isTransparentContext())
- Ctx = Ctx->getParent();
+ Ctx = Ctx->getLookupContext();
if (isa<TranslationUnitDecl>(Ctx))
return TUCtx();
@@ -132,8 +131,7 @@
/// true if 'D' belongs to the given declaration context.
bool IdentifierResolver::isDeclInScope(Decl *D, DeclContext *Ctx,
ASTContext &Context, Scope *S) const {
- while (Ctx->isTransparentContext())
- Ctx = Ctx->getParent();
+ Ctx = Ctx->getLookupContext();
if (Ctx->isFunctionOrMethod()) {
// Ignore the scopes associated within transparent declaration contexts.
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 0e14150..79e443d 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -156,9 +156,7 @@
// We are pushing the name of a function, which might be an
// overloaded name.
FunctionDecl *FD = cast<FunctionDecl>(D);
- DeclContext *DC = FD->getDeclContext();
- while (DC->isTransparentContext())
- DC = DC->getParent();
+ DeclContext *DC = FD->getDeclContext()->getLookupContext();
IdentifierResolver::iterator Redecl
= std::find_if(IdResolver.begin(FD->getDeclName(), DC,
false/*LookInParentCtx*/),
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index cf1a525..c32a806 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -1647,7 +1647,7 @@
}
bool Sema::CheckObjCDeclScope(Decl *D) {
- if (isa<TranslationUnitDecl>(CurContext))
+ if (isa<TranslationUnitDecl>(CurContext->getLookupContext()))
return false;
Diag(D->getLocation(), diag::err_objc_decls_may_only_appear_in_global_scope);