]> granicus.if.org Git - clang/commitdiff
Fix <rdar://problem/6329769> [sema] crash on duplication definition of interface...
authorSteve Naroff <snaroff@apple.com>
Tue, 18 Nov 2008 19:15:30 +0000 (19:15 +0000)
committerSteve Naroff <snaroff@apple.com>
Tue, 18 Nov 2008 19:15:30 +0000 (19:15 +0000)
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

lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/alias-test-2.m
test/SemaObjC/check-dup-objc-decls-1.m

index 8eeb2d367d709387cae586e07d4aaa04352a2d38..49b990906a2f580eca1fa95802aff564dff2ff77 100644 (file)
@@ -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);
index 0a17846685cd58d931d6fe5bc72639afdf9c2506..5f3bfcbba7539479927bbcc7a513084186e720ab 100644 (file)
@@ -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
 
index e3902bdcca32154bfae6c5bb3472a60a280aa1aa..8536a201def0e6d2538b1a394202e839de1ea449 100644 (file)
@@ -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)'}}