summaryrefslogtreecommitdiff
path: root/gcc/testsuite/obj-c++.dg
diff options
context:
space:
mode:
authornicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4>2010-11-15 23:12:49 +0000
committernicola <nicola@138bc75d-0d04-0410-961f-82ee72b054a4>2010-11-15 23:12:49 +0000
commit6d922cb7efcf21bafce2f0f5b98d6a29cdbdcf26 (patch)
tree116650c2d71cbf74dc4d68bcf57d5135b736a64b /gcc/testsuite/obj-c++.dg
parent9a56024d74d1ad3977ee5b657249d8ae07462b94 (diff)
downloadgcc-6d922cb7efcf21bafce2f0f5b98d6a29cdbdcf26.tar.gz
In gcc/objc/:
2010-11-15 Nicola Pero <nicola.pero@meta-innovation.com> * objc-act.c (objc_build_setter_call): New. (objc_maybe_build_modify_expr): Rewritten to build a compound statement. (objc_build_incr_expr_for_property_ref): Updated calls to objc_maybe_build_modify_expr to call objc_build_setter_call instead. Use build_modify_expr () instead of build2 (MODIFY_EXPR, ...). Use convert () instead of build1 (NOP_EXPR, ...). Use TREE_NO_WARNING on the final compound statement to silence C++ warnings. In gcc/testsuite/: 2010-11-15 Nicola Pero <nicola.pero@meta-innovation.com> * objc.dg/property/dotsyntax-18.m: New. * objc.dg/property/dotsyntax-19.m: New. * objc.dg/property/dotsyntax-20.m: New. * obj-c++.dg/property/dotsyntax-18.mm: New. * obj-c++.dg/property/dotsyntax-19.mm: New. * obj-c++.dg/property/dotsyntax-20.mm: New. * objc.dg/property/dotsyntax-4.m: Removed some unused variables and code. * objc.dg/property/dotsyntax-6.m: Same change. * objc.dg/property/dotsyntax-16.m: Same change. * objc.dg/property/dotsyntax-17.m: Same change. * obj-c++.dg/property/dotsyntax-4.mm: Same change. * obj-c++.dg/property/dotsyntax-6.mm: Same change. * obj-c++.dg/property/dotsyntax-16.mm: Same change. * obj-c++.dg/property/dotsyntax-17.mm: Same change. * objc.dg/property/at-property-22.m: Added missing casts. * obj-c++.dg/property/at-property-22.mm: Same change. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@166779 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/obj-c++.dg')
-rw-r--r--gcc/testsuite/obj-c++.dg/property/at-property-22.mm14
-rw-r--r--gcc/testsuite/obj-c++.dg/property/dotsyntax-16.mm1
-rw-r--r--gcc/testsuite/obj-c++.dg/property/dotsyntax-17.mm1
-rw-r--r--gcc/testsuite/obj-c++.dg/property/dotsyntax-18.mm90
-rw-r--r--gcc/testsuite/obj-c++.dg/property/dotsyntax-19.mm113
-rw-r--r--gcc/testsuite/obj-c++.dg/property/dotsyntax-20.mm67
-rw-r--r--gcc/testsuite/obj-c++.dg/property/dotsyntax-4.mm29
-rw-r--r--gcc/testsuite/obj-c++.dg/property/dotsyntax-6.mm1
8 files changed, 279 insertions, 37 deletions
diff --git a/gcc/testsuite/obj-c++.dg/property/at-property-22.mm b/gcc/testsuite/obj-c++.dg/property/at-property-22.mm
index af7f3bc1b4e..03b3d0bb48e 100644
--- a/gcc/testsuite/obj-c++.dg/property/at-property-22.mm
+++ b/gcc/testsuite/obj-c++.dg/property/at-property-22.mm
@@ -128,31 +128,31 @@ int main (void)
if (object.penum != Black)
abort ();
- object.pcharp = 0;
+ object.pcharp = (char *)0;
if (object.pcharp != 0)
abort ();
- object.pshortp = 0;
+ object.pshortp = (short *)0;
if (object.pshortp != 0)
abort ();
- object.pintp = 0;
+ object.pintp = (int *)0;
if (object.pintp != 0)
abort ();
- object.plongp = 0;
+ object.plongp = (long *)0;
if (object.plongp != 0)
abort ();
- object.pfloatp = 0;
+ object.pfloatp = (float *)0;
if (object.pfloatp != 0)
abort ();
- object.pdoublep = 0;
+ object.pdoublep = (double *)0;
if (object.pdoublep != 0)
abort ();
- object.penump = 0;
+ object.penump = (enum colour *)0;
if (object.penump != 0)
abort ();
diff --git a/gcc/testsuite/obj-c++.dg/property/dotsyntax-16.mm b/gcc/testsuite/obj-c++.dg/property/dotsyntax-16.mm
index e0ae3f6edeb..893db69d980 100644
--- a/gcc/testsuite/obj-c++.dg/property/dotsyntax-16.mm
+++ b/gcc/testsuite/obj-c++.dg/property/dotsyntax-16.mm
@@ -37,7 +37,6 @@
int main (void)
{
MyRootClass *object = [[MyRootClass alloc] init];
- int i;
object.count = 10;
if (object.count != 10)
diff --git a/gcc/testsuite/obj-c++.dg/property/dotsyntax-17.mm b/gcc/testsuite/obj-c++.dg/property/dotsyntax-17.mm
index f3942fccb11..c28e11f484b 100644
--- a/gcc/testsuite/obj-c++.dg/property/dotsyntax-17.mm
+++ b/gcc/testsuite/obj-c++.dg/property/dotsyntax-17.mm
@@ -34,7 +34,6 @@
int main (void)
{
MyRootClass *object = [[MyRootClass alloc] init];
- int i;
object.count = 10; /* { dg-error "readonly property can not be set" } */
if (object.count != 10) /* Ok */
diff --git a/gcc/testsuite/obj-c++.dg/property/dotsyntax-18.mm b/gcc/testsuite/obj-c++.dg/property/dotsyntax-18.mm
new file mode 100644
index 00000000000..5697d311d27
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/property/dotsyntax-18.mm
@@ -0,0 +1,90 @@
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
+/* { dg-do run } */
+/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
+
+/* Test dot-syntax with tricky assignments. */
+
+#include <stdlib.h>
+#include <objc/objc.h>
+#include <objc/runtime.h>
+
+@interface MyRootClass
+{
+ Class isa;
+ int a;
+}
++ (id) initialize;
++ (id) alloc;
+- (id) init;
+- (int) count;
+- (void) setCount: (int)count;
+- (int) somethingToExecuteOnlyOnce;
+@end
+
+@implementation MyRootClass
++ (id) initialize { return self; }
++ (id) alloc { return class_createInstance (self, 0); }
+- (id) init { return self; }
+- (int) count
+{
+ return a;
+}
+- (void) setCount: (int)count
+{
+ a = count;
+}
+- (int) somethingToExecuteOnlyOnce
+{
+ a++;
+ return 10;
+}
+@end
+
+int main (void)
+{
+ MyRootClass *object1 = [[MyRootClass alloc] init];
+ MyRootClass *object2 = [[MyRootClass alloc] init];
+ MyRootClass *object3 = [[MyRootClass alloc] init];
+ int i;
+
+ object1.count = 10;
+ if (object1.count != 10)
+ abort ();
+
+ object2.count = 10;
+ if (object2.count != 10)
+ abort ();
+
+ /* Test multiple assignments to a constant. */
+ object1.count = object2.count = 20;
+
+ if (object1.count != 20 || object2.count != 20)
+ abort ();
+
+ i = object1.count = 30;
+
+ if (i != 30 || object1.count != 30)
+ abort ();
+
+ i = object2.count = 30;
+
+ if (i != 30 || object2.count != 30)
+ abort ();
+
+ /* Test a simple assignment to something with a side-effect; the
+ 'rhs' should be evaluated only once. */
+ object1.count = ([object2 somethingToExecuteOnlyOnce] > 0 ? 30 : 45);
+
+ if (object1.count != 30 || object2.count != 31)
+ abort ();
+
+ /* Test multiple assignments with side effects. */
+ object3.count = object1.count = ([object2 somethingToExecuteOnlyOnce] > 0 ? 30 : 45);
+
+ if (object1.count != 30 || object2.count != 32 || object3.count != 30)
+ abort ();
+
+ return 0;
+}
+
+
diff --git a/gcc/testsuite/obj-c++.dg/property/dotsyntax-19.mm b/gcc/testsuite/obj-c++.dg/property/dotsyntax-19.mm
new file mode 100644
index 00000000000..df4867b0ad3
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/property/dotsyntax-19.mm
@@ -0,0 +1,113 @@
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
+/* { dg-do run } */
+/* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
+
+/* Test dot-syntax with more tricky assignments. */
+
+#include <stdlib.h>
+#include <objc/objc.h>
+#include <objc/runtime.h>
+
+@interface MyRootClass
+{
+ Class isa;
+ id a;
+ id b;
+ int p1;
+ float p2;
+}
++ (id) initialize;
++ (id) alloc;
+- (id) init;
+
+@property (assign) id object1;
+@property (assign) id object2;
+- (id) test;
+- (id) myself;
+- (id) nilObject;
+
+@property int p1;
+@property float p2;
+@end
+
+@implementation MyRootClass
++ (id) initialize { return self; }
++ (id) alloc { return class_createInstance (self, 0); }
+- (id) init { return self; }
+@synthesize object1 = a;
+@synthesize object2 = b;
+- (id) test
+{
+ /* Test multiple assignments with 'self'. */
+ self.object1 = self.object2 = self;
+
+ if (self.object1 != self || self.object2 != self)
+ abort ();
+
+ /* Test multiple assignments with a conditional and method calls. */
+ self.object1 = self.object2 = (self ? [self myself] : [self nilObject]);
+
+ if (self.object1 != self || self.object2 != self)
+ abort ();
+
+ self.object1 = self.object2 = (self ? [self nilObject] : [self myself]);
+
+ if (self.object1 != nil || self.object2 != nil)
+ abort ();
+
+ return self.object1;
+}
+- (id) myself
+{
+ return self;
+}
+- (id) nilObject
+{
+ return nil;
+}
+
+@synthesize p1;
+@synthesize p2;
+@end
+
+int main (void)
+{
+ MyRootClass *object = [[MyRootClass alloc] init];
+ MyRootClass *object1 = [[MyRootClass alloc] init];
+
+ [object test];
+
+ /* Now, test multiple assignments with different types. Use
+ int/float as they seem to happily crash the compiler in gimplify
+ if proper conversions are not being generated by the
+ frontend. ;-) */
+ object.p1 = object.p2 = 12;
+
+ if (object.p1 != 12 || object.p2 != 12)
+ abort ();
+
+ object.p1 = object.p2 = 2.7;
+
+ if (object.p1 != 2)
+ abort ();
+
+ /* Just try a different loop, mixing in a few different standard C
+ constructs to cover a few other cases. */
+ object.p1 = 10;
+ object1.p1 = 0;
+ while (object.p1)
+ {
+ object1.p1 += ((object.p2 = 4.56) ? 0 : object.p1);
+ object.p1--;
+ }
+
+ if (object.p1 != 0 || object1.p1 != 0)
+ abort ();
+
+ if ((object.p1 = 0))
+ abort ();
+
+ return 0;
+}
+
+
diff --git a/gcc/testsuite/obj-c++.dg/property/dotsyntax-20.mm b/gcc/testsuite/obj-c++.dg/property/dotsyntax-20.mm
new file mode 100644
index 00000000000..2bddb7c6b96
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/property/dotsyntax-20.mm
@@ -0,0 +1,67 @@
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010. */
+/* { dg-do compile } */
+/* { dg-options "-Wall" } */
+
+/* Test warnings with the dot-syntax. */
+
+#include <stdlib.h>
+#include <objc/objc.h>
+#include <objc/runtime.h>
+
+@interface MyRootClass
+{
+ Class isa;
+ id a;
+ id b;
+ int p1;
+ int p2;
+}
++ (id) initialize;
++ (id) alloc;
+- (id) init;
+
+@property int p1;
+@property int p2;
+@end
+
+@implementation MyRootClass
++ (id) initialize { return self; }
++ (id) alloc { return class_createInstance (self, 0); }
+- (id) init { return self; }
+@synthesize p1;
+@synthesize p2;
+@end
+
+int main (void)
+{
+ MyRootClass *object = [[MyRootClass alloc] init];
+
+ /* First, test that the artificial code generated by dot-syntax does
+ not generate unexpected warnings. */
+
+ /* All of the following should generate no warnings. */
+ object.p1 = 0;
+ object.p2 = 0;
+ object.p1 = object.p2 = 0;
+ if (object.p1 > 0)
+ object.p2 = 0;
+
+ object.p1++;
+ ++object.p1;
+ object.p1--;
+ --object.p1;
+
+ while (object.p1)
+ object.p1--;
+
+ /* Now test some warnings. */
+ object.p1; /* This warning does not seem to be produced in C++. dg-warning "value computed is not used" */
+
+ /* TODO: It would be good to get the following to warn. */
+ if (object.p1 = 0) /* dg-warning "suggest parentheses around assignment used as truth value" */
+ abort ();
+
+ return 0;
+}
+
+
diff --git a/gcc/testsuite/obj-c++.dg/property/dotsyntax-4.mm b/gcc/testsuite/obj-c++.dg/property/dotsyntax-4.mm
index af410185526..2e918d28215 100644
--- a/gcc/testsuite/obj-c++.dg/property/dotsyntax-4.mm
+++ b/gcc/testsuite/obj-c++.dg/property/dotsyntax-4.mm
@@ -9,9 +9,6 @@
#include <objc/objc.h>
#include <objc/runtime.h>
-static int a;
-static id b;
-
@interface MyRootClass
{
Class isa;
@@ -19,38 +16,16 @@ static id b;
+ (id) initialize;
+ (id) alloc;
- (id) init;
-+ (int) count;
-+ (void) setCount: (int)value;
-+ (id) next;
-+ (void) setNext: (id)value;
@end
@implementation MyRootClass
+ (id) initialize { return self; }
+ (id) alloc { return class_createInstance (self, 0); }
- (id) init { return self; }
-+ (int) count
-{
- return a;
-}
-+ (void) setCount: (int)value
-{
- a = value;
-}
-+ (id) next
-{
- return b;
-}
-+ (void) setNext: (id)value
-{
- b = value;
-}
@end
int main (void)
{
- MyRootClass *object = [[MyRootClass alloc] init];
-
MyRootClass.invalid = 40; /* { dg-error "could not find setter.getter" } */
if (MyRootClass.invalid != 40) /* { dg-error "could not find setter.getter" } */
abort ();
@@ -60,9 +35,9 @@ int main (void)
abort ();
MyRootClass.int; /* { dg-error "expected identifier" } */
- /* { dg-error "expected" "" { target *-*-* } 62 } */
+ /* { dg-error "expected" "" { target *-*-* } 37 } */
if (MyRootClass.int) /* { dg-error "expected identifier" } */
- /* { dg-error "expected" "" { target *-*-* } 64 } */
+ /* { dg-error "expected" "" { target *-*-* } 39 } */
abort ();
return 0;
diff --git a/gcc/testsuite/obj-c++.dg/property/dotsyntax-6.mm b/gcc/testsuite/obj-c++.dg/property/dotsyntax-6.mm
index cc8c567cff9..7ecd34e3d0b 100644
--- a/gcc/testsuite/obj-c++.dg/property/dotsyntax-6.mm
+++ b/gcc/testsuite/obj-c++.dg/property/dotsyntax-6.mm
@@ -10,7 +10,6 @@
@class MyRootClass;
-static int c;
static MyRootClass *shared_root = nil;
@interface MyRootClass