diff options
| author | Steve Naroff <snaroff@apple.com> | 2009-02-04 17:14:05 +0000 |
|---|---|---|
| committer | Steve Naroff <snaroff@apple.com> | 2009-02-04 17:14:05 +0000 |
| commit | 189d41f625ebe2bfbb6dda5657cd4cb819dcd2b3 (patch) | |
| tree | 21b79bdc2113e2b268f8a5c5461db3b8666537b6 /clang/lib/Sema/SemaDeclObjC.cpp | |
| parent | 8a6be5ec640dbaa76b727979fb39f0d18879488e (diff) | |
| download | bcm5719-llvm-189d41f625ebe2bfbb6dda5657cd4cb819dcd2b3.tar.gz bcm5719-llvm-189d41f625ebe2bfbb6dda5657cd4cb819dcd2b3.zip | |
Fix <rdar://problem/6552648> error: redefinition of 'XCElementAnchorDelegate' as different kind of symbol.
At first glance, this looked like a recent regression (possibly created by http://llvm.org/viewvc/llvm-project?view=rev&revision=63354, which was the only recent change to this section of Sema::ActOnStartClassInterface()). After more investigation, it looks like an edge case bug that we didn't cover in our tests.
llvm-svn: 63738
Diffstat (limited to 'clang/lib/Sema/SemaDeclObjC.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaDeclObjC.cpp | 39 |
1 files changed, 27 insertions, 12 deletions
diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp index 3b0265e7033..7c76f162755 100644 --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/lib/Sema/SemaDeclObjC.cpp @@ -105,26 +105,41 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc, } if (SuperName) { - ObjCInterfaceDecl* SuperClassEntry = 0; // Check if a different kind of symbol declared in this scope. PrevDecl = LookupName(TUScope, SuperName, LookupOrdinaryName); - if (PrevDecl && !isa<ObjCInterfaceDecl>(PrevDecl)) { - Diag(SuperLoc, diag::err_redefinition_different_kind) << SuperName; - Diag(PrevDecl->getLocation(), diag::note_previous_definition); - } - else { - // Check that super class is previously defined - SuperClassEntry = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); - if (!SuperClassEntry) + ObjCInterfaceDecl *SuperClassDecl = + dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); + if (PrevDecl && SuperClassDecl == 0) { + // The previous declaration was not a class decl. Check if we have a + // typedef. If we do, get the underlying class type. + if (const TypedefDecl *TDecl = dyn_cast_or_null<TypedefDecl>(PrevDecl)) { + QualType T = TDecl->getUnderlyingType(); + if (T->isObjCInterfaceType()) { + if (NamedDecl *IDecl = T->getAsObjCInterfaceType()->getDecl()) + SuperClassDecl = dyn_cast<ObjCInterfaceDecl>(IDecl); + } + } + // This handles the following case: + // + // typedef int SuperClass; + // @interface MyClass : SuperClass {} @end + // + if (!SuperClassDecl) { + Diag(SuperLoc, diag::err_redefinition_different_kind) << SuperName; + Diag(PrevDecl->getLocation(), diag::note_previous_definition); + } + } + if (!dyn_cast_or_null<TypedefDecl>(PrevDecl)) { + if (!SuperClassDecl) Diag(SuperLoc, diag::err_undef_superclass) << SuperName << ClassName << SourceRange(AtInterfaceLoc, ClassLoc); - else if (SuperClassEntry->isForwardDecl()) + else if (SuperClassDecl->isForwardDecl()) Diag(SuperLoc, diag::err_undef_superclass) - << SuperClassEntry->getDeclName() << ClassName + << SuperClassDecl->getDeclName() << ClassName << SourceRange(AtInterfaceLoc, ClassLoc); } - IDecl->setSuperClass(SuperClassEntry); + IDecl->setSuperClass(SuperClassDecl); IDecl->setSuperClassLoc(SuperLoc); IDecl->setLocEnd(SuperLoc); } else { // we have a root class. |

