Debian Codegraph @

gcc/testsuite/objc.dg/method-11.m

raw
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 <[email protected]> */
7 /* { dg-do compile } */
8
9 #include <objc/objc.h>
10
11 @interface Object1
12 - (void)initWithData:(Object1 *)data; /* { dg-line Object1_initWithData } */
13 @end
14
15 @interface Object2
16 - (id)initWithData:(Object1 *)data; /* { dg-line Object2_initWithData } */
17 @end
18
19 @interface Object3
20 - (id)initWithData:(Object2 *)data; /* { dg-line Object3_initWithData } */
21 @end
22
23 void foo(void) {
24 id obj1, obj2 = 0;
25 obj2 = [obj1 initWithData: obj2]; /* { dg-line initWithData_message } */
26 /* { dg-warning "multiple methods named .\\-initWithData:. found" "" { target *-*-* } .-1 } */
27 /* { dg-message "using .\\-\\(void\\)initWithData:\\(Object1 \\*\\)data." "" { target *-*-* } Object1_initWithData } */
28 /* { dg-message "also found .\\-\\(id\\)initWithData:\\(Object1 \\*\\)data." "" { target *-*-* } Object2_initWithData } */
29 /* { dg-message "also found .\\-\\(id\\)initWithData:\\(Object2 \\*\\)data." "" { target *-*-* } Object3_initWithData } */
30
31 /* The following error is a consequence of picking the "wrong" method signature. */
32 /* { dg-error "invalid use of void expression" "" { target *-*-* } initWithData_message } */
33 }