Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin -std=c++0x -S %s -o %t-64.s |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 2 | // RUN: FileCheck -check-prefix LP64 --input-file=%t-64.s %s |
Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 3 | // RUN: %clang_cc1 -triple i386-apple-darwin -std=c++0x -S %s -o %t-32.s |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 4 | // RUN: FileCheck -check-prefix LP32 --input-file=%t-32.s %s |
Fariborz Jahanian | 7a1f4cc | 2009-10-23 18:08:22 +0000 | [diff] [blame] | 5 | // 13.3.3.2 Ranking implicit conversion sequences |
| 6 | |
| 7 | extern "C" int printf(...); |
| 8 | |
| 9 | struct A { |
| 10 | int Ai; |
Fariborz Jahanian | 105aa51 | 2009-11-04 19:13:37 +0000 | [diff] [blame] | 11 | bool foo(int* arg) const; |
Fariborz Jahanian | 7a1f4cc | 2009-10-23 18:08:22 +0000 | [diff] [blame] | 12 | }; |
| 13 | |
Fariborz Jahanian | 105aa51 | 2009-11-04 19:13:37 +0000 | [diff] [blame] | 14 | bool A::foo(int* arg) const { |
| 15 | printf("A::foo(%d)\n", *arg); |
| 16 | return true; |
| 17 | } |
| 18 | |
Fariborz Jahanian | 7a1f4cc | 2009-10-23 18:08:22 +0000 | [diff] [blame] | 19 | struct B : public A { |
| 20 | void bf() { printf("B::bf called\n"); } |
| 21 | }; |
| 22 | |
| 23 | struct C : public B { }; |
| 24 | |
| 25 | // conversion of B::* to C::* is better than conversion of A::* to C::* |
| 26 | typedef void (A::*pmfa)(); |
| 27 | typedef void (B::*pmfb)(); |
| 28 | typedef void (C::*pmfc)(); |
| 29 | |
| 30 | struct X { |
| 31 | operator pmfa(); |
| 32 | operator pmfb() { |
| 33 | return &B::bf; |
| 34 | } |
| 35 | }; |
| 36 | |
| 37 | |
| 38 | void g(pmfc pm) { |
| 39 | C c; |
| 40 | (c.*pm)(); |
| 41 | } |
| 42 | |
| 43 | void test2(X x) |
| 44 | { |
| 45 | g(x); |
| 46 | } |
| 47 | |
Fariborz Jahanian | 105aa51 | 2009-11-04 19:13:37 +0000 | [diff] [blame] | 48 | struct B1 { |
| 49 | bool (A::*pmf)(int*) const; |
| 50 | |
| 51 | B1(int i) : pmf(&A::foo), im(i) { |
| 52 | ((A*)this->*pmf)(&im); |
| 53 | } |
| 54 | |
| 55 | int im; |
| 56 | }; |
| 57 | |
Fariborz Jahanian | 7a1f4cc | 2009-10-23 18:08:22 +0000 | [diff] [blame] | 58 | int main() |
| 59 | { |
| 60 | X x; |
| 61 | test2(x); |
Fariborz Jahanian | 105aa51 | 2009-11-04 19:13:37 +0000 | [diff] [blame] | 62 | B1 b = B1(1); |
| 63 | B1 c = B1(2); |
Fariborz Jahanian | 7a1f4cc | 2009-10-23 18:08:22 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Sean Callanan | 3b29901 | 2009-12-18 00:04:09 +0000 | [diff] [blame] | 66 | // CHECK-LP64: callq __ZN1XcvM1BFvvEEv |
| 67 | // CHECK-LP64: callq __Z1gM1CFvvE |
Fariborz Jahanian | 7a1f4cc | 2009-10-23 18:08:22 +0000 | [diff] [blame] | 68 | |
| 69 | // CHECK-LP32: call L__ZN1XcvM1BFvvEEv |
| 70 | // CHECK-LP32: call __Z1gM1CFvvE |