xref: /aosp_15_r20/external/clang/test/SemaObjC/iboutlet.m (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li// RUN: %clang_cc1 -fsyntax-only -fobjc-arc -Wno-objc-root-class -Warc-repeated-use-of-weak -fobjc-runtime-has-weak -verify %s
2*67e74705SXin Li// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -fobjc-arc -Wno-objc-root-class -Warc-repeated-use-of-weak -fobjc-runtime-has-weak -verify %s
3*67e74705SXin Li// rdar://11448209
4*67e74705SXin Li
5*67e74705SXin Li#define READONLY readonly
6*67e74705SXin Li
7*67e74705SXin Li@class NSView;
8*67e74705SXin Li
9*67e74705SXin LiIB_DESIGNABLE @interface I
10*67e74705SXin Li@property (getter = MyGetter, readonly, assign) IBOutlet NSView *myView; // expected-warning {{readonly IBOutlet property 'myView' when auto-synthesized may not work correctly with 'nib' loader}} expected-note {{property should be changed to be readwrite}}
11*67e74705SXin Li
12*67e74705SXin LiIBInspectable @property (readonly) IBOutlet NSView *myView1; // expected-warning {{readonly IBOutlet property 'myView1' when auto-synthesized may not work correctly with 'nib' loader}} expected-note {{property should be changed to be readwrite}}
13*67e74705SXin Li
14*67e74705SXin Li@property (getter = MyGetter, READONLY) IBOutlet NSView *myView2; // expected-warning {{readonly IBOutlet property 'myView2' when auto-synthesized may not work correctly with 'nib' loader}}
15*67e74705SXin Li
16*67e74705SXin Li@end
17*67e74705SXin Li
18*67e74705SXin Li@implementation I
19*67e74705SXin Li@end
20*67e74705SXin Li
21*67e74705SXin Li
22*67e74705SXin Li// rdar://13123861
23*67e74705SXin Li@class UILabel;
24*67e74705SXin Li
25*67e74705SXin Li@interface NSObject @end
26*67e74705SXin Li
27*67e74705SXin Li@interface RKTFHView : NSObject
28*67e74705SXin Li@property( readonly ) __attribute__((iboutlet)) UILabel *autoReadOnlyReadOnly; // expected-warning {{readonly IBOutlet property 'autoReadOnlyReadOnly' when auto-synthesized may not work correctly with 'nib' loader}} expected-note {{property should be changed to be readwrite}}
29*67e74705SXin Li@property( readonly ) __attribute__((iboutlet)) UILabel *autoReadOnlyReadWrite;
30*67e74705SXin Li@property( readonly ) __attribute__((iboutlet)) UILabel *synthReadOnlyReadWrite;
31*67e74705SXin Li@end
32*67e74705SXin Li
33*67e74705SXin Li@interface RKTFHView()
34*67e74705SXin Li@property( readwrite ) __attribute__((iboutlet)) UILabel *autoReadOnlyReadWrite;
35*67e74705SXin Li@property( readwrite ) __attribute__((iboutlet)) UILabel *synthReadOnlyReadWrite;
36*67e74705SXin Li@end
37*67e74705SXin Li
38*67e74705SXin Li@implementation RKTFHView
39*67e74705SXin Li@synthesize synthReadOnlyReadWrite=_synthReadOnlyReadWrite;
40*67e74705SXin Li@end
41*67e74705SXin Li
42*67e74705SXin Li// rdar://15885642
43*67e74705SXin Li@interface WeakOutlet
44*67e74705SXin Li@property int Number;
45*67e74705SXin Li@property IBOutlet __weak WeakOutlet* WeakProp;
46*67e74705SXin Li@end
47*67e74705SXin Li
48*67e74705SXin LiWeakOutlet* func() {
49*67e74705SXin Li  __weak WeakOutlet* pwi;
50*67e74705SXin Li  pwi.WeakProp = (WeakOutlet*)0;
51*67e74705SXin Li  pwi.WeakProp = pwi.WeakProp;
52*67e74705SXin Li  return pwi.WeakProp;
53*67e74705SXin Li}
54*67e74705SXin Li
55*67e74705SXin LiWeakOutlet* func2(WeakOutlet* pwi) {
56*67e74705SXin Li  [[pwi WeakProp] setNumber:0];
57*67e74705SXin Li  [[pwi WeakProp] setNumber:1];
58*67e74705SXin Li  return [pwi WeakProp];
59*67e74705SXin Li}
60