1 // RUN: %clang_cc1 -fsyntax-only -fblocks -fobjc-arc -verify -Wno-objc-root-class -Wno-strict-prototypes %s
14 // Volatile fields are fine.
43 id __attribute__((objc_ownership(none))) i;
52 __autoreleasing id X; // expected-error {{global variables cannot have __autoreleasing ownership}}
53 __autoreleasing NSError *E; // expected-error {{global variables cannot have __autoreleasing ownership}}
56 extern id __autoreleasing X1; // expected-error {{global variables cannot have __autoreleasing ownership}}
61 static id __autoreleasing X1; // expected-error {{global variables cannot have __autoreleasing ownership}}
62 extern id __autoreleasing E; // expected-error {{global variables cannot have __autoreleasing ownership}}
70 @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}}
71 @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}}
72 @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}}
73 @property (copy, nonatomic) id new;
74 @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}}
75 @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}}
76 @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}}
92 @interface MethodFamilyDiags
93 @property (retain) id newFoo; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}}
94 - (id)newFoo; // expected-note {{explicitly declare getter '-newFoo' with '__attribute__((objc_method_family(none)))' to return an 'unowned' object}}
96 #define OBJC_METHOD_FAMILY_NONE __attribute__((objc_method_family(none)))
97 - (id)newBar; // expected-note {{explicitly declare getter '-newBar' with 'OBJC_METHOD_FAMILY_NONE' to return an 'unowned' object}}
98 @property (retain) id newBar; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}}
100 @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}}
101 #undef OBJC_METHOD_FAMILY_NONE
103 @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}}
106 @interface MethodFamilyDiags (Redeclarations)
107 - (id)newGarply; // no note here
110 @implementation MethodFamilyDiags
111 @synthesize newGarply;
117 - (void)bar:(id)b; // expected-note {{parameter declared here}}
118 - (void)bar1:(id) __attribute((ns_consumed)) b;
119 - (void)ok:(id) __attribute((ns_consumed)) b;
120 - (id)ns_non; // expected-note {{method declared here}}
121 - (id)not_ret:(id) b __attribute((ns_returns_not_retained)); // expected-note {{method declared here}}
122 - (id)both__returns_not_retained:(id) b __attribute((ns_returns_not_retained));
125 @interface Sub : Super
126 - (void)bar:(id) __attribute((ns_consumed)) b; // expected-error {{overriding method has mismatched ns_consumed attribute on its parameter}}
128 - (void)ok:(id) __attribute((ns_consumed)) b;
129 - (id)ns_non __attribute((ns_returns_not_retained)); // expected-error {{overriding method has mismatched ns_returns_not_retained attributes}}
130 - (id)not_ret:(id) b __attribute((ns_returns_retained)); // expected-error {{overriding method has mismatched ns_returns_retained attributes}}
131 - (id)both__returns_not_retained:(id) b __attribute((ns_returns_not_retained));
133 @property (copy, nonatomic) __attribute__((ns_returns_retained)) id (^fblock)(void);
136 // Test that we give a good diagnostic here that mentions the missing
137 // ownership qualifier. We don't want this to get suppressed because
138 // of an invalid conversion.
141 id *px = &x; // expected-error {{pointer to non-const type 'id' with no explicit ownership}}
144 J **py = &y; // expected-error {{pointer to non-const type 'J *' with no explicit ownership}} expected-warning {{incompatible pointer types initializing}}
147 void func(void) __attribute__((objc_ownership(none))); // expected-warning {{'objc_ownership' only applies to Objective-C object or block pointer types; type here is 'void (void)'}}
148 struct __attribute__((objc_ownership(none))) S2 {}; // expected-error {{'objc_ownership' attribute only applies to variables}}
150 @property __attribute__((objc_ownership(frob))) id i; // expected-warning {{'objc_ownership' attribute argument not supported: 'frob'}}
154 @interface NSObject @end
156 @interface ControllerClass : NSObject @end
158 @interface SomeClassOwnedByController
159 @property (readonly) ControllerClass *controller; // expected-note {{property declared here}}
162 @property (readonly, weak) ControllerClass *weak_controller;
165 @interface SomeClassOwnedByController ()
166 @property (readwrite, weak) ControllerClass *controller; // expected-warning {{primary property declaration is implicitly strong while redeclaration in class extension is weak}}
168 @property (readwrite, weak) ControllerClass *weak_controller;
182 // FIXME: clang should diagnose mismatch between methods in D3(Cat1) and
184 - (id)method __attribute__((ns_returns_retained));