1 // RUN: %clang_cc1 -fsyntax-only -verify %s
3 #define nil ((void*) 0)
13 id f0(int cond, id a, void *b) {
16 A *f0_a(int cond, A *a, void *b) {
20 id f1(int cond, id a) {
21 return cond ? a : nil;
23 A *f1_a(int cond, A *a) {
24 return cond ? a : nil;
27 void *f1_const_a(int x, void *p, const A * q) {
28 void *r = x ? p : q; // expected-warning{{initializing 'void *' with an expression of type 'const void *' discards qualifiers}}
32 // Check interaction with qualified id
36 id f2(int cond, id<P0> a, void *b) {
40 id f3(int cond, id<P0> a) {
41 return cond ? a : nil;
44 // Check that result actually has correct type.
46 // Using properties is one way to find the compiler internal type of a
47 // conditional expression. Simple assignment doesn't work because if
48 // the type is id then it can be implicitly promoted.
53 int f5(int cond, id<P1> a, id<P1> b) {
54 return (cond ? a : b).x;
56 int f5_a(int cond, A *a, A *b) {
57 return (cond ? a : b).x;
59 int f5_b(int cond, A *a, B *b) {
60 return (cond ? a : b).x;
63 int f6(int cond, id<P1> a, void *b) {
64 // This should result in something with id type, currently.
65 return (cond ? a : b).x; // expected-error {{member reference base type 'void *' is not a structure or union}}
68 int f7(int cond, id<P1> a) {
69 return (cond ? a : nil).x;
72 int f8(int cond, id<P1> a, A *b) {
73 return a == b; // expected-warning {{comparison of distinct pointer types ('id<P1>' and 'A *')}}
76 int f9(int cond, id<P1> a, A *b) {
77 return (cond ? a : b).x; // expected-warning {{incompatible operand types ('id<P1>' and 'A *')}} \
78 expected-error {{property 'x' not found on object of type 'id'}}