Fix the clang-wpa example.
[clang.git] / test / SemaObjC / conditional-expr-4.m
blob56bcfc2de6fd02ca23aa9d0bdc7b350282b26535
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // <rdar://problem/6212771>
4 #define nil ((void*) 0)
6 @interface A 
7 @property int x;
8 @end
10 @interface B : A
11 @end
13 // Basic checks...
14 id f0(int cond, id a, void *b) {
15   return cond ? a : b;
17 A *f0_a(int cond, A *a, void *b) {
18   return cond ? a : b;
21 id f1(int cond, id a) {
22   return cond ? a : nil;
24 A *f1_a(int cond, A *a) {
25   return cond ? a : nil;
28 void *f1_const_a(int x, void *p, const A * q) {
29   void *r = x ? p : q; // expected-warning{{initializing 'void *' with an expression of type 'const void *' discards qualifiers}}
30   return r;
33 // Check interaction with qualified id
35 @protocol P0 @end
37 id f2(int cond, id<P0> a, void *b) {
38   return cond ? a : b;
41 id f3(int cond, id<P0> a) {
42   return cond ? a : nil;
45 // Check that result actually has correct type.
47 // Using properties is one way to find the compiler internal type of a
48 // conditional expression. Simple assignment doesn't work because if
49 // the type is id then it can be implicitly promoted.
50 @protocol P1
51 @property int x;
52 @end
54 int f5(int cond, id<P1> a, id<P1> b) {
55   return (cond ? a : b).x;
57 int f5_a(int cond, A *a, A *b) {
58   return (cond ? a : b).x;
60 int f5_b(int cond, A *a, B *b) {
61   return (cond ? a : b).x;
64 int f6(int cond, id<P1> a, void *b) {
65   // This should result in something with id type, currently.
66   return (cond ? a : b).x; // expected-error {{member reference base type 'void *' is not a structure or union}}
69 int f7(int cond, id<P1> a) {
70   return (cond ? a : nil).x;
73 int f8(int cond, id<P1> a, A *b) {
74   return a == b; // expected-warning {{comparison of distinct pointer types ('id<P1>' and 'A *')}}
77 int f9(int cond, id<P1> a, A *b) {
78   return (cond ? a : b).x; // expected-warning {{incompatible operand types ('id<P1>' and 'A *')}} \
79                               expected-error {{property 'x' not found on object of type 'id'}}