summaryrefslogtreecommitdiff
path: root/clang/test/SemaObjCXX/conversion-ranking.mm
blob: 6c1408bf21f6965fbe822509a8fc280770a31911 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// RUN: %clang_cc1 -fsyntax-only -verify %s
@protocol P1
@end

@interface A <P1>
@end

@interface B : A
@end

@interface C : B
@end

template<typename T>
struct ConvertsTo {
  operator T() const;
};


// conversion of C* to B* is better than conversion of C* to A*.
int &f0(A*);
float &f0(B*);

void test_f0(C *c) {
  float &fr1 = f0(c);
}

// conversion of B* to A* is better than conversion of C* to A*
void f1(A*);

struct ConvertsToBoth {
private:
  operator C*() const;

public:
  operator B*() const;
};

void test_f1(ConvertsTo<B*> toB, ConvertsTo<C*> toC, ConvertsToBoth toBoth) {
  f1(toB);
  f1(toC);
  f1(toBoth);
};

// A conversion to an a non-id object pointer type is better than a 
// conversion to 'id'.
int &f2(A*);
float &f2(id);

void test_f2(B *b) {
  int &ir = f2(b);
}

// A conversion to an a non-Class object pointer type is better than a 
// conversion to 'Class'.
int &f3(A*);
float &f3(Class);

void test_f3(B *b) {
  int &ir = f3(b);
}

// When both conversions convert to 'id' or 'Class', pick the most
// specific type to convert from.
void f4(id);

void test_f4(ConvertsTo<B*> toB, ConvertsTo<C*> toC, ConvertsToBoth toBoth) {
  f4(toB);
  f4(toC);
  f4(toBoth);
}

void f5(id<P1>);

void test_f5(ConvertsTo<B*> toB, ConvertsTo<C*> toC, ConvertsToBoth toBoth) {
  f5(toB);
  f5(toC);
  f5(toBoth);
}


// A conversion to an a non-id object pointer type is better than a 
// conversion to qualified 'id'.
int &f6(A*);
float &f6(id<P1>);

void test_f6(B *b) {
  int &ir = f6(b);
}