1/* Contributed by Nicola Pero <nicola.pero@meta-innovation.com>, November 2010.  */
2/* { dg-do compile } */
3// { dg-additional-options "-Wno-objc-root-class" }
4
5#include <objc/objc.h>
6
7/* Test that @optional for @protocol works.  */
8
9@protocol MyProtocol
10+ (int)classMethod;
11- (int)method;
12@optional
13+ (int)optionalClassMethod;
14- (int)optionalMethod;
15@end
16
17@interface MyRootClass <MyProtocol>
18@end
19
20/* The implementation implements both the @required methods, but none
21   of the @optional ones.  There should be no warnings as the
22   @optional methods are optional. ;-)  */
23@implementation MyRootClass
24+ (int)classMethod
25{
26  return 20;
27}
28- (int)method
29{
30  return 11;
31}
32@end
33
34int function (id <MyProtocol> object1,
35	      MyRootClass *object2)
36{
37  /* Test that there are no warnings if you try to use an @optional
38     method with an object of the class.  */
39  int i = 0;
40
41  i += [object1 method];
42  i += [object2 method];
43  i += [MyRootClass classMethod];
44  i += [object1 optionalMethod];
45  i += [object2 optionalMethod];
46  i += [MyRootClass optionalClassMethod];
47
48  return i;
49}
50