File: conversion-ranking.mm

package info (click to toggle)
llvm-toolchain-15 1%3A15.0.6-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,554,644 kB
  • sloc: cpp: 5,922,452; ansic: 1,012,136; asm: 674,362; python: 191,568; objc: 73,855; f90: 42,327; lisp: 31,913; pascal: 11,973; javascript: 10,144; sh: 9,421; perl: 7,447; ml: 5,527; awk: 3,523; makefile: 2,520; xml: 885; cs: 573; fortran: 567
file content (90 lines) | stat: -rw-r--r-- 1,538 bytes parent folder | download | duplicates (46)
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
90
// RUN: %clang_cc1 -fsyntax-only -verify %s
// expected-no-diagnostics
@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);
}