annotate clang/test/SemaObjC/warn-direct-ivar-access.m @ 150:1d019706d866

LLVM10
author anatofuz
date Thu, 13 Feb 2020 15:10:13 +0900
parents
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak -Wdirect-ivar-access -verify -Wno-objc-root-class %s
anatofuz
parents:
diff changeset
2 // rdar://6505197
anatofuz
parents:
diff changeset
3
anatofuz
parents:
diff changeset
4 __attribute__((objc_root_class)) @interface MyObject {
anatofuz
parents:
diff changeset
5 @public
anatofuz
parents:
diff changeset
6 id _myMaster;
anatofuz
parents:
diff changeset
7 id _isTickledPink; // expected-error {{existing instance variable '_isTickledPink' for property 'isTickledPink'}}
anatofuz
parents:
diff changeset
8 int _myIntProp;
anatofuz
parents:
diff changeset
9 }
anatofuz
parents:
diff changeset
10 @property(retain) id myMaster;
anatofuz
parents:
diff changeset
11 @property(assign) id isTickledPink; // expected-note {{property declared here}}
anatofuz
parents:
diff changeset
12 @property int myIntProp;
anatofuz
parents:
diff changeset
13 @end
anatofuz
parents:
diff changeset
14
anatofuz
parents:
diff changeset
15 @implementation MyObject
anatofuz
parents:
diff changeset
16
anatofuz
parents:
diff changeset
17 @synthesize myMaster = _myMaster;
anatofuz
parents:
diff changeset
18 @synthesize isTickledPink = _isTickledPink; // expected-note {{property synthesized here}}
anatofuz
parents:
diff changeset
19 @synthesize myIntProp = _myIntProp;
anatofuz
parents:
diff changeset
20
anatofuz
parents:
diff changeset
21 - (void) doSomething {
anatofuz
parents:
diff changeset
22 _myMaster = _isTickledPink; // expected-warning {{instance variable '_myMaster' is being directly accessed}} \
anatofuz
parents:
diff changeset
23 // expected-warning {{instance variable '_isTickledPink' is being directly accessed}}
anatofuz
parents:
diff changeset
24 }
anatofuz
parents:
diff changeset
25
anatofuz
parents:
diff changeset
26 - (id) init {
anatofuz
parents:
diff changeset
27 _myMaster=0;
anatofuz
parents:
diff changeset
28 return _myMaster;
anatofuz
parents:
diff changeset
29 }
anatofuz
parents:
diff changeset
30 - (void) dealloc { _myMaster = 0; }
anatofuz
parents:
diff changeset
31 @end
anatofuz
parents:
diff changeset
32
anatofuz
parents:
diff changeset
33 MyObject * foo ()
anatofuz
parents:
diff changeset
34 {
anatofuz
parents:
diff changeset
35 MyObject* p=0;
anatofuz
parents:
diff changeset
36 p.isTickledPink = p.myMaster; // ok
anatofuz
parents:
diff changeset
37 p->_isTickledPink = (*p)._myMaster; // expected-warning {{instance variable '_isTickledPink' is being directly accessed}} \
anatofuz
parents:
diff changeset
38 // expected-warning {{instance variable '_myMaster' is being directly accessed}}
anatofuz
parents:
diff changeset
39 if (p->_myIntProp) // expected-warning {{instance variable '_myIntProp' is being directly accessed}}
anatofuz
parents:
diff changeset
40 p->_myIntProp = 0; // expected-warning {{instance variable '_myIntProp' is being directly accessed}}
anatofuz
parents:
diff changeset
41 return p->_isTickledPink; // expected-warning {{instance variable '_isTickledPink' is being directly accessed}}
anatofuz
parents:
diff changeset
42 }
anatofuz
parents:
diff changeset
43
anatofuz
parents:
diff changeset
44 @interface ITest32 {
anatofuz
parents:
diff changeset
45 @public
anatofuz
parents:
diff changeset
46 id ivar;
anatofuz
parents:
diff changeset
47 }
anatofuz
parents:
diff changeset
48 @end
anatofuz
parents:
diff changeset
49
anatofuz
parents:
diff changeset
50 id Test32(__weak ITest32 *x) {
anatofuz
parents:
diff changeset
51 __weak ITest32 *y;
anatofuz
parents:
diff changeset
52 x->ivar = 0; // expected-error {{dereferencing a __weak pointer is not allowed}}
anatofuz
parents:
diff changeset
53 return y ? y->ivar // expected-error {{dereferencing a __weak pointer is not allowed}}
anatofuz
parents:
diff changeset
54 : (*x).ivar; // expected-error {{dereferencing a __weak pointer is not allowed}}
anatofuz
parents:
diff changeset
55 }
anatofuz
parents:
diff changeset
56
anatofuz
parents:
diff changeset
57 // rdar://13142820
anatofuz
parents:
diff changeset
58 @protocol PROTOCOL
anatofuz
parents:
diff changeset
59 @property (copy, nonatomic) id property_in_protocol;
anatofuz
parents:
diff changeset
60 @end
anatofuz
parents:
diff changeset
61
anatofuz
parents:
diff changeset
62 __attribute__((objc_root_class)) @interface INTF <PROTOCOL>
anatofuz
parents:
diff changeset
63 @property (copy, nonatomic) id foo;
anatofuz
parents:
diff changeset
64 - (id) foo;
anatofuz
parents:
diff changeset
65 @end
anatofuz
parents:
diff changeset
66
anatofuz
parents:
diff changeset
67 @interface INTF()
anatofuz
parents:
diff changeset
68 @property (copy, nonatomic) id foo1;
anatofuz
parents:
diff changeset
69 - (id) foo1;
anatofuz
parents:
diff changeset
70 @end
anatofuz
parents:
diff changeset
71
anatofuz
parents:
diff changeset
72 @implementation INTF
anatofuz
parents:
diff changeset
73 - (id) foo { return _foo; }
anatofuz
parents:
diff changeset
74 - (id) property_in_protocol { return _property_in_protocol; } // expected-warning {{instance variable '_property_in_protocol' is being directly accessed}}
anatofuz
parents:
diff changeset
75 - (id) foo1 { return _foo1; }
anatofuz
parents:
diff changeset
76 @synthesize property_in_protocol = _property_in_protocol;
anatofuz
parents:
diff changeset
77 @end
anatofuz
parents:
diff changeset
78