| 1 |
/* Contributed by Nicola Pero <[email protected]>, November 2010. */ |
| 2 |
/* { dg-do compile } */ |
| 3 |
/* { dg-options "-Wno-protocol" } */ |
| 4 |
/* { dg-additional-options "-Wno-objc-root-class" } */ |
| 5 |
|
| 6 |
#include <objc/objc.h> |
| 7 |
|
| 8 |
/* Test the -Wno-protocol flag. With this, at a class is accepted |
| 9 |
(with no warnings) as conforming to a protocol even if some |
| 10 |
protocol methods are implemented in the superclass. */ |
| 11 |
|
| 12 |
@protocol MyProtocol |
| 13 |
- (int)method; |
| 14 |
@end |
| 15 |
|
| 16 |
@protocol MyProtocol2 |
| 17 |
- (int)method2; |
| 18 |
@end |
| 19 |
|
| 20 |
/* The superclass implements the method required by the protocol. */ |
| 21 |
@interface MyRootClass |
| 22 |
{ |
| 23 |
Class isa; |
| 24 |
} |
| 25 |
- (int)method; |
| 26 |
@end |
| 27 |
|
| 28 |
@implementation MyRootClass |
| 29 |
- (int)method |
| 30 |
{ |
| 31 |
return 23; |
| 32 |
} |
| 33 |
@end |
| 34 |
|
| 35 |
/* The subclass inherits the method (does not implement it directly) |
| 36 |
but that still makes it conform to the protocol. No warnings. */ |
| 37 |
@interface MySubClass : MyRootClass <MyProtocol> |
| 38 |
@end |
| 39 |
|
| 40 |
@implementation MySubClass |
| 41 |
@end /* No warnings here. */ |
| 42 |
|
| 43 |
|
| 44 |
/* The subclass instead does not inherit the method method2 (and does |
| 45 |
not implement it directly) so it does not conform to the |
| 46 |
protocol MyProtocol2. */ |
| 47 |
@interface MySubClass2 : MyRootClass <MyProtocol2> |
| 48 |
@end |
| 49 |
|
| 50 |
@implementation MySubClass2 |
| 51 |
@end /* Warnings here, below. */ |
| 52 |
/* { dg-warning "incomplete implementation of class .MySubClass2." "" { target *-*-* } .-1 } */ |
| 53 |
/* { dg-warning "method definition for .\\-method2. not found" "" { target *-*-* } .-2 } */ |
| 54 |
/* { dg-warning "class .MySubClass2. does not fully implement the .MyProtocol2. protocol" "" { target *-*-* } .-3 } */ |