annotate clang/test/SemaObjCXX/conversion-ranking.mm @ 206:f17a3b42b08b

Added tag before-12 for changeset b7591485f4cd
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 07 Jun 2021 21:25:57 +0900
parents 1d019706d866
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 // RUN: %clang_cc1 -fsyntax-only -verify %s
anatofuz
parents:
diff changeset
2 // expected-no-diagnostics
anatofuz
parents:
diff changeset
3 @protocol P1
anatofuz
parents:
diff changeset
4 @end
anatofuz
parents:
diff changeset
5
anatofuz
parents:
diff changeset
6 @interface A <P1>
anatofuz
parents:
diff changeset
7 @end
anatofuz
parents:
diff changeset
8
anatofuz
parents:
diff changeset
9 @interface B : A
anatofuz
parents:
diff changeset
10 @end
anatofuz
parents:
diff changeset
11
anatofuz
parents:
diff changeset
12 @interface C : B
anatofuz
parents:
diff changeset
13 @end
anatofuz
parents:
diff changeset
14
anatofuz
parents:
diff changeset
15 template<typename T>
anatofuz
parents:
diff changeset
16 struct ConvertsTo {
anatofuz
parents:
diff changeset
17 operator T() const;
anatofuz
parents:
diff changeset
18 };
anatofuz
parents:
diff changeset
19
anatofuz
parents:
diff changeset
20
anatofuz
parents:
diff changeset
21 // conversion of C* to B* is better than conversion of C* to A*.
anatofuz
parents:
diff changeset
22 int &f0(A*);
anatofuz
parents:
diff changeset
23 float &f0(B*);
anatofuz
parents:
diff changeset
24
anatofuz
parents:
diff changeset
25 void test_f0(C *c) {
anatofuz
parents:
diff changeset
26 float &fr1 = f0(c);
anatofuz
parents:
diff changeset
27 }
anatofuz
parents:
diff changeset
28
anatofuz
parents:
diff changeset
29 // conversion of B* to A* is better than conversion of C* to A*
anatofuz
parents:
diff changeset
30 void f1(A*);
anatofuz
parents:
diff changeset
31
anatofuz
parents:
diff changeset
32 struct ConvertsToBoth {
anatofuz
parents:
diff changeset
33 private:
anatofuz
parents:
diff changeset
34 operator C*() const;
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36 public:
anatofuz
parents:
diff changeset
37 operator B*() const;
anatofuz
parents:
diff changeset
38 };
anatofuz
parents:
diff changeset
39
anatofuz
parents:
diff changeset
40 void test_f1(ConvertsTo<B*> toB, ConvertsTo<C*> toC, ConvertsToBoth toBoth) {
anatofuz
parents:
diff changeset
41 f1(toB);
anatofuz
parents:
diff changeset
42 f1(toC);
anatofuz
parents:
diff changeset
43 f1(toBoth);
anatofuz
parents:
diff changeset
44 };
anatofuz
parents:
diff changeset
45
anatofuz
parents:
diff changeset
46 // A conversion to an a non-id object pointer type is better than a
anatofuz
parents:
diff changeset
47 // conversion to 'id'.
anatofuz
parents:
diff changeset
48 int &f2(A*);
anatofuz
parents:
diff changeset
49 float &f2(id);
anatofuz
parents:
diff changeset
50
anatofuz
parents:
diff changeset
51 void test_f2(B *b) {
anatofuz
parents:
diff changeset
52 int &ir = f2(b);
anatofuz
parents:
diff changeset
53 }
anatofuz
parents:
diff changeset
54
anatofuz
parents:
diff changeset
55 // A conversion to an a non-Class object pointer type is better than a
anatofuz
parents:
diff changeset
56 // conversion to 'Class'.
anatofuz
parents:
diff changeset
57 int &f3(A*);
anatofuz
parents:
diff changeset
58 float &f3(Class);
anatofuz
parents:
diff changeset
59
anatofuz
parents:
diff changeset
60 void test_f3(B *b) {
anatofuz
parents:
diff changeset
61 int &ir = f3(b);
anatofuz
parents:
diff changeset
62 }
anatofuz
parents:
diff changeset
63
anatofuz
parents:
diff changeset
64 // When both conversions convert to 'id' or 'Class', pick the most
anatofuz
parents:
diff changeset
65 // specific type to convert from.
anatofuz
parents:
diff changeset
66 void f4(id);
anatofuz
parents:
diff changeset
67
anatofuz
parents:
diff changeset
68 void test_f4(ConvertsTo<B*> toB, ConvertsTo<C*> toC, ConvertsToBoth toBoth) {
anatofuz
parents:
diff changeset
69 f4(toB);
anatofuz
parents:
diff changeset
70 f4(toC);
anatofuz
parents:
diff changeset
71 f4(toBoth);
anatofuz
parents:
diff changeset
72 }
anatofuz
parents:
diff changeset
73
anatofuz
parents:
diff changeset
74 void f5(id<P1>);
anatofuz
parents:
diff changeset
75
anatofuz
parents:
diff changeset
76 void test_f5(ConvertsTo<B*> toB, ConvertsTo<C*> toC, ConvertsToBoth toBoth) {
anatofuz
parents:
diff changeset
77 f5(toB);
anatofuz
parents:
diff changeset
78 f5(toC);
anatofuz
parents:
diff changeset
79 f5(toBoth);
anatofuz
parents:
diff changeset
80 }
anatofuz
parents:
diff changeset
81
anatofuz
parents:
diff changeset
82
anatofuz
parents:
diff changeset
83 // A conversion to an a non-id object pointer type is better than a
anatofuz
parents:
diff changeset
84 // conversion to qualified 'id'.
anatofuz
parents:
diff changeset
85 int &f6(A*);
anatofuz
parents:
diff changeset
86 float &f6(id<P1>);
anatofuz
parents:
diff changeset
87
anatofuz
parents:
diff changeset
88 void test_f6(B *b) {
anatofuz
parents:
diff changeset
89 int &ir = f6(b);
anatofuz
parents:
diff changeset
90 }