[cfe-commits] r148760 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclObjC.cpp test/SemaObjC/forward-class-1.m test/SemaObjC/forward-class-redeclare.m test/SemaObjC/typedef-class.m

Fariborz Jahanian fjahanian at apple.com
Mon Jan 23 16:40:15 PST 2012


Author: fjahanian
Date: Mon Jan 23 18:40:15 2012
New Revision: 148760

URL: http://llvm.org/viewvc/llvm-project?rev=148760&view=rev
Log:
objective-c: Ignore with warning forward class declaration whose name
matches a typedef declaring an object type. // rdar://10733000

Added:
    cfe/trunk/test/SemaObjC/forward-class-redeclare.m
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/test/SemaObjC/forward-class-1.m
    cfe/trunk/test/SemaObjC/typedef-class.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=148760&r1=148759&r2=148760&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Jan 23 18:40:15 2012
@@ -2809,6 +2809,9 @@
   "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<

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=148760&r1=148759&r2=148760&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Mon Jan 23 18:40:15 2012
@@ -1776,17 +1776,22 @@
       // 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;
+        }
       }
     }
     

Modified: cfe/trunk/test/SemaObjC/forward-class-1.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/forward-class-1.m?rev=148760&r1=148759&r2=148760&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/forward-class-1.m (original)
+++ cfe/trunk/test/SemaObjC/forward-class-1.m Mon Jan 23 18:40:15 2012
@@ -31,14 +31,14 @@
 
 @protocol XCElementP @end
 
-typedef NSObject <XCElementP> XCElement;
+typedef NSObject <XCElementP> XCElement; // expected-note {{previous definition is here}}
 
 @interface XCElementMainImp  {
   XCElement * _editingElement;
 }
 @end
 
- at class XCElement;
+ at 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;  }

Added: cfe/trunk/test/SemaObjC/forward-class-redeclare.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/forward-class-redeclare.m?rev=148760&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/forward-class-redeclare.m (added)
+++ cfe/trunk/test/SemaObjC/forward-class-redeclare.m Mon Jan 23 18:40:15 2012
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// rdar://10733000
+
+ at interface NSObject @end
+
+ at protocol PLAssetContainer
+ at property (readonly, nonatomic, retain) id assets;
+ at end
+
+
+typedef NSObject <PLAssetContainer> PLAlbum; // expected-note {{previous definition is here}}
+
+ at class PLAlbum; // expected-warning {{redefinition of forward class 'PLAlbum' of a typedef name of an object type is ignore}}
+
+ at interface PLPhotoBrowserController
+{
+    PLAlbum *_album;
+}
+ at end
+
+ at interface WPhotoViewController:PLPhotoBrowserController
+ at end
+
+ at implementation WPhotoViewController
+- (void)_prepareForContracting
+{
+  (void)_album.assets;
+}
+ at end

Modified: cfe/trunk/test/SemaObjC/typedef-class.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/typedef-class.m?rev=148760&r1=148759&r2=148760&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/typedef-class.m (original)
+++ cfe/trunk/test/SemaObjC/typedef-class.m Mon Jan 23 18:40:15 2012
@@ -48,13 +48,13 @@
 @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
 
- at class XCElementToggler; 
+ at class XCElementToggler;  // expected-warning {{redefinition of forward class 'XCElementToggler' of a typedef name of an object type is ignored}}
 
 @interface XCRASlice:XCElementFace {} @end
 





More information about the cfe-commits mailing list