* tree-loop-distribution.c (struct partition): New field recording
[official-gcc.git] / gcc / testsuite / objc.dg / protocol-optional-1.m
blobbc4a3d07e978081000dcb89328bcf2bbda1c256c
1 /* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010.  */
2 /* { dg-do compile } */
4 #include <objc/objc.h>
6 /* Test that @optional for @protocol works.  */
8 @protocol MyProtocol
9 + (int)classMethod;
10 - (int)method;
11 @optional
12 + (int)optionalClassMethod;
13 - (int)optionalMethod;
14 @end
16 @interface MyRootClass <MyProtocol>
17 @end
19 /* The implementation implements both the @required methods, but none
20    of the @optional ones.  There should be no warnings as the
21    @optional methods are optional. ;-)  */
22 @implementation MyRootClass
23 + (int)classMethod
25   return 20;
27 - (int)method
29   return 11;
31 @end
33 int function (id <MyProtocol> object1,
34               MyRootClass *object2)
36   /* Test that there are no warnings if you try to use an @optional
37      method with an object of the class.  */
38   int i = 0;
40   i += [object1 method];
41   i += [object2 method];
42   i += [MyRootClass classMethod];
43   i += [object1 optionalMethod];
44   i += [object2 optionalMethod];
45   i += [MyRootClass optionalClassMethod];
47   return i;