aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Naroff <snaroff@apple.com>2008-11-18 19:15:30 +0000
committerSteve Naroff <snaroff@apple.com>2008-11-18 19:15:30 +0000
commitcfe8bf31ad61a16458d5970734d4a300a7bd9b0a (patch)
treec54aef5163106ff3e0b43ac0184eb4220d76ae08
parente4d378815364255b002b4295162c290598fc899c (diff)
Fix <rdar://problem/6329769> [sema] crash on duplication definition of interface with protocols.
As soon as we detect duplicate interfaces, discontinue further semantic checks (returning the original interface). This is now consistent with how we handle protocols (and less error prone in general). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59541 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaDeclObjC.cpp9
-rw-r--r--test/SemaObjC/alias-test-2.m5
-rw-r--r--test/SemaObjC/check-dup-objc-decls-1.m11
3 files changed, 20 insertions, 5 deletions
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index 8eeb2d367d..49b990906a 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -75,9 +75,12 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
ObjCInterfaceDecl* IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl);
if (IDecl) {
// Class already seen. Is it a forward declaration?
- if (!IDecl->isForwardDecl())
+ if (!IDecl->isForwardDecl()) {
Diag(AtInterfaceLoc, diag::err_duplicate_class_def, IDecl->getName());
- else {
+ // Return the previous class interface.
+ // FIXME: don't leak the objects passed in!
+ return IDecl;
+ } else {
IDecl->setLocation(AtInterfaceLoc);
IDecl->setForwardDecl(false);
}
@@ -119,7 +122,7 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
IDecl->setLocEnd(ClassLoc);
}
- /// Check then save referenced protocols
+ /// Check then save referenced protocols.
if (NumProtoRefs) {
IDecl->addReferencedProtocols((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs);
IDecl->setLocEnd(EndProtoLoc);
diff --git a/test/SemaObjC/alias-test-2.m b/test/SemaObjC/alias-test-2.m
index 0a17846685..5f3bfcbba7 100644
--- a/test/SemaObjC/alias-test-2.m
+++ b/test/SemaObjC/alias-test-2.m
@@ -1,6 +1,7 @@
// RUN: clang -fsyntax-only -verify %s
-@interface Super @end
+// Note: GCC doesn't produce any of the following errors.
+@interface Super @end // expected-error {{previous definition is here}}
@interface MyWpModule @end
@@ -11,6 +12,6 @@
@interface MyAlias : AliasForSuper // expected-error {{duplicate interface declaration for class 'MyWpModule'}}
@end
-@implementation MyAlias : AliasForSuper
+@implementation MyAlias : AliasForSuper // expected-error {{conflicting super class name 'Super'}}
@end
diff --git a/test/SemaObjC/check-dup-objc-decls-1.m b/test/SemaObjC/check-dup-objc-decls-1.m
index e3902bdcca..8536a201de 100644
--- a/test/SemaObjC/check-dup-objc-decls-1.m
+++ b/test/SemaObjC/check-dup-objc-decls-1.m
@@ -26,3 +26,14 @@ void Gorf() // expected-error {{redefinition of 'Gorf' as different kind of symb
{
int Bar, Foo, FooBar;
}
+
+@protocol P -im1; @end
+@protocol Q -im2; @end
+@interface A<P> @end
+@interface A<Q> @end // expected-error {{duplicate interface declaration for class 'A'}}
+
+@protocol PP<P> @end
+@protocol PP<Q> @end // expected-error {{duplicate protocol declaration of 'PP'}}
+
+@interface A(Cat)<P> @end
+@interface A(Cat)<Q> @end // expected-warning {{duplicate interface declaration for category 'A(Cat)'}}