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