xref: /aosp_15_r20/external/clang/test/SemaObjCXX/objc-pointer-conv.mm (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li// RUN: %clang_cc1 -fsyntax-only -verify -Wno-objc-root-class %s
2*67e74705SXin Li
3*67e74705SXin Litypedef const void * VoidStar;
4*67e74705SXin Li
5*67e74705SXin Litypedef struct __CFDictionary * CFMDRef;
6*67e74705SXin Li
7*67e74705SXin Livoid RandomFunc(CFMDRef theDict, const void *key, const void *value);
8*67e74705SXin Li
9*67e74705SXin Li@interface Foo
10*67e74705SXin Li- (void)_apply:(void (*)(const void *, const void *, void *))func context:(void *)context;
11*67e74705SXin Li- (void)a:(id *)objects b:(id *)keys;
12*67e74705SXin Li@end
13*67e74705SXin Li
14*67e74705SXin Li@implementation Foo
15*67e74705SXin Li- (void)_apply:(void (*)(const void *, const void *, void *))func context:(void *)context {
16*67e74705SXin Li	id item;
17*67e74705SXin Li	id obj;
18*67e74705SXin Li    func(item, obj, context);
19*67e74705SXin Li}
20*67e74705SXin Li
21*67e74705SXin Li- (void)a:(id *)objects b:(id *)keys {
22*67e74705SXin Li    VoidStar dict;
23*67e74705SXin Li	id key;
24*67e74705SXin Li    RandomFunc((CFMDRef)dict, key, objects[3]);
25*67e74705SXin Li}
26*67e74705SXin Li@end
27*67e74705SXin Li
28*67e74705SXin Li@interface I
29*67e74705SXin Li- (void) Meth : (I*) Arg; // expected-note{{passing argument to parameter 'Arg' here}}
30*67e74705SXin Li@end
31*67e74705SXin Li
32*67e74705SXin Livoid Func (I* arg);  // expected-note {{candidate function not viable: no known conversion from 'const I *' to 'I *' for 1st argument}}
33*67e74705SXin Li
34*67e74705SXin Livoid foo(const I *p, I* sel) {
35*67e74705SXin Li  [sel Meth : p];	// expected-error {{cannot initialize a parameter of type 'I *' with an lvalue of type 'const I *'}}
36*67e74705SXin Li  Func(p);		// expected-error {{no matching function for call to 'Func'}}
37*67e74705SXin Li}
38*67e74705SXin Li
39*67e74705SXin Li@interface DerivedFromI : I
40*67e74705SXin Li@end
41*67e74705SXin Li
42*67e74705SXin Livoid accept_derived(DerivedFromI*);
43*67e74705SXin Li
44*67e74705SXin Livoid test_base_to_derived(I* i) {
45*67e74705SXin Li  accept_derived(i); // expected-warning{{incompatible pointer types passing 'I *' to parameter of type 'DerivedFromI *'}}
46*67e74705SXin Li  DerivedFromI *di = i; // expected-warning{{incompatible pointer types initializing 'DerivedFromI *' with an expression of type 'I *'}}
47*67e74705SXin Li  DerivedFromI *di2 = (DerivedFromI *)i;
48*67e74705SXin Li}
49