Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame^] | 1 | // RUN: clang-cc -fsyntax-only %s |
Daniel Dunbar | 5e155f0 | 2008-09-11 23:12:46 +0000 | [diff] [blame] | 2 | // 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... |
| 15 | id f0(int cond, id a, void *b) { |
| 16 | return cond ? a : b; |
| 17 | } |
| 18 | A *f0_a(int cond, A *a, void *b) { |
| 19 | return cond ? a : b; |
| 20 | } |
| 21 | |
| 22 | id f1(int cond, id a) { |
| 23 | return cond ? a : nil; |
| 24 | } |
| 25 | A *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 | |
| 33 | id f2(int cond, id<P0> a, void *b) { |
| 34 | return cond ? a : b; |
| 35 | } |
| 36 | |
| 37 | id 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 | |
| 50 | int 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 | } |
| 55 | int f5_a(int cond, A *a, A *b) { |
| 56 | return (cond ? a : b).x; |
| 57 | } |
| 58 | int f5_b(int cond, A *a, B *b) { |
| 59 | return (cond ? a : b).x; |
| 60 | } |
| 61 | |
| 62 | int 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 | |
| 67 | int f7(int cond, id<P1> a) { |
| 68 | return (cond ? a : nil).x; |
| 69 | } |
| 70 | |
| 71 | int 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 | |
| 76 | int f9(int cond, id<P1> a, A *b) { |
| 77 | return (cond ? a : b).x; // expected-error {{incompatible operand types}} |
| 78 | } |