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