summaryrefslogtreecommitdiff
path: root/gcc/testsuite/obj-c++.dg
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/testsuite/obj-c++.dg')
-rw-r--r--gcc/testsuite/obj-c++.dg/attributes/method-attribute-2.mm2
-rw-r--r--gcc/testsuite/obj-c++.dg/attributes/method-deprecated-1.mm33
-rw-r--r--gcc/testsuite/obj-c++.dg/attributes/method-deprecated-2.mm23
-rw-r--r--gcc/testsuite/obj-c++.dg/attributes/method-deprecated-3.mm21
-rw-r--r--gcc/testsuite/obj-c++.dg/attributes/method-format-1.mm43
-rw-r--r--gcc/testsuite/obj-c++.dg/attributes/method-noreturn-1.mm34
-rw-r--r--gcc/testsuite/obj-c++.dg/attributes/method-sentinel-1.mm34
-rw-r--r--gcc/testsuite/obj-c++.dg/property/at-property-10.mm2
-rw-r--r--gcc/testsuite/obj-c++.dg/property/at-property-11.mm2
-rw-r--r--gcc/testsuite/obj-c++.dg/property/at-property-12.mm46
-rw-r--r--gcc/testsuite/obj-c++.dg/property/at-property-13.mm71
-rw-r--r--gcc/testsuite/obj-c++.dg/property/at-property-6.mm2
-rw-r--r--gcc/testsuite/obj-c++.dg/property/at-property-7.mm2
-rw-r--r--gcc/testsuite/obj-c++.dg/property/at-property-8.mm2
-rw-r--r--gcc/testsuite/obj-c++.dg/property/at-property-9.mm2
-rw-r--r--gcc/testsuite/obj-c++.dg/property/at-property-deprecated-1.mm37
16 files changed, 349 insertions, 7 deletions
diff --git a/gcc/testsuite/obj-c++.dg/attributes/method-attribute-2.mm b/gcc/testsuite/obj-c++.dg/attributes/method-attribute-2.mm
index f9a184cdf41..4a56b3aa8f6 100644
--- a/gcc/testsuite/obj-c++.dg/attributes/method-attribute-2.mm
+++ b/gcc/testsuite/obj-c++.dg/attributes/method-attribute-2.mm
@@ -14,7 +14,7 @@
@end
@implementation obj
-- (int) depmth __attribute__((deprecated)) { return var; }
+- (int) depmth __attribute__((deprecated)) { return var; } /* { dg-warning "method attributes can not be specified in @implementation context" } */
- (int) depmtharg:(int) iarg { return var + iarg ; }
- (int) unusedarg:(int) __attribute__((unused)) uarg { return var; }
- (int) depunusedarg:(int) __attribute__((unused)) uarg { return var; }
diff --git a/gcc/testsuite/obj-c++.dg/attributes/method-deprecated-1.mm b/gcc/testsuite/obj-c++.dg/attributes/method-deprecated-1.mm
new file mode 100644
index 00000000000..8343856a5c6
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/attributes/method-deprecated-1.mm
@@ -0,0 +1,33 @@
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010. */
+/* { dg-do compile } */
+
+#include <objc/objc.h>
+
+@interface MyClass
+{
+ Class isa;
+}
++ (int) method;
+- (int) method;
++ (int) deprecatedClassMethod __attribute__((deprecated));
+- (int) deprecatedInstanceMethod __attribute__((deprecated));
+@end
+
+/* Test that deprecation warnings are produced, but not if the
+ receiver is of type 'id'. */
+void foo (void)
+{
+ Class c;
+ id object;
+ MyClass *another_object;
+
+ [c method];
+ [object method];
+ [c deprecatedClassMethod];
+ [object deprecatedInstanceMethod];
+
+ [object method];
+ [another_object method];
+ [MyClass deprecatedClassMethod]; /* { dg-warning "is deprecated" } */
+ [another_object deprecatedInstanceMethod]; /* { dg-warning "is deprecated" } */
+}
diff --git a/gcc/testsuite/obj-c++.dg/attributes/method-deprecated-2.mm b/gcc/testsuite/obj-c++.dg/attributes/method-deprecated-2.mm
new file mode 100644
index 00000000000..1e5d87f3e63
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/attributes/method-deprecated-2.mm
@@ -0,0 +1,23 @@
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010. */
+/* { dg-do compile } */
+
+#include <objc/objc.h>
+
+@interface MyClass
+{
+ Class isa;
+}
++ (int) deprecatedClassMethod: (id)firstObject, ... __attribute__((sentinel)) __attribute__((deprecated));
+- (int) deprecatedInstanceMethod: (id)firstobject, ... __attribute__((sentinel)) __attribute__((deprecated));
+@end
+
+/* Test that deprecation warnings are produced even if the method is
+ also marked with another attribute too (this is to test the
+ processing of multiple attributes). */
+void foo (void)
+{
+ MyClass *object = nil;
+
+ [MyClass deprecatedClassMethod: object, nil]; /* { dg-warning "is deprecated" } */
+ [object deprecatedInstanceMethod: object, nil]; /* { dg-warning "is deprecated" } */
+}
diff --git a/gcc/testsuite/obj-c++.dg/attributes/method-deprecated-3.mm b/gcc/testsuite/obj-c++.dg/attributes/method-deprecated-3.mm
new file mode 100644
index 00000000000..5c715a20b68
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/attributes/method-deprecated-3.mm
@@ -0,0 +1,21 @@
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010. */
+/* { dg-do compile } */
+
+#include <objc/objc.h>
+
+/* Test that __attribute__ ((__deprecated__)) works as well as __attribute__ ((deprecated)). */
+@interface MyClass
+{
+ Class isa;
+}
++ (int) deprecatedClassMethod: (id)firstObject, ... __attribute__((__deprecated__));
+- (int) deprecatedInstanceMethod: (id)firstobject, ... __attribute__((__deprecated__));
+@end
+
+void foo (void)
+{
+ MyClass *object = nil;
+
+ [MyClass deprecatedClassMethod: object, nil]; /* { dg-warning "is deprecated" } */
+ [object deprecatedInstanceMethod: object, nil]; /* { dg-warning "is deprecated" } */
+}
diff --git a/gcc/testsuite/obj-c++.dg/attributes/method-format-1.mm b/gcc/testsuite/obj-c++.dg/attributes/method-format-1.mm
new file mode 100644
index 00000000000..0a078ff0a3a
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/attributes/method-format-1.mm
@@ -0,0 +1,43 @@
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010. */
+/* { dg-do compile } */
+/* { dg-options "-Wall" } */
+
+#include <objc/objc.h>
+#include <stdlib.h>
+
+@interface LogObject
+{
+ Class isa;
+}
++ (void) log: (int)level message: (const char *) my_format, ... __attribute__ ((format (printf, 2, 3)));
+- (void) log: (int)level message: (const char *) my_format, ... __attribute__ ((format (printf, 2, 3)));
+
++ (void) debug: (const char *) my_format, ... __attribute__ ((format (printf, 1, 2)));
+- (void) debug: (const char *) my_format, ... __attribute__ ((format (printf, 1, 2)));
+
+/* Just make sure a missing or invalid attribute won't crash the compiler. */
+- (void) log2: (int)level message: (const char *) my_format, ... __attribute__ ((format (printf, 2))); /* { dg-error "wrong" } */
++ (void) debug2: (const char *) my_format, ... __attribute__ ((format (printf))); /* { dg-error "wrong" } */
+- (void) debug2: (const char *) my_format, ... __attribute__ ((format (printf))); /* { dg-error "wrong" } */
++ (void) alert: (const char *) my_format __attribute__ ((format (printf, 1, 2))); /* { dg-error "args to be formatted is not ..." } */
+- (void) alert: (const char *) my_format __attribute__ ((format (printf, 1, 2))); /* { dg-error "args to be formatted is not ..." } */
+@end
+
+void test (LogObject *object)
+{
+ [object log: 2 message: "attribute only applies to variadic functions"];
+ [object log: 2 message: "attribute %s only applies to variadic functions", "'format'"];
+ [object log: 2 message: "attribute %s only applies to variadic functions"]; /* { dg-warning "too few arguments for format" } */
+
+ [object debug: "attribute only applies to variadic functions"];
+ [object debug: "attribute %s only applies to variadic functions", "'format'"];
+ [object debug: "attribute %s only applies to variadic functions"]; /* { dg-warning "too few arguments for format" } */
+
+ [LogObject log: 2 message: "attribute only applies to variadic functions"];
+ [LogObject log: 2 message: "attribute %s only applies to variadic functions", "'format'"];
+ [LogObject log: 2 message: "attribute %s only applies to variadic functions"]; /* { dg-warning "too few arguments for format" } */
+
+ [LogObject debug: "attribute only applies to variadic functions"];
+ [LogObject debug: "attribute %s only applies to variadic functions", "'format'"];
+ [LogObject debug: "attribute %s only applies to variadic functions"]; /* { dg-warning "too few arguments for format" } */
+}
diff --git a/gcc/testsuite/obj-c++.dg/attributes/method-noreturn-1.mm b/gcc/testsuite/obj-c++.dg/attributes/method-noreturn-1.mm
new file mode 100644
index 00000000000..af051a61d34
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/attributes/method-noreturn-1.mm
@@ -0,0 +1,34 @@
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010. */
+/* { dg-do compile } */
+
+#include <objc/objc.h>
+#include <stdlib.h>
+
+@interface MyClass
+{
+ Class isa;
+}
++ (id) method1 __attribute__ ((noreturn));
+- (id) method2 __attribute__ ((noreturn));
++ (id) method3 __attribute__ ((noreturn));
+- (id) method4 __attribute__ ((noreturn));
+@end
+
+@implementation MyClass
++ (id) method1
+{
+ return self; /* { dg-warning "function declared .noreturn. has a .return. statement" } */
+} /* { dg-warning ".noreturn. function does return" } */
+- (id) method2
+{
+ return self; /* { dg-warning "function declared .noreturn. has a .return. statement" } */
+} /* { dg-warning ".noreturn. function does return" } */
++ (id) method3
+{
+ abort ();
+}
+- (id) method4
+{
+ abort ();
+}
+@end
diff --git a/gcc/testsuite/obj-c++.dg/attributes/method-sentinel-1.mm b/gcc/testsuite/obj-c++.dg/attributes/method-sentinel-1.mm
new file mode 100644
index 00000000000..ecaa36c21f8
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/attributes/method-sentinel-1.mm
@@ -0,0 +1,34 @@
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010. */
+/* { dg-do compile } */
+/* { dg-options "-Wall" } */
+
+#include <objc/objc.h>
+#include <stdlib.h>
+
+@interface NSArray
+{
+ Class isa;
+}
++ (id) arrayWithObject: (id)object __attribute__ ((sentinel)); /* { dg-warning "attribute only applies to variadic functions" } */
++ (id) arrayWithObjects: (id)firstObject, ... __attribute__ ((sentinel));
+
+- (id) initWithObject: (id)object __attribute__ ((sentinel)); /* { dg-warning "attribute only applies to variadic functions" } */
+- (id) initWithObjects: (id)firstObject, ... __attribute__ ((sentinel));
+@end
+
+void test (id object)
+{
+ NSArray *array;
+
+ array = [NSArray arrayWithObject: object];
+ array = [NSArray arrayWithObjects: object, nil];
+ array = [NSArray arrayWithObjects: object, object, nil];
+ array = [NSArray arrayWithObjects: object]; /* { dg-warning "not enough variable arguments" } */
+ array = [NSArray arrayWithObjects: object, object]; /* { dg-warning "missing sentinel" } */
+
+ [array initWithObject: object];
+ [array initWithObjects: object, nil];
+ [array initWithObjects: object, object, nil];
+ [array initWithObjects: object]; /* { dg-warning "not enough variable arguments" } */
+ [array initWithObjects: object, object]; /* { dg-warning "missing sentinel" } */
+}
diff --git a/gcc/testsuite/obj-c++.dg/property/at-property-10.mm b/gcc/testsuite/obj-c++.dg/property/at-property-10.mm
index f130292bb0f..83494ec3bcc 100644
--- a/gcc/testsuite/obj-c++.dg/property/at-property-10.mm
+++ b/gcc/testsuite/obj-c++.dg/property/at-property-10.mm
@@ -12,7 +12,7 @@
Class isa;
int a;
}
-@property int a;
+@property (nonatomic) int a;
+ (id) initialize;
+ (id) alloc;
- (id) init;
diff --git a/gcc/testsuite/obj-c++.dg/property/at-property-11.mm b/gcc/testsuite/obj-c++.dg/property/at-property-11.mm
index 36da7bf2794..82880521680 100644
--- a/gcc/testsuite/obj-c++.dg/property/at-property-11.mm
+++ b/gcc/testsuite/obj-c++.dg/property/at-property-11.mm
@@ -12,7 +12,7 @@
Class isa;
int a;
}
-@property int a;
+@property (nonatomic) int a;
+ (id) initialize;
+ (id) alloc;
- (id) init;
diff --git a/gcc/testsuite/obj-c++.dg/property/at-property-12.mm b/gcc/testsuite/obj-c++.dg/property/at-property-12.mm
new file mode 100644
index 00000000000..8d28bde9668
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/property/at-property-12.mm
@@ -0,0 +1,46 @@
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010. */
+/* { dg-do run } */
+
+/* Test atomic, assign synthesized methods. */
+
+#include <stdlib.h>
+#include <objc/objc.h>
+#include <objc/runtime.h>
+
+@interface MyRootClass
+{
+ Class isa;
+ int a;
+ id b;
+}
+@property int a;
+@property (assign) id b;
++ (id) initialize;
++ (id) alloc;
+- (id) init;
+@end
+
+@implementation MyRootClass
++ (id) initialize { return self; }
++ (id) alloc { return class_createInstance (self, 0); }
+- (id) init { return self; }
+@synthesize a;
+@synthesize b;
+@end
+
+int main (void)
+{
+ MyRootClass *object = [[MyRootClass alloc] init];
+
+ object.a = 40;
+ if (object.a != 40)
+ abort ();
+
+ object.b = object;
+ if (object.b != object)
+ abort ();
+
+ return (0);
+}
+
+
diff --git a/gcc/testsuite/obj-c++.dg/property/at-property-13.mm b/gcc/testsuite/obj-c++.dg/property/at-property-13.mm
new file mode 100644
index 00000000000..5a5dcbbf63c
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/property/at-property-13.mm
@@ -0,0 +1,71 @@
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010. */
+/* { dg-do run } */
+
+/* Test retain and copy synthesized methods. */
+
+#include <stdlib.h>
+#include <objc/objc.h>
+#include <objc/runtime.h>
+
+@interface MyRootClass
+{
+ Class isa;
+ int copy_count;
+ id a;
+ id b;
+}
+@property (copy) id a;
+@property (retain) id b;
++ (id) initialize;
++ (id) alloc;
+- (id) init;
+- (id) copyWithZone: (void *)zone;
+- (int) copyCount;
+- (id) autorelease;
+- (oneway void) release;
+- (id) retain;
+@end
+
+/* This class implements copyWithZone, which doesn't do anything other
+ than increasing a counter of how many copies were made. */
+@implementation MyRootClass
++ (id) initialize { return self; }
++ (id) alloc { return class_createInstance (self, 0); }
+- (id) init { return self; }
+- (id) copyWithZone: (void *)zone { copy_count++; return self; }
+- (int) copyCount { return copy_count; }
+- (id) autorelease { return self; }
+- (oneway void) release { return; }
+- (id) retain { return self; }
+@synthesize a;
+@synthesize b;
+@end
+
+int main (void)
+{
+ MyRootClass *object = [[MyRootClass alloc] init];
+ MyRootClass *argument = [[MyRootClass alloc] init];
+
+ /* This should copy argument. */
+ object.a = argument;
+ if (object.a != argument)
+ abort ();
+
+ /* Test that it was copied. */
+ if ([object.a copyCount] != 1)
+ abort ();
+
+ /* We just test that the retain accessors seem to work and that they
+ don't copy. We don't test that retain was actually called,
+ because if garbage collection is enabled, it may never be
+ called! */
+ object.b = argument;
+ if (object.b != argument)
+ abort ();
+
+ /* Test that it was not copied. */
+ if ([object.b copyCount] != 1)
+ abort ();
+
+ return (0);
+}
diff --git a/gcc/testsuite/obj-c++.dg/property/at-property-6.mm b/gcc/testsuite/obj-c++.dg/property/at-property-6.mm
index 3f1f0d3abe0..8b7346b95af 100644
--- a/gcc/testsuite/obj-c++.dg/property/at-property-6.mm
+++ b/gcc/testsuite/obj-c++.dg/property/at-property-6.mm
@@ -13,7 +13,7 @@
Class isa;
int a;
}
-@property int a;
+@property (nonatomic) int a;
+ (id) initialize;
+ (id) alloc;
- (id) init;
diff --git a/gcc/testsuite/obj-c++.dg/property/at-property-7.mm b/gcc/testsuite/obj-c++.dg/property/at-property-7.mm
index cae04dee498..bace2420e57 100644
--- a/gcc/testsuite/obj-c++.dg/property/at-property-7.mm
+++ b/gcc/testsuite/obj-c++.dg/property/at-property-7.mm
@@ -13,7 +13,7 @@
Class isa;
int a;
}
-@property (getter = getA) int a;
+@property (getter = getA, nonatomic) int a;
+ (id) initialize;
+ (id) alloc;
- (id) init;
diff --git a/gcc/testsuite/obj-c++.dg/property/at-property-8.mm b/gcc/testsuite/obj-c++.dg/property/at-property-8.mm
index ec37052989a..a290dd3df35 100644
--- a/gcc/testsuite/obj-c++.dg/property/at-property-8.mm
+++ b/gcc/testsuite/obj-c++.dg/property/at-property-8.mm
@@ -13,7 +13,7 @@
Class isa;
int a;
}
-@property (setter = writeA:) int a;
+@property (setter = writeA:, nonatomic) int a;
+ (id) initialize;
+ (id) alloc;
- (id) init;
diff --git a/gcc/testsuite/obj-c++.dg/property/at-property-9.mm b/gcc/testsuite/obj-c++.dg/property/at-property-9.mm
index 12e9ffde872..be52e37f5d0 100644
--- a/gcc/testsuite/obj-c++.dg/property/at-property-9.mm
+++ b/gcc/testsuite/obj-c++.dg/property/at-property-9.mm
@@ -13,7 +13,7 @@
Class isa;
int a;
}
-@property (getter = giveMeA, setter = writeA:) int a;
+@property (getter = giveMeA, setter = writeA:, nonatomic) int a;
+ (id) initialize;
+ (id) alloc;
- (id) init;
diff --git a/gcc/testsuite/obj-c++.dg/property/at-property-deprecated-1.mm b/gcc/testsuite/obj-c++.dg/property/at-property-deprecated-1.mm
new file mode 100644
index 00000000000..1bcb28820a6
--- /dev/null
+++ b/gcc/testsuite/obj-c++.dg/property/at-property-deprecated-1.mm
@@ -0,0 +1,37 @@
+/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, October 2010. */
+/* { dg-do compile } */
+
+/* Test that properties can be deprecated. */
+
+#include <stdlib.h>
+#include <objc/objc.h>
+#include <objc/runtime.h>
+
+@interface MyRootClass
+{
+ Class isa;
+ int a;
+}
+@property int a __attribute__((deprecated));
++ (id) initialize;
++ (id) alloc;
+- (id) init;
+@end
+
+@implementation MyRootClass
++ (id) initialize { return self; }
++ (id) alloc { return class_createInstance (self, 0); }
+- (id) init { return self; }
+@synthesize a;
+@end
+
+int main (void)
+{
+ MyRootClass *object = [[MyRootClass alloc] init];
+
+ object.a = 40; /* { dg-warning ".a. is deprecated .declared at " } */
+ if (object.a != 40) /* { dg-warning ".a. is deprecated .declared at " } */
+ abort ();
+
+ return (0);
+}