xref: /minix3/external/bsd/llvm/dist/clang/test/SemaObjCXX/conversion-ranking.mm (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc// RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc// expected-no-diagnostics
3*f4a2713aSLionel Sambuc@protocol P1
4*f4a2713aSLionel Sambuc@end
5*f4a2713aSLionel Sambuc
6*f4a2713aSLionel Sambuc@interface A <P1>
7*f4a2713aSLionel Sambuc@end
8*f4a2713aSLionel Sambuc
9*f4a2713aSLionel Sambuc@interface B : A
10*f4a2713aSLionel Sambuc@end
11*f4a2713aSLionel Sambuc
12*f4a2713aSLionel Sambuc@interface C : B
13*f4a2713aSLionel Sambuc@end
14*f4a2713aSLionel Sambuc
15*f4a2713aSLionel Sambuctemplate<typename T>
16*f4a2713aSLionel Sambucstruct ConvertsTo {
17*f4a2713aSLionel Sambuc  operator T() const;
18*f4a2713aSLionel Sambuc};
19*f4a2713aSLionel Sambuc
20*f4a2713aSLionel Sambuc
21*f4a2713aSLionel Sambuc// conversion of C* to B* is better than conversion of C* to A*.
22*f4a2713aSLionel Sambucint &f0(A*);
23*f4a2713aSLionel Sambucfloat &f0(B*);
24*f4a2713aSLionel Sambuc
25*f4a2713aSLionel Sambucvoid test_f0(C *c) {
26*f4a2713aSLionel Sambuc  float &fr1 = f0(c);
27*f4a2713aSLionel Sambuc}
28*f4a2713aSLionel Sambuc
29*f4a2713aSLionel Sambuc// conversion of B* to A* is better than conversion of C* to A*
30*f4a2713aSLionel Sambucvoid f1(A*);
31*f4a2713aSLionel Sambuc
32*f4a2713aSLionel Sambucstruct ConvertsToBoth {
33*f4a2713aSLionel Sambucprivate:
34*f4a2713aSLionel Sambuc  operator C*() const;
35*f4a2713aSLionel Sambuc
36*f4a2713aSLionel Sambucpublic:
37*f4a2713aSLionel Sambuc  operator B*() const;
38*f4a2713aSLionel Sambuc};
39*f4a2713aSLionel Sambuc
40*f4a2713aSLionel Sambucvoid test_f1(ConvertsTo<B*> toB, ConvertsTo<C*> toC, ConvertsToBoth toBoth) {
41*f4a2713aSLionel Sambuc  f1(toB);
42*f4a2713aSLionel Sambuc  f1(toC);
43*f4a2713aSLionel Sambuc  f1(toBoth);
44*f4a2713aSLionel Sambuc};
45*f4a2713aSLionel Sambuc
46*f4a2713aSLionel Sambuc// A conversion to an a non-id object pointer type is better than a
47*f4a2713aSLionel Sambuc// conversion to 'id'.
48*f4a2713aSLionel Sambucint &f2(A*);
49*f4a2713aSLionel Sambucfloat &f2(id);
50*f4a2713aSLionel Sambuc
51*f4a2713aSLionel Sambucvoid test_f2(B *b) {
52*f4a2713aSLionel Sambuc  int &ir = f2(b);
53*f4a2713aSLionel Sambuc}
54*f4a2713aSLionel Sambuc
55*f4a2713aSLionel Sambuc// A conversion to an a non-Class object pointer type is better than a
56*f4a2713aSLionel Sambuc// conversion to 'Class'.
57*f4a2713aSLionel Sambucint &f3(A*);
58*f4a2713aSLionel Sambucfloat &f3(Class);
59*f4a2713aSLionel Sambuc
60*f4a2713aSLionel Sambucvoid test_f3(B *b) {
61*f4a2713aSLionel Sambuc  int &ir = f3(b);
62*f4a2713aSLionel Sambuc}
63*f4a2713aSLionel Sambuc
64*f4a2713aSLionel Sambuc// When both conversions convert to 'id' or 'Class', pick the most
65*f4a2713aSLionel Sambuc// specific type to convert from.
66*f4a2713aSLionel Sambucvoid f4(id);
67*f4a2713aSLionel Sambuc
68*f4a2713aSLionel Sambucvoid test_f4(ConvertsTo<B*> toB, ConvertsTo<C*> toC, ConvertsToBoth toBoth) {
69*f4a2713aSLionel Sambuc  f4(toB);
70*f4a2713aSLionel Sambuc  f4(toC);
71*f4a2713aSLionel Sambuc  f4(toBoth);
72*f4a2713aSLionel Sambuc}
73*f4a2713aSLionel Sambuc
74*f4a2713aSLionel Sambucvoid f5(id<P1>);
75*f4a2713aSLionel Sambuc
76*f4a2713aSLionel Sambucvoid test_f5(ConvertsTo<B*> toB, ConvertsTo<C*> toC, ConvertsToBoth toBoth) {
77*f4a2713aSLionel Sambuc  f5(toB);
78*f4a2713aSLionel Sambuc  f5(toC);
79*f4a2713aSLionel Sambuc  f5(toBoth);
80*f4a2713aSLionel Sambuc}
81*f4a2713aSLionel Sambuc
82*f4a2713aSLionel Sambuc
83*f4a2713aSLionel Sambuc// A conversion to an a non-id object pointer type is better than a
84*f4a2713aSLionel Sambuc// conversion to qualified 'id'.
85*f4a2713aSLionel Sambucint &f6(A*);
86*f4a2713aSLionel Sambucfloat &f6(id<P1>);
87*f4a2713aSLionel Sambuc
88*f4a2713aSLionel Sambucvoid test_f6(B *b) {
89*f4a2713aSLionel Sambuc  int &ir = f6(b);
90*f4a2713aSLionel Sambuc}
91