]> granicus.if.org Git - clang/commitdiff
When forming a cycle in objc's inheritance hierarchy,
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 23 Jun 2011 23:16:19 +0000 (23:16 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 23 Jun 2011 23:16:19 +0000 (23:16 +0000)
diagnose it properly and don't throw clang into an
infinit loop. // rdar://9653341

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133773 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/class-proto-1.m
test/SemaObjC/forward-class-1.m
test/SemaObjC/undef-superclass-1.m

index c734c064e7feba4f5ba76bffdc446120106e4d0c..84aac0c14f90b51646f2cdffa5588459bf3b796b 100644 (file)
@@ -330,6 +330,8 @@ def err_duplicate_class_def : Error<
   "duplicate interface definition for class %0">;
 def err_undef_superclass : Error<
   "cannot find interface declaration for %0, superclass of %1">;
+def err_forward_superclass : Error<
+  "attempting to use the forward class %0 as superclass of %1">;
 def err_no_nsconstant_string_class : Error<
   "cannot find interface declaration for %0">;
 def err_recursive_superclass : Error<
index b54e2425b2cdb508d1d07d6d9f3c465f62ddb8ee..3bbe421cd144b2cfcc9a8cbfef55ad56faf58cc2 100644 (file)
@@ -491,10 +491,13 @@ ActOnStartClassInterface(SourceLocation AtInterfaceLoc,
         if (!SuperClassDecl)
           Diag(SuperLoc, diag::err_undef_superclass)
             << SuperName << ClassName << SourceRange(AtInterfaceLoc, ClassLoc);
-        else if (SuperClassDecl->isForwardDecl())
-          Diag(SuperLoc, diag::err_undef_superclass)
+        else if (SuperClassDecl->isForwardDecl()) {
+          Diag(SuperLoc, diag::err_forward_superclass)
             << SuperClassDecl->getDeclName() << ClassName
             << SourceRange(AtInterfaceLoc, ClassLoc);
+          Diag(SuperClassDecl->getLocation(), diag::note_forward_class);
+          SuperClassDecl = 0;
+        }
       }
       IDecl->setSuperClass(SuperClassDecl);
       IDecl->setSuperClassLoc(SuperLoc);
index 246b5002f67f4a0214c8231cc4518b2293ed9335..80309764335b77a4c8d8171a938f696f0df0a3e5 100644 (file)
@@ -23,9 +23,9 @@
 
 @interface E2 <p1,p2,p3> @end  // expected-warning {{cannot find protocol definition for 'p3'}}
 
-@class U1, U2;
+@class U1, U2; // expected-note {{forward class is declared here}}
 
-@interface E3 : U1 @end // expected-error {{cannot find interface declaration for 'U1', superclass of 'E3'}}
+@interface E3 : U1 @end // expected-error {{attempting to use the forward class 'U1' as superclass of 'E3'}}
 
 
 @interface I3 : E3  @end
index ab213fb4ce723c6a8060dc5966b47bc31fbf3c9e..de94e884aee2735de81ae637f5f7a0a1ddc07ee4 100644 (file)
@@ -1,9 +1,9 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
-@class FOO, BAR;
+@class FOO, BAR; // expected-note {{forward class is declared here}}
 @class FOO, BAR;
 
-@interface INTF : FOO  // expected-error {{cannot find interface declaration for 'FOO', superclass of 'INTF'}}
+@interface INTF : FOO  // expected-error {{attempting to use the forward class 'FOO' as superclass of 'INTF'}}
 @end
 
 @interface FOO 
@@ -45,3 +45,14 @@ typedef NSObject <XCElementP> XCElement;
 @end
 
 
+// rdar://9653341
+@class B; // expected-note {{forward class is declared here}}
+@interface A : B {} // expected-error {{attempting to use the forward class 'B' as superclass of 'A'}}
+@end
+
+@interface B : A {}
+@end
+
+@implementation A @end
+@implementation B @end
+
index c941f82e435c9bc53af9ecb6b770f4909fa43e16..41cf1439bd9c7d34f01525984f6ce17b7489cc67 100644 (file)
@@ -1,8 +1,8 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
-@class SUPER, Y;
+@class SUPER, Y; // expected-note 2 {{forward class is declared here}}
 
-@interface INTF :SUPER  // expected-error {{cannot find interface declaration for 'SUPER', superclass of 'INTF'}}
+@interface INTF :SUPER  // expected-error {{attempting to use the forward class 'SUPER' as superclass of 'INTF'}}
 @end
 
 @interface SUPER @end
@@ -13,7 +13,7 @@
 @interface INTF2 : INTF1
 @end
 
-@interface INTF3 : Y // expected-error {{cannot find interface declaration for 'Y', superclass of 'INTF3'}} \
+@interface INTF3 : Y // expected-error {{attempting to use the forward class 'Y' as superclass of 'INTF3'}} \
                      // expected-note{{'INTF3' declared here}}
 @end