Patrick Beard | b2f6820 | 2012-04-06 18:12:22 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s |
Fariborz Jahanian | adcfab1 | 2009-12-16 23:13:33 +0000 | [diff] [blame] | 2 | |
| 3 | typedef const void * VoidStar; |
| 4 | |
| 5 | typedef struct __CFDictionary * CFMDRef; |
| 6 | |
| 7 | void RandomFunc(CFMDRef theDict, const void *key, const void *value); |
| 8 | |
| 9 | @interface Foo |
| 10 | - (void)_apply:(void (*)(const void *, const void *, void *))func context:(void *)context; |
| 11 | - (void)a:(id *)objects b:(id *)keys; |
| 12 | @end |
| 13 | |
| 14 | @implementation Foo |
| 15 | - (void)_apply:(void (*)(const void *, const void *, void *))func context:(void *)context { |
| 16 | id item; |
| 17 | id obj; |
| 18 | func(item, obj, context); |
| 19 | } |
| 20 | |
| 21 | - (void)a:(id *)objects b:(id *)keys { |
| 22 | VoidStar dict; |
| 23 | id key; |
| 24 | RandomFunc((CFMDRef)dict, key, objects[3]); |
| 25 | } |
| 26 | @end |
Fariborz Jahanian | ee9ca69 | 2010-03-15 18:36:00 +0000 | [diff] [blame] | 27 | |
| 28 | @interface I |
Douglas Gregor | a41a8c5 | 2010-04-22 00:20:18 +0000 | [diff] [blame] | 29 | - (void) Meth : (I*) Arg; // expected-note{{passing argument to parameter 'Arg' here}} |
Fariborz Jahanian | ee9ca69 | 2010-03-15 18:36:00 +0000 | [diff] [blame] | 30 | @end |
| 31 | |
Chris Lattner | d7e52b8 | 2010-09-05 00:43:21 +0000 | [diff] [blame] | 32 | void Func (I* arg); // expected-note {{candidate function not viable: no known conversion from 'const I *' to 'I *' for 1st argument}} |
Fariborz Jahanian | ee9ca69 | 2010-03-15 18:36:00 +0000 | [diff] [blame] | 33 | |
| 34 | void foo(const I *p, I* sel) { |
Chris Lattner | d7e52b8 | 2010-09-05 00:43:21 +0000 | [diff] [blame] | 35 | [sel Meth : p]; // expected-error {{cannot initialize a parameter of type 'I *' with an lvalue of type 'const I *'}} |
Fariborz Jahanian | ee9ca69 | 2010-03-15 18:36:00 +0000 | [diff] [blame] | 36 | Func(p); // expected-error {{no matching function for call to 'Func'}} |
| 37 | } |
| 38 | |
Douglas Gregor | 8578981 | 2010-06-30 23:01:39 +0000 | [diff] [blame] | 39 | @interface DerivedFromI : I |
| 40 | @end |
| 41 | |
Douglas Gregor | da80f74 | 2010-12-01 21:43:58 +0000 | [diff] [blame] | 42 | void accept_derived(DerivedFromI*); |
Douglas Gregor | 8578981 | 2010-06-30 23:01:39 +0000 | [diff] [blame] | 43 | |
| 44 | void test_base_to_derived(I* i) { |
Douglas Gregor | a3998bd | 2010-12-02 21:47:04 +0000 | [diff] [blame] | 45 | accept_derived(i); // expected-warning{{incompatible pointer types passing 'I *' to parameter of type 'DerivedFromI *'}} |
Fariborz Jahanian | 84950c7 | 2011-03-21 19:08:42 +0000 | [diff] [blame] | 46 | DerivedFromI *di = i; // expected-warning{{incompatible pointer types initializing 'DerivedFromI *' with an expression of type 'I *'}} |
Douglas Gregor | a3998bd | 2010-12-02 21:47:04 +0000 | [diff] [blame] | 47 | DerivedFromI *di2 = (DerivedFromI *)i; |
Douglas Gregor | 8578981 | 2010-06-30 23:01:39 +0000 | [diff] [blame] | 48 | } |