blob: 7d50ba60750c73f8602fb0f678cb257e24addd2a [file] [log] [blame]
Daniel Dunbard7d5f022009-03-24 02:24:46 +00001// RUN: clang-cc -fsyntax-only %s
Daniel Dunbar5e155f02008-09-11 23:12:46 +00002// XFAIL
3// <rdar://problem/6212771>
4
5#define nil ((void*) 0)
6
7@interface A
8@property int x;
9@end
10
11@interface B : A
12@end
13
14// Basic checks...
15id f0(int cond, id a, void *b) {
16 return cond ? a : b;
17}
18A *f0_a(int cond, A *a, void *b) {
19 return cond ? a : b;
20}
21
22id f1(int cond, id a) {
23 return cond ? a : nil;
24}
25A *f1_a(int cond, A *a) {
26 return cond ? a : nil;
27}
28
29// Check interaction with qualified id
30
31@protocol P0 @end
32
33id f2(int cond, id<P0> a, void *b) {
34 return cond ? a : b;
35}
36
37id f3(int cond, id<P0> a) {
38 return cond ? a : nil;
39}
40
41// Check that result actually has correct type.
42
43// Using properties is one way to find the compiler internal type of a
44// conditional expression. Simple assignment doesn't work because if
45// the type is id then it can be implicitly promoted.
46@protocol P1
47@property int x;
48@end
49
50int f5(int cond, id<P1> a, id<P1> b) {
51 // This should result in something with id type, currently. This is
52 // almost certainly wrong and should be fixed.
53 return (cond ? a : b).x; // expected-error {{member reference base type ('id') is not a structure or union}}
54}
55int f5_a(int cond, A *a, A *b) {
56 return (cond ? a : b).x;
57}
58int f5_b(int cond, A *a, B *b) {
59 return (cond ? a : b).x;
60}
61
62int f6(int cond, id<P1> a, void *b) {
63 // This should result in something with id type, currently.
64 return (cond ? a : b).x; // expected-error {{member reference base type ('id') is not a structure or union}}
65}
66
67int f7(int cond, id<P1> a) {
68 return (cond ? a : nil).x;
69}
70
71int f8(int cond, id<P1> a, A *b) {
72 // GCC regards this as a warning (comparison of distinct Objective-C types lacks a cast)
73 return a == b; // expected-error {{invalid operands to binary expression}}
74}
75
76int f9(int cond, id<P1> a, A *b) {
77 return (cond ? a : b).x; // expected-error {{incompatible operand types}}
78}