aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)'}}