diff options
author | Jordan Rose <jordan_rose@apple.com> | 2015-01-16 23:04:31 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2015-01-16 23:04:31 +0000 |
commit | a34d04d35e72c9104c32e2f772b8bccab7f0cd33 (patch) | |
tree | d11a22b32d20a9434fbcff50b82962ee4dda18e5 /clang/test | |
parent | 16ba553f754a6ab6c934deaa6232be1cb74db904 (diff) | |
download | bcm5719-llvm-a34d04d35e72c9104c32e2f772b8bccab7f0cd33.tar.gz bcm5719-llvm-a34d04d35e72c9104c32e2f772b8bccab7f0cd33.zip |
Suggest objc_method_family(none) for a property named -newFoo or similar.
As mentioned in the previous commit, if a property (declared with @property)
has a name that matches a special Objective-C method family, the getter picks
up that family despite being declared by the property. The most correct way
to solve this problem is to add the 'objc_method_family' attribute to the
getter with an argument of 'none', which unfortunately requires an explicit
declaration of the getter.
This commit adds a note to the existing error (ARC) or warning (MRR) for
such a poorly-named property that suggests the solution; if there's already
a declaration of the getter, it even includes a fix-it.
llvm-svn: 226339
Diffstat (limited to 'clang/test')
-rw-r--r-- | clang/test/SemaObjC/arc-decls.m | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/clang/test/SemaObjC/arc-decls.m b/clang/test/SemaObjC/arc-decls.m index 7fcf576f700..c1c319d95e3 100644 --- a/clang/test/SemaObjC/arc-decls.m +++ b/clang/test/SemaObjC/arc-decls.m @@ -54,13 +54,13 @@ void func() // rdar://15757510 @interface J -@property (retain) id newFoo; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} -@property (strong) id copyBar; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} -@property (copy) id allocBaz; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} +@property (retain) id newFoo; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} expected-note{{explicitly declare getter '-newFoo' with '__attribute__((objc_method_family(none)))' to return an 'unowned' object}} +@property (strong) id copyBar; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} expected-note{{explicitly declare getter '-copyBar' with '__attribute__((objc_method_family(none)))' to return an 'unowned' object}} +@property (copy) id allocBaz; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} expected-note{{explicitly declare getter '-allocBaz' with '__attribute__((objc_method_family(none)))' to return an 'unowned' object}} @property (copy, nonatomic) id new; -@property (retain) id newDFoo; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} -@property (strong) id copyDBar; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} -@property (copy) id allocDBaz; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} +@property (retain) id newDFoo; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} expected-note{{explicitly declare getter '-newDFoo' with '__attribute__((objc_method_family(none)))' to return an 'unowned' object}} +@property (strong) id copyDBar; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} expected-note{{explicitly declare getter '-copyDBar' with '__attribute__((objc_method_family(none)))' to return an 'unowned' object}} +@property (copy) id allocDBaz; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} expected-note{{explicitly declare getter '-allocDBaz' with '__attribute__((objc_method_family(none)))' to return an 'unowned' object}} @end @implementation J @@ -76,6 +76,29 @@ void func() @end +@interface MethodFamilyDiags +@property (retain) id newFoo; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} +- (id)newFoo; // expected-note {{explicitly declare getter '-newFoo' with '__attribute__((objc_method_family(none)))' to return an 'unowned' object}} + +#define OBJC_METHOD_FAMILY_NONE __attribute__((objc_method_family(none))) +- (id)newBar; // expected-note {{explicitly declare getter '-newBar' with 'OBJC_METHOD_FAMILY_NONE' to return an 'unowned' object}} +@property (retain) id newBar; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} + +@property (retain) id newBaz; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} expected-note {{explicitly declare getter '-newBaz' with 'OBJC_METHOD_FAMILY_NONE' to return an 'unowned' object}} +#undef OBJC_METHOD_FAMILY_NONE + +@property (retain, readonly) id newGarply; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} expected-note {{explicitly declare getter '-newGarply' with '__attribute__((objc_method_family(none)))' to return an 'unowned' object}} +@end + +@interface MethodFamilyDiags (Redeclarations) +- (id)newGarply; // no note here +@end + +@implementation MethodFamilyDiags +@synthesize newGarply; +@end + + // rdar://10187884 @interface Super - (void)bar:(id)b; // expected-note {{parameter declared here}} |