xref: /llvm-project/clang/test/SemaObjC/mrc-no-weak.m (revision c6af8c606dae9a9b728d5099d5964ea6540dc22c)
1b61e14e5SJohn McCall// RUN: %clang_cc1 -fobjc-runtime=macosx-10.8 -fsyntax-only -verify %s
2b61e14e5SJohn McCall
3b61e14e5SJohn McCall__attribute__((objc_root_class))
4b61e14e5SJohn McCall@interface Root @end
5b61e14e5SJohn McCall
6b61e14e5SJohn McCall// These should not get diagnosed immediately.
7b61e14e5SJohn McCall@interface A : Root {
8b61e14e5SJohn McCall  __weak id x;
9b61e14e5SJohn McCall}
10b61e14e5SJohn McCall@property __weak id y;
11b61e14e5SJohn McCall@end
12b61e14e5SJohn McCall
13b61e14e5SJohn McCall// Diagnostic goes on the ivar if it's explicit.
14b61e14e5SJohn McCall@interface B : Root {
15b61e14e5SJohn McCall  __weak id x;  // expected-error {{cannot create __weak reference in file using manual reference counting}}
16b61e14e5SJohn McCall}
17b61e14e5SJohn McCall@property __weak id x;
18b61e14e5SJohn McCall@end
19b61e14e5SJohn McCall@implementation B
20b61e14e5SJohn McCall@synthesize x;
21b61e14e5SJohn McCall@end
22b61e14e5SJohn McCall
23b61e14e5SJohn McCall// Otherwise, it goes with the @synthesize.
24b61e14e5SJohn McCall@interface C : Root
25b61e14e5SJohn McCall@property __weak id x; // expected-note {{property declared here}}
26b61e14e5SJohn McCall@end
27b61e14e5SJohn McCall@implementation C
28b61e14e5SJohn McCall@synthesize x; // expected-error {{cannot synthesize weak property in file using manual reference counting}}
29b61e14e5SJohn McCall@end
30b61e14e5SJohn McCall
31b61e14e5SJohn McCall@interface D : Root
32b61e14e5SJohn McCall@property __weak id x; // expected-note {{property declared here}}
33b61e14e5SJohn McCall@end
34b61e14e5SJohn McCall@implementation D // expected-error {{cannot synthesize weak property in file using manual reference counting}}
35b61e14e5SJohn McCall@end
36b61e14e5SJohn McCall
37b61e14e5SJohn McCall@interface E : Root {
38b61e14e5SJohn McCall@public
39*c6af8c60SJohn McCall  __weak id x; // expected-note 2 {{declaration uses __weak, but ARC is disabled}}
40b61e14e5SJohn McCall}
41b61e14e5SJohn McCall@end
42b61e14e5SJohn McCall
43b61e14e5SJohn McCallvoid testE(E *e) {
44*c6af8c60SJohn McCall  id x = e->x; // expected-error {{'x' is unavailable}}
45*c6af8c60SJohn McCall  e->x = x; // expected-error {{'x' is unavailable}}
46b61e14e5SJohn McCall}
47b61e14e5SJohn McCall
48b61e14e5SJohn McCall@interface F : Root
49b61e14e5SJohn McCall@property (weak) id x;
50b61e14e5SJohn McCall@end
51b61e14e5SJohn McCall
52b61e14e5SJohn McCallvoid testF(F *f) {
53b61e14e5SJohn McCall  id x = f.x;
54b61e14e5SJohn McCall}
55