]> granicus.if.org Git - clang/commitdiff
a forward class declaration matching a typedef name of a class
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 7 May 2009 21:49:26 +0000 (21:49 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 7 May 2009 21:49:26 +0000 (21:49 +0000)
refers to the underlying class.
This is radar 6859726. Steve, please read the radar for my rational.

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

lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/forward-class-1.m

index 0e655a493da9ae0d0c661fd12e00d508450be76e..27f127716e5d1401784d9042b814c0d563932293 100644 (file)
@@ -1075,6 +1075,13 @@ Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc,
         Diag(AtClassLoc, diag::err_redefinition_different_kind) << IdentList[i];
         Diag(PrevDecl->getLocation(), diag::note_previous_definition);
       }
+      else if (TDD) {
+        // a forward class declaration matching a typedef name of a class
+        // refers to the underlying class.
+        if (ObjCInterfaceType * OI = 
+              dyn_cast<ObjCInterfaceType>(TDD->getUnderlyingType()))
+          PrevDecl = OI->getDecl();
+      }
     }
     ObjCInterfaceDecl *IDecl = dyn_cast_or_null<ObjCInterfaceDecl>(PrevDecl); 
     if (!IDecl) {  // Not already seen?  Make a forward decl.
index d8eb311cf446e7f76358c648694fa4459244ec62..f5f9505666726da2654fde9b937e2b64f46fe05a 100644 (file)
 
 @interface INTF2 : INTF1 // expected-error {{duplicate interface definition for class 'INTF2'}}
 @end
+
+// 2nd test of a forward class declaration matching a typedef name
+// referring to class object.
+// FIXME. This may become a negative test should we decide to make this an error.
+//
+@interface NSObject @end
+
+@protocol XCElementP @end
+
+typedef NSObject <XCElementP> XCElement;
+
+@interface XCElementMainImp  {
+  XCElement * _editingElement;
+}
+@end
+
+@class XCElement;
+
+@implementation XCElementMainImp
+- (XCElement *)editingElement  { return _editingElement;  }
+@end
+
+