1 // RUN: %clang_cc1 -x objective-c -fsyntax-only -verify -Wno-objc-root-class %s
2 // RUN: %clang_cc1 -x objective-c++ -fsyntax-only -verify -Wno-objc-root-class %s
5 @interface StopAccessingIvarsDirectlyExample
6 @property(strong) id name, rank, serialNumber;
9 @implementation StopAccessingIvarsDirectlyExample
11 - (void)identifyYourSelf {
12 if (self.name && self.rank && self.serialNumber)
16 // @synthesize name, rank, serialNumber;
17 // default synthesis allows direct access to property ivars.
19 _name = _rank = _serialNumber = 0;
30 @property(strong, nonatomic) id object;
33 // object has user declared setter/getter so it won't be
34 // default synthesized; thus causing user error.
36 - (id) bar { return object; } // expected-error {{use of undeclared identifier 'object'}}
37 - (void)setObject:(id)newObject {}
38 - (id)object { return 0; }
44 id uid; // expected-note {{instance variable is declared here}}
46 @property (readwrite, assign) id uid; // expected-note {{property declared here}}
50 @implementation Test3 // expected-warning {{autosynthesized property 'uid' will use synthesized instance variable '_uid', not existing instance variable 'uid'}}
51 // Oops, forgot to write @synthesize! will be default synthesized
53 self.uid = 0; // Use of the “setter”
54 uid = 0; // Use of the wrong instance variable
55 _uid = 0; // Use of the property instance variable
62 @property (readwrite, assign) id var;
66 // default synthesize property named 'var'
69 return self->_var; // compiles because 'var' is synthesized by default
77 @property (readwrite, assign) id var;
80 // default synthesis of property 'var'
84 return foo->_var; // OK
90 id _var; // expected-note {{'_var' declared here}}
92 @property (readwrite, assign) id var;
95 // no default synthesis. So error is expected.
99 return var; // expected-error {{use of undeclared identifier 'var'}}
101 @synthesize var = _var;
107 @property (readwrite, assign) id object;
110 // With default synthesis, '_object' is be the synthesized ivar not the global
111 // 'int*' object. So no error.
112 @implementation Test7
122 id y; // expected-note {{instance variable is declared here}}
124 @property(copy) id y; // expected-note {{property declared here}}
128 @implementation Test8 @end // expected-warning {{autosynthesized property 'y' will use instance variable '_y', not existing instance variable 'y'}}