| 1 |
// RUN: %clang_cc1 -fsyntax-only -fblocks -fobjc-arc -verify -Wno-objc-root-class -Wno-strict-prototypes %s |
| 2 |
|
| 3 |
struct A { |
| 4 |
id x[4]; |
| 5 |
id y; |
| 6 |
}; |
| 7 |
|
| 8 |
union u { |
| 9 |
id u; |
| 10 |
}; |
| 11 |
|
| 12 |
// Volatile fields are fine. |
| 13 |
struct C { |
| 14 |
volatile int x[4]; |
| 15 |
volatile int y; |
| 16 |
}; |
| 17 |
|
| 18 |
union u_trivial_c { |
| 19 |
volatile int b; |
| 20 |
struct C c; |
| 21 |
}; |
| 22 |
|
| 23 |
@interface I { |
| 24 |
struct A a; |
| 25 |
struct B { |
| 26 |
id y[10][20]; |
| 27 |
id z; |
| 28 |
} b; |
| 29 |
|
| 30 |
union u c; |
| 31 |
}; |
| 32 |
@end |
| 33 |
|
| 34 |
struct r10260525 { |
| 35 |
id (^block1) (); |
| 36 |
id (^block2) (void); |
| 37 |
}; |
| 38 |
|
| 39 |
struct S { |
| 40 |
id __attribute__((objc_ownership(none))) i; |
| 41 |
void * vp; |
| 42 |
int i1; |
| 43 |
}; |
| 44 |
|
| 45 |
@class NSError; |
| 46 |
|
| 47 |
__autoreleasing id X; // expected-error {{global variables cannot have __autoreleasing ownership}} |
| 48 |
__autoreleasing NSError *E; // expected-error {{global variables cannot have __autoreleasing ownership}} |
| 49 |
|
| 50 |
|
| 51 |
extern id __autoreleasing X1; // expected-error {{global variables cannot have __autoreleasing ownership}} |
| 52 |
|
| 53 |
void func(void) |
| 54 |
{ |
| 55 |
id X; |
| 56 |
static id __autoreleasing X1; // expected-error {{global variables cannot have __autoreleasing ownership}} |
| 57 |
extern id __autoreleasing E; // expected-error {{global variables cannot have __autoreleasing ownership}} |
| 58 |
|
| 59 |
} |
| 60 |
|
| 61 |
@interface J |
| 62 |
@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}} |
| 63 |
@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}} |
| 64 |
@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}} |
| 65 |
@property (copy, nonatomic) id new; |
| 66 |
@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}} |
| 67 |
@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}} |
| 68 |
@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}} |
| 69 |
@end |
| 70 |
|
| 71 |
@implementation J |
| 72 |
@synthesize newFoo; |
| 73 |
@synthesize copyBar; |
| 74 |
@synthesize allocBaz; |
| 75 |
@synthesize new; |
| 76 |
- new {return 0; }; |
| 77 |
|
| 78 |
@dynamic newDFoo; |
| 79 |
@dynamic copyDBar; |
| 80 |
@dynamic allocDBaz; |
| 81 |
@end |
| 82 |
|
| 83 |
|
| 84 |
@interface MethodFamilyDiags |
| 85 |
@property (retain) id newFoo; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} |
| 86 |
- (id)newFoo; // expected-note {{explicitly declare getter '-newFoo' with '__attribute__((objc_method_family(none)))' to return an 'unowned' object}} |
| 87 |
|
| 88 |
#define OBJC_METHOD_FAMILY_NONE __attribute__((objc_method_family(none))) |
| 89 |
- (id)newBar; // expected-note {{explicitly declare getter '-newBar' with 'OBJC_METHOD_FAMILY_NONE' to return an 'unowned' object}} |
| 90 |
@property (retain) id newBar; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} |
| 91 |
|
| 92 |
@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}} |
| 93 |
#undef OBJC_METHOD_FAMILY_NONE |
| 94 |
|
| 95 |
@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}} |
| 96 |
@end |
| 97 |
|
| 98 |
@interface MethodFamilyDiags (Redeclarations) |
| 99 |
- (id)newGarply; // no note here |
| 100 |
@end |
| 101 |
|
| 102 |
@implementation MethodFamilyDiags |
| 103 |
@synthesize newGarply; |
| 104 |
@end |
| 105 |
|
| 106 |
|
| 107 |
@interface Super |
| 108 |
- (void)bar:(id)b; // expected-note {{parameter declared here}} |
| 109 |
- (void)bar1:(id) __attribute((ns_consumed)) b; |
| 110 |
- (void)ok:(id) __attribute((ns_consumed)) b; |
| 111 |
- (id)ns_non; // expected-note {{method declared here}} |
| 112 |
- (id)not_ret:(id) b __attribute((ns_returns_not_retained)); // expected-note {{method declared here}} |
| 113 |
- (id)both__returns_not_retained:(id) b __attribute((ns_returns_not_retained)); |
| 114 |
@end |
| 115 |
|
| 116 |
@interface Sub : Super |
| 117 |
- (void)bar:(id) __attribute((ns_consumed)) b; // expected-error {{overriding method has mismatched ns_consumed attribute on its parameter}} |
| 118 |
- (void)bar1:(id)b; |
| 119 |
- (void)ok:(id) __attribute((ns_consumed)) b; |
| 120 |
- (id)ns_non __attribute((ns_returns_not_retained)); // expected-error {{overriding method has mismatched ns_returns_not_retained attributes}} |
| 121 |
- (id)not_ret:(id) b __attribute((ns_returns_retained)); // expected-error {{overriding method has mismatched ns_returns_retained attributes}} |
| 122 |
- (id)both__returns_not_retained:(id) b __attribute((ns_returns_not_retained)); |
| 123 |
@property (copy, nonatomic) __attribute__((ns_returns_retained)) id (^fblock)(void); |
| 124 |
@end |
| 125 |
|
| 126 |
// Test that we give a good diagnostic here that mentions the missing |
| 127 |
// ownership qualifier. We don't want this to get suppressed because |
| 128 |
// of an invalid conversion. |
| 129 |
void test7(void) { |
| 130 |
id x; |
| 131 |
id *px = &x; // expected-error {{pointer to non-const type 'id' with no explicit ownership}} |
| 132 |
|
| 133 |
I *y; |
| 134 |
J **py = &y; // expected-error {{pointer to non-const type 'J *' with no explicit ownership}} expected-error {{incompatible pointer types initializing}} |
| 135 |
} |
| 136 |
|
| 137 |
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)'}} |
| 138 |
struct __attribute__((objc_ownership(none))) S2 {}; // expected-error {{'objc_ownership' attribute only applies to variables}} |
| 139 |
@interface I2 |
| 140 |
@property __attribute__((objc_ownership(frob))) id i; // expected-warning {{'objc_ownership' attribute argument not supported: 'frob'}} |
| 141 |
@end |
| 142 |
|
| 143 |
@interface NSObject @end |
| 144 |
|
| 145 |
@interface ControllerClass : NSObject @end |
| 146 |
|
| 147 |
@interface SomeClassOwnedByController |
| 148 |
@property (readonly) ControllerClass *controller; // expected-note {{property declared here}} |
| 149 |
|
| 150 |
@property (readonly, weak) ControllerClass *weak_controller; |
| 151 |
@end |
| 152 |
|
| 153 |
@interface SomeClassOwnedByController () |
| 154 |
@property (readwrite, weak) ControllerClass *controller; // expected-warning {{primary property declaration is implicitly strong while redeclaration in class extension is weak}} |
| 155 |
|
| 156 |
@property (readwrite, weak) ControllerClass *weak_controller; |
| 157 |
@end |
| 158 |
|
| 159 |
@interface I3 |
| 160 |
@end |
| 161 |
|
| 162 |
@interface D3 : I3 |
| 163 |
@end |
| 164 |
|
| 165 |
@interface D3 (Cat1) |
| 166 |
- (id)method; |
| 167 |
@end |
| 168 |
|
| 169 |
@interface I3 (Cat2) |
| 170 |
// FIXME: clang should diagnose mismatch between methods in D3(Cat1) and |
| 171 |
// I3(Cat2). |
| 172 |
- (id)method __attribute__((ns_returns_retained)); |
| 173 |
@end |
| 174 |
|
| 175 |
@implementation D3 |
| 176 |
- (id)method { |
| 177 |
return (id)0; |
| 178 |
} |
| 179 |
@end |