2012-04-07 02:12:22 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -fblocks -fobjc-arc -verify -Wno-objc-root-class %s
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
// rdar://8843524
|
|
|
|
|
|
|
|
struct A {
|
2019-02-08 04:21:46 +08:00
|
|
|
id x[4];
|
|
|
|
id y;
|
2011-06-16 07:02:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
union u {
|
2019-09-07 08:34:43 +08:00
|
|
|
id u;
|
2019-02-08 04:21:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Volatile fields are fine.
|
|
|
|
struct C {
|
|
|
|
volatile int x[4];
|
|
|
|
volatile int y;
|
|
|
|
};
|
|
|
|
|
|
|
|
union u_trivial_c {
|
|
|
|
volatile int b;
|
|
|
|
struct C c;
|
|
|
|
};
|
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
@interface I {
|
|
|
|
struct A a;
|
|
|
|
struct B {
|
2018-02-28 15:15:55 +08:00
|
|
|
id y[10][20];
|
2011-06-16 07:02:42 +08:00
|
|
|
id z;
|
|
|
|
} b;
|
|
|
|
|
|
|
|
union u c;
|
|
|
|
};
|
|
|
|
@end
|
|
|
|
|
2011-12-13 07:17:04 +08:00
|
|
|
// rdar://10260525
|
|
|
|
struct r10260525 {
|
2018-02-28 15:15:55 +08:00
|
|
|
id (^block) ();
|
2011-12-13 07:17:04 +08:00
|
|
|
};
|
|
|
|
|
2011-06-16 07:02:42 +08:00
|
|
|
struct S {
|
2011-06-24 08:08:59 +08:00
|
|
|
id __attribute__((objc_ownership(none))) i;
|
2011-06-16 07:02:42 +08:00
|
|
|
void * vp;
|
|
|
|
int i1;
|
|
|
|
};
|
|
|
|
|
|
|
|
// rdar://9046528
|
|
|
|
|
|
|
|
@class NSError;
|
|
|
|
|
2011-06-24 08:08:59 +08:00
|
|
|
__autoreleasing id X; // expected-error {{global variables cannot have __autoreleasing ownership}}
|
|
|
|
__autoreleasing NSError *E; // expected-error {{global variables cannot have __autoreleasing ownership}}
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
|
2011-06-24 08:08:59 +08:00
|
|
|
extern id __autoreleasing X1; // expected-error {{global variables cannot have __autoreleasing ownership}}
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
void func()
|
|
|
|
{
|
|
|
|
id X;
|
2011-06-24 08:08:59 +08:00
|
|
|
static id __autoreleasing X1; // expected-error {{global variables cannot have __autoreleasing ownership}}
|
|
|
|
extern id __autoreleasing E; // expected-error {{global variables cannot have __autoreleasing ownership}}
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// rdar://9157348
|
2014-01-10 08:53:48 +08:00
|
|
|
// rdar://15757510
|
2011-06-16 07:02:42 +08:00
|
|
|
|
|
|
|
@interface J
|
2015-01-17 07:04:31 +08:00
|
|
|
@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}}
|
2011-06-16 07:02:42 +08:00
|
|
|
@property (copy, nonatomic) id new;
|
2015-01-17 07:04:31 +08:00
|
|
|
@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}}
|
2011-06-16 07:02:42 +08:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation J
|
2014-01-10 08:53:48 +08:00
|
|
|
@synthesize newFoo;
|
|
|
|
@synthesize copyBar;
|
|
|
|
@synthesize allocBaz;
|
2011-06-16 07:02:42 +08:00
|
|
|
@synthesize new;
|
|
|
|
- new {return 0; };
|
2014-01-10 08:53:48 +08:00
|
|
|
|
|
|
|
@dynamic newDFoo;
|
|
|
|
@dynamic copyDBar;
|
|
|
|
@dynamic allocDBaz;
|
2011-06-16 07:02:42 +08:00
|
|
|
@end
|
|
|
|
|
2011-09-28 06:35:36 +08:00
|
|
|
|
2015-01-17 07:04:31 +08:00
|
|
|
@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
|
|
|
|
|
|
|
|
|
2011-09-28 06:35:36 +08:00
|
|
|
// rdar://10187884
|
|
|
|
@interface Super
|
|
|
|
- (void)bar:(id)b; // expected-note {{parameter declared here}}
|
|
|
|
- (void)bar1:(id) __attribute((ns_consumed)) b;
|
|
|
|
- (void)ok:(id) __attribute((ns_consumed)) b;
|
|
|
|
- (id)ns_non; // expected-note {{method declared here}}
|
|
|
|
- (id)not_ret:(id) b __attribute((ns_returns_not_retained)); // expected-note {{method declared here}}
|
|
|
|
- (id)both__returns_not_retained:(id) b __attribute((ns_returns_not_retained));
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface Sub : Super
|
|
|
|
- (void)bar:(id) __attribute((ns_consumed)) b; // expected-error {{overriding method has mismatched ns_consumed attribute on its parameter}}
|
|
|
|
- (void)bar1:(id)b;
|
|
|
|
- (void)ok:(id) __attribute((ns_consumed)) b;
|
|
|
|
- (id)ns_non __attribute((ns_returns_not_retained)); // expected-error {{overriding method has mismatched ns_returns_not_retained attributes}}
|
|
|
|
- (id)not_ret:(id) b __attribute((ns_returns_retained)); // expected-error {{overriding method has mismatched ns_returns_retained attributes}}
|
|
|
|
- (id)both__returns_not_retained:(id) b __attribute((ns_returns_not_retained));
|
2012-08-29 06:26:21 +08:00
|
|
|
// rdar://12173491
|
|
|
|
@property (copy, nonatomic) __attribute__((ns_returns_retained)) id (^fblock)(void);
|
2011-09-28 06:35:36 +08:00
|
|
|
@end
|
2012-01-27 04:04:03 +08:00
|
|
|
|
|
|
|
// Test that we give a good diagnostic here that mentions the missing
|
|
|
|
// ownership qualifier. We don't want this to get suppressed because
|
|
|
|
// of an invalid conversion.
|
|
|
|
void test7(void) {
|
|
|
|
id x;
|
|
|
|
id *px = &x; // expected-error {{pointer to non-const type 'id' with no explicit ownership}}
|
|
|
|
|
|
|
|
I *y;
|
|
|
|
J **py = &y; // expected-error {{pointer to non-const type 'J *' with no explicit ownership}} expected-warning {{incompatible pointer types initializing}}
|
|
|
|
}
|
2013-09-02 03:11:23 +08:00
|
|
|
|
|
|
|
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)'}}
|
|
|
|
struct __attribute__((objc_ownership(none))) S2 {}; // expected-error {{'objc_ownership' attribute only applies to variables}}
|
|
|
|
@interface I2
|
|
|
|
@property __attribute__((objc_ownership(frob))) id i; // expected-warning {{'objc_ownership' attribute argument not supported: 'frob'}}
|
|
|
|
@end
|
2013-10-26 08:35:39 +08:00
|
|
|
|
|
|
|
// rdar://15304886
|
|
|
|
@interface NSObject @end
|
|
|
|
|
|
|
|
@interface ControllerClass : NSObject @end
|
|
|
|
|
|
|
|
@interface SomeClassOwnedByController
|
|
|
|
@property (readonly) ControllerClass *controller; // expected-note {{property declared here}}
|
2013-11-20 03:26:30 +08:00
|
|
|
|
|
|
|
// rdar://15465916
|
|
|
|
@property (readonly, weak) ControllerClass *weak_controller;
|
2013-10-26 08:35:39 +08:00
|
|
|
@end
|
|
|
|
|
|
|
|
@interface SomeClassOwnedByController ()
|
|
|
|
@property (readwrite, weak) ControllerClass *controller; // expected-warning {{primary property declaration is implicitly strong while redeclaration in class extension is weak}}
|
2013-11-20 03:26:30 +08:00
|
|
|
|
|
|
|
@property (readwrite, weak) ControllerClass *weak_controller;
|
2013-10-26 08:35:39 +08:00
|
|
|
@end
|
2018-02-07 07:44:40 +08:00
|
|
|
|
|
|
|
@interface I3
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface D3 : I3
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface D3 (Cat1)
|
|
|
|
- (id)method;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface I3 (Cat2)
|
|
|
|
// FIXME: clang should diagnose mismatch between methods in D3(Cat1) and
|
|
|
|
// I3(Cat2).
|
|
|
|
- (id)method __attribute__((ns_returns_retained));
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation D3
|
|
|
|
- (id)method {
|
|
|
|
return (id)0;
|
|
|
|
}
|
|
|
|
@end
|