[cfe-commits] r136155 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaObjCProperty.cpp test/SemaObjC/arc.m
Argyrios Kyrtzidis
akyrtzi at gmail.com
Tue Jul 26 14:48:26 PDT 2011
Author: akirtzidis
Date: Tue Jul 26 16:48:26 2011
New Revision: 136155
URL: http://llvm.org/viewvc/llvm-project?rev=136155&view=rev
Log:
In ARC we emit an error when compiling:
@interface Foo : NSObject
@property (readonly) id myProp;
@end
@implementation Foo
@synthesize myProp;
@end
t.m:9:13: error: ARC forbids synthesizing a property of an Objective-C object with unspecified storage attribute
@synthesize myProp;
^
which is fine, we want the ownership of the synthesized ivar to be explicit. But we should _not_ emit an error
for the following cases, because we can get the ownership either from the declared ivar or from the property type:
@interface Foo : NSObject {
__weak id _myProp1;
id myProp2;
}
@property (readonly) id myProp1;
@property (readonly) id myProp2;
@property (readonly) __strong id myProp3;
@end
@implementation Foo
@synthesize myProp1 = _myProp1;
@synthesize myProp2;
@synthesize myProp3;
@end

rdar://9844006.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaObjCProperty.cpp
cfe/trunk/test/SemaObjC/arc.m
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=136155&r1=136154&r2=136155&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jul 26 16:48:26 2011
@@ -2627,7 +2627,7 @@
"ARC forbids Objective-C objects in structs or unions">;
def err_arc_objc_property_default_assign_on_object : Error<
"ARC forbids synthesizing a property of an Objective-C object "
- "with unspecified storage attribute">;
+ "with unspecified ownership or storage attribute">;
def err_arc_illegal_selector : Error<
"ARC forbids use of %0 in a @selector">;
def err_arc_illegal_method_def : Error<
Modified: cfe/trunk/lib/Sema/SemaObjCProperty.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaObjCProperty.cpp?rev=136155&r1=136154&r2=136155&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaObjCProperty.cpp (original)
+++ cfe/trunk/lib/Sema/SemaObjCProperty.cpp Tue Jul 26 16:48:26 2011
@@ -594,13 +594,6 @@
ObjCIvarDecl *Ivar = 0;
// Check that we have a valid, previously declared ivar for @synthesize
if (Synthesize) {
- if (getLangOptions().ObjCAutoRefCount &&
- !property->hasWrittenStorageAttribute() &&
- property->getType()->isObjCRetainableType()) {
- Diag(PropertyLoc, diag::err_arc_objc_property_default_assign_on_object);
- Diag(property->getLocation(), diag::note_property_declare);
- }
-
// @synthesize
if (!PropertyIvar)
PropertyIvar = PropertyId;
@@ -619,6 +612,13 @@
if (getLangOptions().ObjCAutoRefCount &&
!PropertyIvarType.getObjCLifetime()) {
+ if (!property->hasWrittenStorageAttribute() &&
+ property->getType()->isObjCRetainableType()) {
+ Diag(PropertyLoc,
+ diag::err_arc_objc_property_default_assign_on_object);
+ Diag(property->getLocation(), diag::note_property_declare);
+ }
+
// retain/copy have retaining lifetime.
if (kind & (ObjCPropertyDecl::OBJC_PR_retain |
ObjCPropertyDecl::OBJC_PR_strong |
Modified: cfe/trunk/test/SemaObjC/arc.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc.m?rev=136155&r1=136154&r2=136155&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/arc.m (original)
+++ cfe/trunk/test/SemaObjC/arc.m Tue Jul 26 16:48:26 2011
@@ -483,19 +483,31 @@
@end
// rdar://9525555
- at interface Test27
+ at interface Test27 {
+ __weak id _myProp1;
+ id myProp2;
+}
@property id x; // expected-warning {{no 'assign', 'retain', or 'copy' attribute is specified - 'assign' is assumed}} \
// expected-warning {{default property attribute 'assign' not appropriate for non-gc object}} \
// expected-note {{declared here}}
@property (readonly) id ro; // expected-note {{declared here}}
@property (readonly) id custom_ro;
@property int y;
+
+ at property (readonly) id myProp1;
+ at property (readonly) id myProp2;
+ at property (readonly) __strong id myProp3;
@end
@implementation Test27
- at synthesize x; // expected-error {{ARC forbids synthesizing a property of an Objective-C object with unspecified storage attribute}}
- at synthesize ro; // expected-error {{ARC forbids synthesizing a property of an Objective-C object with unspecified storage attribute}}
+ at synthesize x; // expected-error {{ARC forbids synthesizing a property of an Objective-C object with unspecified ownership or storage attribute}}
+ at synthesize ro; // expected-error {{ARC forbids synthesizing a property of an Objective-C object with unspecified ownership or storage attribute}}
@synthesize y;
+
+ at synthesize myProp1 = _myProp1;
+ at synthesize myProp2;
+ at synthesize myProp3;
+
-(id)custom_ro { return 0; }
@end
More information about the cfe-commits
mailing list