[cfe-commits] r138917 - /cfe/trunk/test/SemaObjC/default-synthesize-2.m
Fariborz Jahanian
fjahanian at apple.com
Wed Aug 31 16:32:48 PDT 2011
Author: fjahanian
Date: Wed Aug 31 18:32:48 2011
New Revision: 138917
URL: http://llvm.org/viewvc/llvm-project?rev=138917&view=rev
Log:
Test for default property synthesis.
Added:
cfe/trunk/test/SemaObjC/default-synthesize-2.m
Added: cfe/trunk/test/SemaObjC/default-synthesize-2.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/default-synthesize-2.m?rev=138917&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/default-synthesize-2.m (added)
+++ cfe/trunk/test/SemaObjC/default-synthesize-2.m Wed Aug 31 18:32:48 2011
@@ -0,0 +1,118 @@
+// RUN: %clang_cc1 -x objective-c -fsyntax-only -fobjc-nonfragile-abi -fobjc-default-synthesize-properties -verify %s
+// RUN: %clang_cc1 -x objective-c++ -fsyntax-only -fobjc-nonfragile-abi -fobjc-default-synthesize-properties -verify %s
+// rdar://8843851
+
+ at interface StopAccessingIvarsDirectlyExample
+ at property(strong) id name, rank, serialNumber;
+ at end
+
+ at implementation StopAccessingIvarsDirectlyExample
+
+- (void)identifyYourSelf {
+ if (self.name && self.rank && self.serialNumber)
+ self.name = 0;
+}
+
+// @synthesize name, rank, serialNumber;
+// default synthesis allows direct access to property ivars.
+- (id)init {
+ name = rank = serialNumber = 0;
+ return self;
+}
+
+- (void)dealloc {
+}
+ at end
+
+
+// Test2
+ at interface Test2
+ at property(strong, nonatomic) id object;
+ at end
+
+// object has user declared setter/getter so it won't be
+// default synthesized; thus causing user error.
+ at implementation Test2
+- (id) bar { return object; } // expected-error {{use of undeclared identifier 'object'}}
+- (void)setObject:(id)newObject {}
+- (id)object { return 0; }
+ at end
+
+// Test3
+ at interface Test3
+{
+ id _uid;
+}
+ at property (readwrite, assign) id uid;
+ at end
+
+ at implementation Test3
+// Oops, forgot to write @synthesize! will be default synthesized
+- (void) myMethod {
+ self.uid = 0; // Use of the âsetterâ
+ _uid = 0; // Use of the wrong instance variable
+ uid = 0; // Use of the property instance variable
+}
+ at end
+
+ at interface Test4 {
+ id _var;
+}
+ at property (readwrite, assign) id var;
+ at end
+
+
+// default synthesize property named 'var'
+ at implementation Test4
+- (id) myMethod {
+ return self->var; // compiles because 'var' is synthesized by default
+}
+ at end
+
+ at interface Test5
+{
+ id _var;
+}
+ at property (readwrite, assign) id var;
+ at end
+
+// default synthesis of property 'var'
+ at implementation Test5
+- (id) myMethod {
+ Test5 *foo = 0;
+ return foo->var; // OK
+}
+ at end
+
+ at interface Test6
+{
+ id _var; // expected-note {{'_var' declared here}}
+}
+ at property (readwrite, assign) id var;
+ at end
+
+// no default synthesis. So error is expected.
+ at implementation Test6
+- (id) myMethod
+{
+ return var; // expected-error {{use of undeclared identifier 'var'}}
+}
+ at synthesize var = _var;
+ at end
+
+int* object;
+
+ at interface Test7 {
+id _object;
+}
+ at property (readwrite, assign) id object;
+ at end
+
+// With default synthesis, 'object' is be the synthesized ivar not the global
+// 'int*' object. So no error.
+ at implementation Test7
+- (id) myMethod {
+ return object;
+}
+ at end
+
More information about the cfe-commits
mailing list