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);
}
IDecl->setLocEnd(ClassLoc);
}
- /// Check then save referenced protocols
+ /// Check then save referenced protocols.
if (NumProtoRefs) {
IDecl->addReferencedProtocols((ObjCProtocolDecl**)ProtoRefs, NumProtoRefs);
IDecl->setLocEnd(EndProtoLoc);
// 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
@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
{
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)'}}