]> granicus.if.org Git - clang/commitdiff
objective-c: Ignore with warning forward class declaration whose name
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 24 Jan 2012 00:40:15 +0000 (00:40 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 24 Jan 2012 00:40:15 +0000 (00:40 +0000)
matches a typedef declaring an object type. // rdar://10733000

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDeclObjC.cpp
test/SemaObjC/forward-class-1.m
test/SemaObjC/forward-class-redeclare.m [new file with mode: 0644]
test/SemaObjC/typedef-class.m

index dfe49108acb9a3b5042c4e6348d404beb14a603f..73f3cda545b6c63cfa9a12335ece189e357b728d 100644 (file)
@@ -2809,6 +2809,9 @@ def err_redefinition_different_type : Error<
   "redefinition of %0 with a different type">;
 def err_redefinition_different_kind : Error<
   "redefinition of %0 as different kind of symbol">;
+def warn_forward_class_redefinition : Warning<
+  "redefinition of forward class %0 of a typedef name of an object type is ignored">,
+  InGroup<DiagGroup<"objc-forward-class-redefinition">>;
 def err_redefinition_different_typedef : Error<
   "%select{typedef|type alias|type alias template}0 redefinition with different types (%1 vs %2)">;
 def err_tag_reference_non_tag : Error<
index ff92453ca7fb00718a97d3862c0f72a0219b8783..4264b7105a7fbf7de8e984152cee3038999a9aed 100644 (file)
@@ -1776,17 +1776,22 @@ Sema::ActOnForwardClassDeclaration(SourceLocation AtClassLoc,
       // typedef NSObject < XCElementTogglerP > XCElementToggler;
       // @class XCElementToggler;
       //
-      // FIXME: Make an extension?
+      // Here we have chosen to ignore the forward class declaration
+      // with a warning. Since this is the implied behavior.
       TypedefNameDecl *TDD = dyn_cast<TypedefNameDecl>(PrevDecl);
       if (!TDD || !TDD->getUnderlyingType()->isObjCObjectType()) {
         Diag(AtClassLoc, diag::err_redefinition_different_kind) << IdentList[i];
         Diag(PrevDecl->getLocation(), diag::note_previous_definition);
       } else {
         // a forward class declaration matching a typedef name of a class refers
-        // to the underlying class.
-        if (const ObjCObjectType *OI =
-              TDD->getUnderlyingType()->getAs<ObjCObjectType>())
-          PrevDecl = OI->getInterface();
+        // to the underlying class. Just ignore the forward class with a warning
+        // as this will force the intended behavior which is to lookup the typedef
+        // name.
+        if (isa<ObjCObjectType>(TDD->getUnderlyingType())) {
+          Diag(AtClassLoc, diag::warn_forward_class_redefinition) << IdentList[i];
+          Diag(PrevDecl->getLocation(), diag::note_previous_definition);
+          continue;
+        }
       }
     }
     
index e8c36957a31d879b2fbd5d8d08ce851d514c1d40..30a06358c5ef2b839189deadb51c2cd78695c35d 100644 (file)
 
 @protocol XCElementP @end
 
-typedef NSObject <XCElementP> XCElement;
+typedef NSObject <XCElementP> XCElement; // expected-note {{previous definition is here}}
 
 @interface XCElementMainImp  {
   XCElement * _editingElement;
 }
 @end
 
-@class XCElement;
+@class XCElement; // expected-warning {{redefinition of forward class 'XCElement' of a typedef name of an object type is ignored}}
 
 @implementation XCElementMainImp
 - (XCElement *)editingElement  { return _editingElement;  }
diff --git a/test/SemaObjC/forward-class-redeclare.m b/test/SemaObjC/forward-class-redeclare.m
new file mode 100644 (file)
index 0000000..80dc335
--- /dev/null
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// rdar://10733000
+
+@interface NSObject @end
+
+@protocol PLAssetContainer
+@property (readonly, nonatomic, retain) id assets;
+@end
+
+
+typedef NSObject <PLAssetContainer> PLAlbum; // expected-note {{previous definition is here}}
+
+@class PLAlbum; // expected-warning {{redefinition of forward class 'PLAlbum' of a typedef name of an object type is ignore}}
+
+@interface PLPhotoBrowserController
+{
+    PLAlbum *_album;
+}
+@end
+
+@interface WPhotoViewController:PLPhotoBrowserController
+@end
+
+@implementation WPhotoViewController
+- (void)_prepareForContracting
+{
+  (void)_album.assets;
+}
+@end
index c983195b243e6d899826835afe274e2e69109d85..bd68397fd96950e88b1b308445a3d3037693714c 100644 (file)
@@ -48,13 +48,13 @@ typedef NSObject < XCElementSpacerP > XCElementSpacer;
 @protocol XCElementTogglerP < XCElementP > -(void) setDisplayed:(BOOL) displayed;
 @end
 
-typedef NSObject < XCElementTogglerP > XCElementToggler;
+typedef NSObject < XCElementTogglerP > XCElementToggler; // expected-note {{previous definition is here}}
 
 @interface XCElementRootFace:NSObject {} @end
 
 @interface XCElementFace:XCElementRootFace {} @end
 
-@class XCElementToggler; 
+@class XCElementToggler;  // expected-warning {{redefinition of forward class 'XCElementToggler' of a typedef name of an object type is ignored}}
 
 @interface XCRASlice:XCElementFace {} @end