Several name lookup conflict detection fixes involving objective-c names.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@43000 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 65f6708..59a2d1d 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -945,6 +945,9 @@
// Chain & install the interface decl into the identifier.
IDecl->setNext(ClassName->getFETokenInfo<ScopedDecl>());
ClassName->setFETokenInfo(IDecl);
+
+ // Remember that this needs to be removed when the scope is popped.
+ TUScope->AddDecl(IDecl);
}
if (SuperName) {
@@ -1214,6 +1217,8 @@
IDecl->setNext(ClassName->getFETokenInfo<ScopedDecl>());
ClassName->setFETokenInfo(IDecl);
+ // Remember that this needs to be removed when the scope is popped.
+ TUScope->AddDecl(IDecl);
}
// Check that there is no duplicate implementation of this class.
@@ -1397,9 +1402,16 @@
llvm::SmallVector<ObjcInterfaceDecl*, 32> Interfaces;
for (unsigned i = 0; i != NumElts; ++i) {
- ObjcInterfaceDecl *IDecl = getObjCInterfaceDecl(IdentList[i]);
+ // Check for another declaration kind with the same name.
+ ScopedDecl *PrevDecl = LookupInterfaceDecl(IdentList[i]);
+ if (PrevDecl && !isa<ObjcInterfaceDecl>(PrevDecl)) {
+ Diag(AtClassLoc, diag::err_redefinition_different_kind,
+ IdentList[i]->getName());
+ Diag(PrevDecl->getLocation(), diag::err_previous_definition);
+ }
+ ObjcInterfaceDecl *IDecl = dyn_cast_or_null<ObjcInterfaceDecl>(PrevDecl);
if (!IDecl) { // Not already seen? Make a forward decl.
- IDecl = new ObjcInterfaceDecl(SourceLocation(), 0, IdentList[i], true);
+ IDecl = new ObjcInterfaceDecl(AtClassLoc, 0, IdentList[i], true);
// Chain & install the interface decl into the identifier.
IDecl->setNext(IdentList[i]->getFETokenInfo<ScopedDecl>());
IdentList[i]->setFETokenInfo(IDecl);