1/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010.  */
2/* { dg-do compile } */
3
4#include <objc/objc.h>
5
6/* Test that @optional for @protocol works.  */
7
8@protocol MyProtocol
9+ (int)classMethod;
10- (int)method;
11@optional
12+ (int)optionalClassMethod;
13- (int)optionalMethod;
14@end
15
16@interface MyRootClass <MyProtocol>
17@end
18
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
24{
25  return 20;
26}
27- (int)method
28{
29  return 11;
30}
31@end
32
33int function (id <MyProtocol> object1,
34	      MyRootClass *object2)
35{
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;
39
40  i += [object1 method];
41  i += [object2 method];
42  i += [MyRootClass classMethod];
43  i += [object1 optionalMethod];
44  i += [object2 optionalMethod];
45  i += [MyRootClass optionalClassMethod];
46
47  return i;
48}
49