has inconsistent ownership with the backing ivar, point the error location to the
ivar.
Pointing to the ivar (instead of the @synthesize) is better since this is where a fix is needed.
Also provide the location of @synthesize via a note.
This also fixes the problem where an auto-synthesized property would emit an error without
any location.
llvm-svn: 170039
"class implementation">;
def note_property_declare : Note<
"property declared here">;
+def note_property_synthesize : Note<
+ "property synthesized here">;
def error_synthesize_category_decl : Error<
"@synthesize not allowed in a category's implementation">;
def error_reference_property : Error<
for (PropsTy::iterator I = props.begin(), E = props.end(); I != E; ++I) {
if (I->ImplD)
- Pass.TA.clearDiagnostic(diag::err_arc_assign_property_ownership,
- I->ImplD->getLocation());
+ Pass.TA.clearDiagnostic(diag::err_arc_strong_property_ownership,
+ diag::err_arc_assign_property_ownership,
+ diag::err_arc_inconsistent_property_ownership,
+ I->IvarD->getLocation());
}
}
}
}
if (I->ImplD)
- Pass.TA.clearDiagnostic(diag::err_arc_assign_property_ownership,
- I->ImplD->getLocation());
+ Pass.TA.clearDiagnostic(diag::err_arc_strong_property_ownership,
+ diag::err_arc_assign_property_ownership,
+ diag::err_arc_inconsistent_property_ownership,
+ I->IvarD->getLocation());
}
}
canUseWeak ? "__weak " : "__unsafe_unretained ");
}
if (I->ImplD) {
- Pass.TA.clearDiagnostic(diag::err_arc_assign_property_ownership,
- I->ImplD->getLocation());
+ Pass.TA.clearDiagnostic(diag::err_arc_strong_property_ownership,
+ diag::err_arc_assign_property_ownership,
+ diag::err_arc_inconsistent_property_ownership,
+ I->IvarD->getLocation());
Pass.TA.clearDiagnostic(
diag::err_arc_objc_property_default_assign_on_object,
I->ImplD->getLocation());
switch (propertyLifetime) {
case Qualifiers::OCL_Strong:
- S.Diag(propertyImplLoc, diag::err_arc_strong_property_ownership)
+ S.Diag(ivar->getLocation(), diag::err_arc_strong_property_ownership)
<< property->getDeclName()
<< ivar->getDeclName()
<< ivarLifetime;
break;
case Qualifiers::OCL_Weak:
- S.Diag(propertyImplLoc, diag::error_weak_property)
+ S.Diag(ivar->getLocation(), diag::error_weak_property)
<< property->getDeclName()
<< ivar->getDeclName();
break;
case Qualifiers::OCL_ExplicitNone:
- S.Diag(propertyImplLoc, diag::err_arc_assign_property_ownership)
+ S.Diag(ivar->getLocation(), diag::err_arc_assign_property_ownership)
<< property->getDeclName()
<< ivar->getDeclName()
<< ((property->getPropertyAttributesAsWritten()
}
S.Diag(property->getLocation(), diag::note_property_declare);
+ if (propertyImplLoc.isValid())
+ S.Diag(propertyImplLoc, diag::note_property_synthesize);
}
/// setImpliedPropertyAttributeForReadOnlyProperty -
-// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s
+// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-default-synthesize-properties -fobjc-runtime-has-weak -fsyntax-only -fobjc-arc -verify -Wno-objc-root-class %s
// rdar://9340606
@interface Foo {
@public
- id __unsafe_unretained x;
- id __weak y;
+ id __unsafe_unretained x; // expected-error {{existing instance variable 'x' for strong property 'x' may not be __unsafe_unretained}}
+ id __weak y; // expected-error {{existing instance variable 'y' for strong property 'y' may not be __weak}}
id __autoreleasing z; // expected-error {{instance variables cannot have __autoreleasing ownership}}
}
@property(strong) id x; // expected-note {{property declared here}}
@end
@implementation Foo
-@synthesize x; // expected-error {{existing instance variable 'x' for strong property 'x' may not be __unsafe_unretained}}
-@synthesize y; // expected-error {{existing instance variable 'y' for strong property 'y' may not be __weak}}
+@synthesize x; // expected-note {{property synthesized here}}
+@synthesize y; // expected-note {{property synthesized here}}
@synthesize z; // suppressed
@end
@interface Bar {
@public
- id __unsafe_unretained x;
- id __weak y;
+ id __unsafe_unretained x; // expected-error {{existing instance variable 'x' for strong property 'x' may not be __unsafe_unretained}}
+ id __weak y; // expected-error {{existing instance variable 'y' for strong property 'y' may not be __weak}}
id __autoreleasing z; // expected-error {{instance variables cannot have __autoreleasing ownership}}
}
@property(retain) id x; // expected-note {{property declared here}}
@end
@implementation Bar
-@synthesize x; // expected-error {{existing instance variable 'x' for strong property 'x' may not be __unsafe_unretained}}
-@synthesize y; // expected-error {{existing instance variable 'y' for strong property 'y' may not be __weak}}
+@synthesize x; // expected-note {{property synthesized here}}
+@synthesize y; // expected-note {{property synthesized here}}
@synthesize z; // suppressed
@end
@interface Bas {
@public
- id __unsafe_unretained x;
- id __weak y;
+ id __unsafe_unretained x; // expected-error {{existing instance variable 'x' for strong property 'x' may not be __unsafe_unretained}}
+ id __weak y; // expected-error {{existing instance variable 'y' for strong property 'y' may not be __weak}}
id __autoreleasing z; // expected-error {{instance variables cannot have __autoreleasing ownership}}
}
@property(copy) id x; // expected-note {{property declared here}}
@end
@implementation Bas
-@synthesize x; // expected-error {{existing instance variable 'x' for strong property 'x' may not be __unsafe_unretained}}
-@synthesize y; // expected-error {{existing instance variable 'y' for strong property 'y' may not be __weak}}
+@synthesize x; // expected-note {{property synthesized here}}
+@synthesize y; // expected-note {{property synthesized here}}
@synthesize z; // suppressed
@end
// rdar://9341593
@interface Gorf {
id __unsafe_unretained x;
- id y;
+ id y; // expected-error {{existing instance variable 'y' for property 'y' with assign attribute must be __unsafe_unretained}}
}
@property(assign) id __unsafe_unretained x;
@property(assign) id y; // expected-note {{property declared here}}
@implementation Gorf
@synthesize x;
-@synthesize y; // expected-error {{existing instance variable 'y' for property 'y' with assign attribute must be __unsafe_unretained}}
+@synthesize y; // expected-note {{property synthesized here}}
@synthesize z;
@end
@interface Gorf2 {
id __unsafe_unretained x;
- id y;
+ id y; // expected-error {{existing instance variable 'y' for property 'y' with unsafe_unretained attribute must be __unsafe_unretained}}
}
@property(unsafe_unretained) id __unsafe_unretained x;
@property(unsafe_unretained) id y; // expected-note {{property declared here}}
@implementation Gorf2
@synthesize x;
-@synthesize y; // expected-error {{existing instance variable 'y' for property 'y' with unsafe_unretained attribute must be __unsafe_unretained}}
+@synthesize y; // expected-note {{property synthesized here}}
@synthesize z;
@end
@interface Boom
@property (readonly) const void * innerPointer __attribute__((objc_returns_inner_pointer)); // expected-error {{'objc_returns_inner_pointer' attribute only applies to methods}}
@end
+
+@interface Foo2 {
+ id _prop; // expected-error {{existing instance variable '_prop' for property 'prop' with assign attribute must be __unsafe_unretained}}
+}
+@property (nonatomic, assign) id prop; // expected-note {{property declared here}}
+@end
+
+@implementation Foo2
+@end
// rdar://9309489
@interface MyClass {
- id __weak myString;
+ id __weak myString; // expected-error {{existing instance variable 'myString' for strong property 'myString' may not be __weak}}
id StrongIvar;
- id __weak myString2;
+ id __weak myString2; // expected-error {{existing instance variable 'myString2' for strong property 'myString2' may not be __weak}}
id __weak myString3;
- id StrongIvar5;
+ id StrongIvar5; // expected-error {{existing instance variable 'StrongIvar5' for __weak property 'myString5' must be __weak}}
}
@property (strong) id myString; // expected-note {{property declared here}}
@property (strong) id myString1;
@end
@implementation MyClass
-@synthesize myString; // expected-error {{existing instance variable 'myString' for strong property 'myString' may not be __weak}}
+@synthesize myString; // expected-note {{property synthesized here}}
@synthesize myString1 = StrongIvar; // OK
-@synthesize myString2 = myString2; // expected-error {{existing instance variable 'myString2' for strong property 'myString2' may not be __weak}}
+@synthesize myString2 = myString2; // expected-note {{property synthesized here}}
//
@synthesize myString3; // OK
@synthesize myString4; // OK
-@synthesize myString5 = StrongIvar5; // expected-error {{existing instance variable 'StrongIvar5' for __weak property 'myString5' must be __weak}}
+@synthesize myString5 = StrongIvar5; // expected-note {{property synthesized here}}
@end
// rdar://9340692
@interface Foo {
@public
- id __unsafe_unretained x; // should be __weak
- id __strong y;
+ id __unsafe_unretained x; // expected-error {{existing instance variable 'x' for __weak property 'x' must be __weak}}
+ id __strong y; // expected-error {{existing instance variable 'y' for __weak property 'y' must be __weak}}
id __autoreleasing z; // expected-error {{instance variables cannot have __autoreleasing ownership}}
}
@property(weak) id x; // expected-note {{property declared here}}
@end
@implementation Foo
-@synthesize x; // expected-error {{existing instance variable 'x' for __weak property 'x' must be __weak}}
-@synthesize y; // expected-error {{existing instance variable 'y' for __weak property 'y' must be __weak}}
+@synthesize x; // expected-note {{property synthesized here}}
+@synthesize y; // expected-note {{property synthesized here}}
@synthesize z; // suppressed
@end
__attribute__((objc_root_class)) @interface MyObject {
@public
id _myMaster;
- id _isTickledPink;
+ id _isTickledPink; // expected-error {{existing instance variable '_isTickledPink' for property 'isTickledPink'}}
int _myIntProp;
}
@property(retain) id myMaster;
@implementation MyObject
@synthesize myMaster = _myMaster;
-@synthesize isTickledPink = _isTickledPink; // expected-error {{existing instance variable '_isTickledPink' for property 'isTickledPink'}}
+@synthesize isTickledPink = _isTickledPink; // expected-note {{property synthesized here}}
@synthesize myIntProp = _myIntProp;
- (void) doSomething {
@interface WeakPropertyTest {
Class isa;
__weak id value;
- id x;
+ id x; // expected-error {{existing instance variable 'x' for __weak property 'x' must be __weak}}
}
@property (weak) id value1;
@property __weak id value;
@end
@implementation WeakPropertyTest
-@synthesize x; // expected-error {{existing instance variable 'x' for __weak property 'x' must be __weak}}
+@synthesize x; // expected-note {{property synthesized here}}
@dynamic value1, value, value2, v1,v2,v3,v4;
@end