PR inline-asm/84742
[official-gcc.git] / gcc / testsuite / objc.dg / proto-lossage-4.m
blob182e92d94b202a5e572f45b658724dda47d4e0a1
1 /* Test for situations in which protocol conformance information
2    may be lost while casting.  */
3 /* Author: Ziemowit Laski <zlaski@apple.com>.  */
4 /* { dg-do compile } */
6 #include <stdint.h>
8 /* One-line substitute for objc/objc.h */
9 typedef struct objc_object { struct objc_class *class_pointer; } *id;
11 @protocol Proto
12 - (intptr_t)someValue;
13 @end
15 @interface Obj
16 - (intptr_t)anotherValue;
17 @end
19 long foo(void) {
20   intptr_t receiver = 2;
21   Obj *objrcvr;
22   Obj <Proto> *objrcvr2;
24   /* NB: Since 'receiver' is an invalid ObjC message receiver, the compiler
25      should warn but then search for methods as if we were messaging 'id'.  */
27   receiver += [receiver someValue]; /* { dg-warning "invalid receiver type .intptr_t." } */
28   receiver += [receiver anotherValue]; /* { dg-warning "invalid receiver type .intptr_t." } */
30   receiver += [(Obj *)receiver someValue]; /* { dg-warning ".Obj. may not respond to .\\-someValue." } */
31 /* { dg-warning "assignment to 'intptr_t' {aka '(long )?int'} from 'id' makes integer from pointer without a cast" "" { target *-*-* } .-1 } */
33   receiver += [(Obj *)receiver anotherValue];
34   receiver += [(Obj <Proto> *)receiver someValue];
35   receiver += [(Obj <Proto> *)receiver anotherValue];
36   receiver += [objrcvr someValue]; /* { dg-warning ".Obj. may not respond to .\\-someValue." } */
37 /* { dg-warning "assignment to 'intptr_t' {aka '(long )?int'} from 'id' makes integer from pointer without a cast" "" { target *-*-* } .-1 } */
39   receiver += [objrcvr anotherValue];
40   receiver += [(Obj <Proto> *)objrcvr someValue];
41   receiver += [(Obj <Proto> *)objrcvr anotherValue];
42   receiver += [objrcvr2 someValue];
43   receiver += [objrcvr2 anotherValue];
44   receiver += [(Obj *)objrcvr2 someValue]; /* { dg-warning ".Obj. may not respond to .\\-someValue." } */
45 /* { dg-warning "assignment to 'intptr_t' {aka '(long )?int'} from 'id' makes integer from pointer without a cast" "" { target *-*-* } .-1 } */
47   receiver += [(Obj *)objrcvr2 anotherValue];
49   return receiver;
52 /* { dg-warning "Messages without a matching method signature" "" { target *-*-* } 0 } */
53 /* { dg-warning "will be assumed to return .id. and accept" "" { target *-*-* } 0 } */
54 /* { dg-warning ".\.\.\.. as arguments" "" { target *-*-* } 0 } */