Debian Codegraph @

clang/test/SemaObjC/ivar-access-tests.m

raw
1 // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
2
3 @interface MySuperClass
4 {
5 int unmarked;
6
7 @private
8 int private;
9
10 @protected
11 int protected;
12
13 @public
14 int public;
15 }
16 @end
17
18 @implementation MySuperClass
19 - (void) test {
20 int access;
21 MySuperClass *s = 0;
22 access = s->unmarked;
23 access = s->private;
24 access = s->protected;
25 }
26 @end
27
28
29 @interface MyClass : MySuperClass
30 @end
31
32 @implementation MyClass
33 - (void) test {
34 int access;
35 MySuperClass *s = 0;
36 access = s->unmarked;
37 access = s->private; // expected-error {{instance variable 'private' is private}}
38 access = s->protected;
39 MyClass *m=0;
40 access = m->unmarked;
41 access = m->private; // expected-error {{instance variable 'private' is private}}
42 access = m->protected;
43 }
44 @end
45
46
47 @interface Deeper : MyClass
48 @end
49
50 @implementation Deeper
51 - (void) test {
52 int access;
53 MySuperClass *s = 0;
54 access = s->unmarked;
55 access = s->private; // expected-error {{instance variable 'private' is private}}
56 access = s->protected;
57 MyClass *m=0;
58 access = m->unmarked;
59 access = m->private; // expected-error {{instance variable 'private' is private}}
60 access = m->protected;
61 }
62 @end
63
64 @interface Unrelated
65 @end
66
67 @implementation Unrelated
68 - (void) test {
69 int access;
70 MySuperClass *s = 0;
71 access = s->unmarked; // expected-error {{instance variable 'unmarked' is protected}}
72 access = s->private; // expected-error {{instance variable 'private' is private}}
73 access = s->protected; // expected-error {{instance variable 'protected' is protected}}
74 MyClass *m=0;
75 access = m->unmarked; // expected-error {{instance variable 'unmarked' is protected}}
76 access = m->private; // expected-error {{instance variable 'private' is private}}
77 access = m->protected; // expected-error {{instance variable 'protected' is protected}}
78 }
79 @end
80
81 int main (void)
82 {
83 MySuperClass *s = 0;
84 int access;
85 access = s->unmarked; // expected-error {{instance variable 'unmarked' is protected}}
86 access = s->private; // expected-error {{instance variable 'private' is private}}
87 access = s->protected; // expected-error {{instance variable 'protected' is protected}}
88 return 0;
89 }
90
91 typedef signed char BOOL;
92 typedef unsigned int NSUInteger;
93 typedef struct _NSZone NSZone;
94 @class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator;
95 @protocol NSObject - (BOOL)isEqual:(id)object;
96 @end
97 @protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder;
98 @end
99 @interface NSObject <NSObject> {}
100 @end
101 extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone);
102 @interface NSResponder : NSObject <NSCoding> {}
103 @end
104 @protocol NSAnimatablePropertyContainer
105 - (id)animator;
106 @end
107 extern NSString *NSAnimationTriggerOrderIn ;
108 @interface NSView : NSResponder <NSAnimatablePropertyContainer> {
109 struct __VFlags2 {
110 }
111 _vFlags2;
112 }
113 @end
114 @class NSFontDescriptor, NSAffineTransform, NSGraphicsContext;
115 @interface NSScrollView : NSView {}
116 @end
117
118 @class CasperMixerView;
119 @interface CasperDiffScrollView : NSScrollView {
120 @private
121 CasperMixerView *_comparatorView;
122 NSView *someField;
123 }
124 @end
125
126 @implementation CasperDiffScrollView
127 + (void)initialize {}
128 static void _CasperDiffScrollViewInstallMixerView(CasperDiffScrollView *scrollView) {
129 if (scrollView->someField != ((void *)0)) {
130 }
131 }
132 @end