File: warn-direct-ivar-access.m

package info (click to toggle)
llvm-toolchain-19 1%3A19.1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,998,520 kB
  • sloc: cpp: 6,951,680; ansic: 1,486,157; asm: 913,598; python: 232,024; f90: 80,126; objc: 75,281; lisp: 37,276; pascal: 16,990; sh: 10,009; ml: 5,058; perl: 4,724; awk: 3,523; makefile: 3,167; javascript: 2,504; xml: 892; fortran: 664; cs: 573
file content (76 lines) | stat: -rw-r--r-- 2,572 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// RUN: %clang_cc1  -fsyntax-only -fobjc-arc -fobjc-runtime-has-weak  -Wdirect-ivar-access -verify -Wno-objc-root-class %s

__attribute__((objc_root_class)) @interface MyObject {
@public
    id _myLeader;
    id _isTickledPink; // expected-error {{existing instance variable '_isTickledPink' for property 'isTickledPink'}}
    int _myIntProp;
}
@property(retain) id myLeader;
@property(assign) id isTickledPink; // expected-note {{property declared here}}
@property int myIntProp;
@end

@implementation MyObject

@synthesize myLeader = _myLeader;
@synthesize isTickledPink = _isTickledPink; // expected-note {{property synthesized here}}
@synthesize myIntProp = _myIntProp;

- (void) doSomething {
    _myLeader = _isTickledPink; // expected-warning {{instance variable '_myLeader' is being directly accessed}} \
    // expected-warning {{instance variable '_isTickledPink' is being directly accessed}}
}

- (id) init {
    _myLeader=0;
    return _myLeader;
}
- (void) dealloc { _myLeader = 0; }
@end

MyObject * foo (void)
{
	MyObject* p=0;
        p.isTickledPink = p.myLeader;	// ok
	p->_isTickledPink = (*p)._myLeader; // expected-warning {{instance variable '_isTickledPink' is being directly accessed}} \
        // expected-warning {{instance variable '_myLeader' is being directly accessed}}
        if (p->_myIntProp) // expected-warning {{instance variable '_myIntProp' is being directly accessed}}
          p->_myIntProp = 0; // expected-warning {{instance variable '_myIntProp' is being directly accessed}}
	return p->_isTickledPink; // expected-warning {{instance variable '_isTickledPink' is being directly accessed}}
}

@interface ITest32 {
@public
 id ivar;
}
@end

id Test32(__weak ITest32 *x) {
  __weak ITest32 *y;
  x->ivar = 0; // expected-error {{dereferencing a __weak pointer is not allowed}}
  return y ? y->ivar     // expected-error {{dereferencing a __weak pointer is not allowed}}
           : (*x).ivar;  // expected-error {{dereferencing a __weak pointer is not allowed}}
}

@protocol PROTOCOL
@property (copy, nonatomic) id property_in_protocol;
@end

__attribute__((objc_root_class)) @interface INTF <PROTOCOL>
@property (copy, nonatomic) id foo;
- (id) foo;
@end

@interface INTF()
@property (copy, nonatomic) id foo1;
- (id) foo1;
@end

@implementation INTF
- (id) foo { return _foo; }
- (id) property_in_protocol { return _property_in_protocol; } // expected-warning {{instance variable '_property_in_protocol' is being directly accessed}}
- (id) foo1 { return _foo1; }
@synthesize property_in_protocol = _property_in_protocol;
@end