OSDN Git Service

gcc/
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / objc.dg / method-11.m
1 /* Ensure that we indeed cannot obtain the value of a message send
2    if the chosen method signature returns 'void'.  There used to
3    exist a cheesy hack that allowed it.  While at it, check that
4    the first lexically occurring method signature gets picked
5    when sending messages to 'id'.  */ 
6 /* Contributed by Ziemowit Laski <zlaski@apple.com>  */
7 /* { dg-do compile } */
8
9 #include <objc/objc.h>
10
11 @interface Object1
12 - (void)initWithData:(Object1 *)data;
13 @end
14
15 @interface Object2
16 - (id)initWithData:(Object1 *)data;
17 @end
18
19 @interface Object3
20 - (id)initWithData:(Object2 *)data;
21 @end
22
23 void foo(void) {
24   id obj1, obj2 = 0;
25   obj2 = [obj1 initWithData: obj2];
26      /* { dg-warning "multiple methods named .\\-initWithData:. found" "" { target *-*-* } 25 } */
27      /* { dg-message "using .\\-\\(void\\)initWithData:\\(Object1 \\*\\)data." "" { target *-*-* } 12 } */
28      /* { dg-message "also found .\\-\\(id\\)initWithData:\\(Object1 \\*\\)data." "" { target *-*-* } 16 } */
29      /* { dg-message "also found .\\-\\(id\\)initWithData:\\(Object2 \\*\\)data." "" { target *-*-* } 20 } */
30
31      /* The following error is a consequence of picking the "wrong" method signature.  */
32      /* { dg-error "void value not ignored as it ought to be" "" { target *-*-* } 25 } */
33 }