Debian Codegraph @

gcc/testsuite/obj-c++.dg/method-16.mm

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