xref: /aosp_15_r20/external/clang/test/SemaCXX/calling-conv-compat.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -std=c++11 -fms-extensions -verify -triple i686-pc-win32 %s
2*67e74705SXin Li 
3*67e74705SXin Li // Pointers to free functions
4*67e74705SXin Li void            free_func_default();
5*67e74705SXin Li void __cdecl    free_func_cdecl();
6*67e74705SXin Li void __stdcall  free_func_stdcall();
7*67e74705SXin Li void __fastcall free_func_fastcall();
8*67e74705SXin Li 
9*67e74705SXin Li typedef void (           *fptr_default)();
10*67e74705SXin Li typedef void (__cdecl    *fptr_cdecl)();
11*67e74705SXin Li typedef void (__stdcall  *fptr_stdcall)();
12*67e74705SXin Li typedef void (__fastcall *fptr_fastcall)();
13*67e74705SXin Li 
14*67e74705SXin Li // expected-note@+4 {{candidate function not viable: no known conversion from 'void () __attribute__((stdcall))' to 'fptr_default' (aka 'void (*)()') for 1st argument}}
15*67e74705SXin Li // expected-note@+3 {{candidate function not viable: no known conversion from 'void () __attribute__((fastcall))' to 'fptr_default' (aka 'void (*)()') for 1st argument}}
16*67e74705SXin Li // expected-note@+2 {{candidate function not viable: no known conversion from 'void (*)() __attribute__((stdcall))' to 'fptr_default' (aka 'void (*)()') for 1st argument}}
17*67e74705SXin Li // expected-note@+1 {{candidate function not viable: no known conversion from 'void (*)() __attribute__((fastcall))' to 'fptr_default' (aka 'void (*)()') for 1st argument}}
18*67e74705SXin Li void cb_fptr_default(fptr_default ptr);
19*67e74705SXin Li // expected-note@+4 {{candidate function not viable: no known conversion from 'void () __attribute__((stdcall))' to 'fptr_cdecl' (aka 'void (*)()') for 1st argument}}
20*67e74705SXin Li // expected-note@+3 {{candidate function not viable: no known conversion from 'void () __attribute__((fastcall))' to 'fptr_cdecl' (aka 'void (*)()') for 1st argument}}
21*67e74705SXin Li // expected-note@+2 {{candidate function not viable: no known conversion from 'void (*)() __attribute__((stdcall))' to 'fptr_cdecl' (aka 'void (*)()') for 1st argument}}
22*67e74705SXin Li // expected-note@+1 {{candidate function not viable: no known conversion from 'void (*)() __attribute__((fastcall))' to 'fptr_cdecl' (aka 'void (*)()') for 1st argument}}
23*67e74705SXin Li void cb_fptr_cdecl(fptr_cdecl ptr);
24*67e74705SXin Li // expected-note@+3 {{candidate function not viable: no known conversion from 'void ()' to 'fptr_stdcall' (aka 'void (*)() __attribute__((stdcall))') for 1st argument}}
25*67e74705SXin Li // expected-note@+2 {{candidate function not viable: no known conversion from 'void () __attribute__((cdecl))' to 'fptr_stdcall' (aka 'void (*)() __attribute__((stdcall))') for 1st argument}}
26*67e74705SXin Li // expected-note@+1 {{candidate function not viable: no known conversion from 'void () __attribute__((fastcall))' to 'fptr_stdcall' (aka 'void (*)() __attribute__((stdcall))') for 1st argument}}
27*67e74705SXin Li void cb_fptr_stdcall(fptr_stdcall ptr);
28*67e74705SXin Li // expected-note@+3 {{candidate function not viable: no known conversion from 'void ()' to 'fptr_fastcall' (aka 'void (*)() __attribute__((fastcall))') for 1st argument}}
29*67e74705SXin Li // expected-note@+2 {{candidate function not viable: no known conversion from 'void () __attribute__((cdecl))' to 'fptr_fastcall' (aka 'void (*)() __attribute__((fastcall))') for 1st argument}}
30*67e74705SXin Li // expected-note@+1 {{candidate function not viable: no known conversion from 'void () __attribute__((stdcall))' to 'fptr_fastcall' (aka 'void (*)() __attribute__((fastcall))') for 1st argument}}
31*67e74705SXin Li void cb_fptr_fastcall(fptr_fastcall ptr);
32*67e74705SXin Li // expected-note@+2 {{candidate function not viable: no known conversion from 'void () __attribute__((stdcall))' to 'const fptr_default' (aka 'void (*const)()') for 1st argument}}
33*67e74705SXin Li // expected-note@+1 {{candidate function not viable: no known conversion from 'void () __attribute__((fastcall))' to 'const fptr_default' (aka 'void (*const)()') for 1st argument}}
34*67e74705SXin Li void cb_fptr_const_default(const fptr_default ptr);
35*67e74705SXin Li 
call_free_func()36*67e74705SXin Li void call_free_func() {
37*67e74705SXin Li   cb_fptr_default(free_func_default);
38*67e74705SXin Li   cb_fptr_default(free_func_cdecl);
39*67e74705SXin Li   cb_fptr_default(free_func_stdcall); // expected-error {{no matching function for call to 'cb_fptr_default'}}
40*67e74705SXin Li   cb_fptr_default(free_func_fastcall); // expected-error {{no matching function for call to 'cb_fptr_default'}}
41*67e74705SXin Li   cb_fptr_default(&free_func_default);
42*67e74705SXin Li   cb_fptr_default(&free_func_cdecl);
43*67e74705SXin Li   cb_fptr_default(&free_func_stdcall); // expected-error {{no matching function for call to 'cb_fptr_default'}}
44*67e74705SXin Li   cb_fptr_default(&free_func_fastcall); // expected-error {{no matching function for call to 'cb_fptr_default'}}
45*67e74705SXin Li 
46*67e74705SXin Li   cb_fptr_cdecl(free_func_default);
47*67e74705SXin Li   cb_fptr_cdecl(free_func_cdecl);
48*67e74705SXin Li   cb_fptr_cdecl(free_func_stdcall); // expected-error {{no matching function for call to 'cb_fptr_cdecl'}}
49*67e74705SXin Li   cb_fptr_cdecl(free_func_fastcall); // expected-error {{no matching function for call to 'cb_fptr_cdecl'}}
50*67e74705SXin Li   cb_fptr_cdecl(&free_func_default);
51*67e74705SXin Li   cb_fptr_cdecl(&free_func_cdecl);
52*67e74705SXin Li   cb_fptr_cdecl(&free_func_stdcall); // expected-error {{no matching function for call to 'cb_fptr_cdecl'}}
53*67e74705SXin Li   cb_fptr_cdecl(&free_func_fastcall); // expected-error {{no matching function for call to 'cb_fptr_cdecl'}}
54*67e74705SXin Li 
55*67e74705SXin Li   cb_fptr_stdcall(free_func_default); // expected-error {{no matching function for call to 'cb_fptr_stdcall'}}
56*67e74705SXin Li   cb_fptr_stdcall(free_func_cdecl); // expected-error {{no matching function for call to 'cb_fptr_stdcall'}}
57*67e74705SXin Li   cb_fptr_stdcall(free_func_stdcall);
58*67e74705SXin Li   cb_fptr_stdcall(free_func_fastcall); // expected-error {{no matching function for call to 'cb_fptr_stdcall'}}
59*67e74705SXin Li 
60*67e74705SXin Li   cb_fptr_fastcall(free_func_default); // expected-error {{no matching function for call to 'cb_fptr_fastcall'}}
61*67e74705SXin Li   cb_fptr_fastcall(free_func_cdecl); // expected-error {{no matching function for call to 'cb_fptr_fastcall'}}
62*67e74705SXin Li   cb_fptr_fastcall(free_func_stdcall); // expected-error {{no matching function for call to 'cb_fptr_fastcall'}}
63*67e74705SXin Li   cb_fptr_fastcall(free_func_fastcall);
64*67e74705SXin Li 
65*67e74705SXin Li   cb_fptr_const_default(free_func_default);
66*67e74705SXin Li   cb_fptr_const_default(free_func_cdecl);
67*67e74705SXin Li   cb_fptr_const_default(free_func_stdcall); // expected-error {{no matching function for call to 'cb_fptr_const_default'}}
68*67e74705SXin Li   cb_fptr_const_default(free_func_fastcall); // expected-error {{no matching function for call to 'cb_fptr_const_default'}}
69*67e74705SXin Li 
70*67e74705SXin Li }
71*67e74705SXin Li 
72*67e74705SXin Li // Pointers to variadic functions
73*67e74705SXin Li // variadic function can't declared stdcall or fastcall
74*67e74705SXin Li void         free_func_variadic_default(int, ...);
75*67e74705SXin Li void __cdecl free_func_variadic_cdecl(int, ...);
76*67e74705SXin Li 
77*67e74705SXin Li typedef void (        *fptr_variadic_default)(int, ...);
78*67e74705SXin Li typedef void (__cdecl *fptr_variadic_cdecl)(int, ...);
79*67e74705SXin Li 
80*67e74705SXin Li void cb_fptr_variadic_default(fptr_variadic_default ptr);
81*67e74705SXin Li void cb_fptr_variadic_cdecl(fptr_variadic_cdecl ptr);
82*67e74705SXin Li 
call_free_variadic_func()83*67e74705SXin Li void call_free_variadic_func() {
84*67e74705SXin Li   cb_fptr_variadic_default(free_func_variadic_default);
85*67e74705SXin Li   cb_fptr_variadic_default(free_func_variadic_cdecl);
86*67e74705SXin Li   cb_fptr_variadic_default(&free_func_variadic_default);
87*67e74705SXin Li   cb_fptr_variadic_default(&free_func_variadic_cdecl);
88*67e74705SXin Li 
89*67e74705SXin Li   cb_fptr_variadic_cdecl(free_func_variadic_default);
90*67e74705SXin Li   cb_fptr_variadic_cdecl(free_func_variadic_cdecl);
91*67e74705SXin Li   cb_fptr_variadic_cdecl(&free_func_variadic_default);
92*67e74705SXin Li   cb_fptr_variadic_cdecl(&free_func_variadic_cdecl);
93*67e74705SXin Li }
94*67e74705SXin Li 
95*67e74705SXin Li // References to functions
96*67e74705SXin Li typedef void (           &fref_default)();
97*67e74705SXin Li typedef void (__cdecl    &fref_cdecl)();
98*67e74705SXin Li typedef void (__stdcall  &fref_stdcall)();
99*67e74705SXin Li typedef void (__fastcall &fref_fastcall)();
100*67e74705SXin Li 
101*67e74705SXin Li // expected-note@+2 {{candidate function not viable: no known conversion from 'void () __attribute__((stdcall))' to 'fref_default' (aka 'void (&)()') for 1st argument}}
102*67e74705SXin Li // expected-note@+1 {{candidate function not viable: no known conversion from 'void () __attribute__((fastcall))' to 'fref_default' (aka 'void (&)()') for 1st argument}}
103*67e74705SXin Li void cb_fref_default(fref_default ptr);
104*67e74705SXin Li // expected-note@+2 {{candidate function not viable: no known conversion from 'void () __attribute__((stdcall))' to 'fref_cdecl' (aka 'void (&)()') for 1st argument}}
105*67e74705SXin Li // expected-note@+1 {{candidate function not viable: no known conversion from 'void () __attribute__((fastcall))' to 'fref_cdecl' (aka 'void (&)()') for 1st argument}}
106*67e74705SXin Li void cb_fref_cdecl(fref_cdecl ptr);
107*67e74705SXin Li // expected-note@+3 {{candidate function not viable: no known conversion from 'void ()' to 'fref_stdcall' (aka 'void (&)() __attribute__((stdcall))') for 1st argument}}
108*67e74705SXin Li // expected-note@+2 {{candidate function not viable: no known conversion from 'void () __attribute__((cdecl))' to 'fref_stdcall' (aka 'void (&)() __attribute__((stdcall))') for 1st argument}}
109*67e74705SXin Li // expected-note@+1 {{candidate function not viable: no known conversion from 'void () __attribute__((fastcall))' to 'fref_stdcall' (aka 'void (&)() __attribute__((stdcall))') for 1st argument}}
110*67e74705SXin Li void cb_fref_stdcall(fref_stdcall ptr);
111*67e74705SXin Li // expected-note@+3 {{candidate function not viable: no known conversion from 'void ()' to 'fref_fastcall' (aka 'void (&)() __attribute__((fastcall))') for 1st argument}}
112*67e74705SXin Li // expected-note@+2 {{candidate function not viable: no known conversion from 'void () __attribute__((cdecl))' to 'fref_fastcall' (aka 'void (&)() __attribute__((fastcall))') for 1st argument}}
113*67e74705SXin Li // expected-note@+1 {{candidate function not viable: no known conversion from 'void () __attribute__((stdcall))' to 'fref_fastcall' (aka 'void (&)() __attribute__((fastcall))') for 1st argument}}
114*67e74705SXin Li void cb_fref_fastcall(fref_fastcall ptr);
115*67e74705SXin Li 
call_free_func_ref()116*67e74705SXin Li void call_free_func_ref() {
117*67e74705SXin Li   cb_fref_default(free_func_default);
118*67e74705SXin Li   cb_fref_default(free_func_cdecl);
119*67e74705SXin Li   cb_fref_default(free_func_stdcall); // expected-error {{no matching function for call to 'cb_fref_default'}}
120*67e74705SXin Li   cb_fref_default(free_func_fastcall); // expected-error {{no matching function for call to 'cb_fref_default'}}
121*67e74705SXin Li 
122*67e74705SXin Li   cb_fref_cdecl(free_func_default);
123*67e74705SXin Li   cb_fref_cdecl(free_func_cdecl);
124*67e74705SXin Li   cb_fref_cdecl(free_func_stdcall); // expected-error {{no matching function for call to 'cb_fref_cdecl'}}
125*67e74705SXin Li   cb_fref_cdecl(free_func_fastcall); // expected-error {{no matching function for call to 'cb_fref_cdecl'}}
126*67e74705SXin Li 
127*67e74705SXin Li   cb_fref_stdcall(free_func_default); // expected-error {{no matching function for call to 'cb_fref_stdcall'}}
128*67e74705SXin Li   cb_fref_stdcall(free_func_cdecl); // expected-error {{no matching function for call to 'cb_fref_stdcall'}}
129*67e74705SXin Li   cb_fref_stdcall(free_func_stdcall);
130*67e74705SXin Li   cb_fref_stdcall(free_func_fastcall); // expected-error {{no matching function for call to 'cb_fref_stdcall'}}
131*67e74705SXin Li 
132*67e74705SXin Li   cb_fref_fastcall(free_func_default); // expected-error {{no matching function for call to 'cb_fref_fastcall'}}
133*67e74705SXin Li   cb_fref_fastcall(free_func_cdecl); // expected-error {{no matching function for call to 'cb_fref_fastcall'}}
134*67e74705SXin Li   cb_fref_fastcall(free_func_stdcall); // expected-error {{no matching function for call to 'cb_fref_fastcall'}}
135*67e74705SXin Li   cb_fref_fastcall(free_func_fastcall);
136*67e74705SXin Li }
137*67e74705SXin Li 
138*67e74705SXin Li // References to variadic functions
139*67e74705SXin Li // variadic function can't declared stdcall or fastcall
140*67e74705SXin Li typedef void (        &fref_variadic_default)(int, ...);
141*67e74705SXin Li typedef void (__cdecl &fref_variadic_cdecl)(int, ...);
142*67e74705SXin Li 
143*67e74705SXin Li void cb_fref_variadic_default(fptr_variadic_default ptr);
144*67e74705SXin Li void cb_fref_variadic_cdecl(fptr_variadic_cdecl ptr);
145*67e74705SXin Li 
call_free_variadic_func_ref()146*67e74705SXin Li void call_free_variadic_func_ref() {
147*67e74705SXin Li   cb_fref_variadic_default(free_func_variadic_default);
148*67e74705SXin Li   cb_fref_variadic_default(free_func_variadic_cdecl);
149*67e74705SXin Li 
150*67e74705SXin Li   cb_fref_variadic_cdecl(free_func_variadic_default);
151*67e74705SXin Li   cb_fref_variadic_cdecl(free_func_variadic_cdecl);
152*67e74705SXin Li }
153*67e74705SXin Li 
154*67e74705SXin Li // Pointers to members
155*67e74705SXin Li namespace NonVariadic {
156*67e74705SXin Li 
157*67e74705SXin Li struct A {
158*67e74705SXin Li   void            member_default();
159*67e74705SXin Li   void __cdecl    member_cdecl();
160*67e74705SXin Li   void __thiscall member_thiscall();
161*67e74705SXin Li };
162*67e74705SXin Li 
163*67e74705SXin Li struct B : public A {
164*67e74705SXin Li };
165*67e74705SXin Li 
166*67e74705SXin Li struct C {
167*67e74705SXin Li   void            member_default();
168*67e74705SXin Li   void __cdecl    member_cdecl();
169*67e74705SXin Li   void __thiscall member_thiscall();
170*67e74705SXin Li };
171*67e74705SXin Li 
172*67e74705SXin Li typedef void (           A::*memb_a_default)();
173*67e74705SXin Li typedef void (__cdecl    A::*memb_a_cdecl)();
174*67e74705SXin Li typedef void (__thiscall A::*memb_a_thiscall)();
175*67e74705SXin Li typedef void (           B::*memb_b_default)();
176*67e74705SXin Li typedef void (__cdecl    B::*memb_b_cdecl)();
177*67e74705SXin Li typedef void (__thiscall B::*memb_b_thiscall)();
178*67e74705SXin Li typedef void (           C::*memb_c_default)();
179*67e74705SXin Li typedef void (__cdecl    C::*memb_c_cdecl)();
180*67e74705SXin Li typedef void (__thiscall C::*memb_c_thiscall)();
181*67e74705SXin Li 
182*67e74705SXin Li // expected-note@+1 {{candidate function not viable: no known conversion from 'void (NonVariadic::A::*)() __attribute__((cdecl))' to 'memb_a_default' (aka 'void (NonVariadic::A::*)() __attribute__((thiscall))') for 1st argument}}
183*67e74705SXin Li void cb_memb_a_default(memb_a_default ptr);
184*67e74705SXin Li // expected-note@+2 {{candidate function not viable: no known conversion from 'void (NonVariadic::A::*)() __attribute__((thiscall))' to 'memb_a_cdecl' (aka 'void (NonVariadic::A::*)() __attribute__((cdecl))') for 1st argument}}
185*67e74705SXin Li // expected-note@+1 {{candidate function not viable: no known conversion from 'void (NonVariadic::A::*)() __attribute__((thiscall))' to 'memb_a_cdecl' (aka 'void (NonVariadic::A::*)() __attribute__((cdecl))') for 1st argument}}
186*67e74705SXin Li void cb_memb_a_cdecl(memb_a_cdecl ptr);
187*67e74705SXin Li // expected-note@+1 {{candidate function not viable: no known conversion from 'void (NonVariadic::A::*)() __attribute__((cdecl))' to 'memb_a_thiscall' (aka 'void (NonVariadic::A::*)() __attribute__((thiscall))') for 1st argument}}
188*67e74705SXin Li void cb_memb_a_thiscall(memb_a_thiscall ptr);
189*67e74705SXin Li // expected-note@+1 {{candidate function not viable: no known conversion from 'void (NonVariadic::A::*)() __attribute__((cdecl))' to 'memb_b_default' (aka 'void (NonVariadic::B::*)() __attribute__((thiscall))') for 1st argument}}
190*67e74705SXin Li void cb_memb_b_default(memb_b_default ptr);
191*67e74705SXin Li // expected-note@+2 {{candidate function not viable: no known conversion from 'void (NonVariadic::A::*)() __attribute__((thiscall))' to 'memb_b_cdecl' (aka 'void (NonVariadic::B::*)() __attribute__((cdecl))') for 1st argument}}
192*67e74705SXin Li // expected-note@+1 {{candidate function not viable: no known conversion from 'void (NonVariadic::A::*)() __attribute__((thiscall))' to 'memb_b_cdecl' (aka 'void (NonVariadic::B::*)() __attribute__((cdecl))') for 1st argument}}
193*67e74705SXin Li void cb_memb_b_cdecl(memb_b_cdecl ptr);
194*67e74705SXin Li // expected-note@+1 {{candidate function not viable: no known conversion from 'void (NonVariadic::A::*)() __attribute__((cdecl))' to 'memb_b_thiscall' (aka 'void (NonVariadic::B::*)() __attribute__((thiscall))') for 1st argument}}
195*67e74705SXin Li void cb_memb_b_thiscall(memb_b_thiscall ptr);
196*67e74705SXin Li // expected-note@+3 {{candidate function not viable: no known conversion from 'void (NonVariadic::A::*)() __attribute__((thiscall))' to 'memb_c_default' (aka 'void (NonVariadic::C::*)() __attribute__((thiscall))') for 1st argument}}
197*67e74705SXin Li // expected-note@+2 {{candidate function not viable: no known conversion from 'void (NonVariadic::A::*)() __attribute__((cdecl))' to 'memb_c_default' (aka 'void (NonVariadic::C::*)() __attribute__((thiscall))') for 1st argument}}
198*67e74705SXin Li // expected-note@+1 {{candidate function not viable: no known conversion from 'void (NonVariadic::A::*)() __attribute__((thiscall))' to 'memb_c_default' (aka 'void (NonVariadic::C::*)() __attribute__((thiscall))') for 1st argument}}
199*67e74705SXin Li void cb_memb_c_default(memb_c_default ptr);
200*67e74705SXin Li // expected-note@+3 {{candidate function not viable: no known conversion from 'void (NonVariadic::A::*)() __attribute__((thiscall))' to 'memb_c_cdecl' (aka 'void (NonVariadic::C::*)() __attribute__((cdecl))') for 1st argument}}
201*67e74705SXin Li // expected-note@+2 {{candidate function not viable: no known conversion from 'void (NonVariadic::A::*)() __attribute__((cdecl))' to 'memb_c_cdecl' (aka 'void (NonVariadic::C::*)() __attribute__((cdecl))') for 1st argument}}
202*67e74705SXin Li // expected-note@+1 {{candidate function not viable: no known conversion from 'void (NonVariadic::A::*)() __attribute__((thiscall))' to 'memb_c_cdecl' (aka 'void (NonVariadic::C::*)() __attribute__((cdecl))') for 1st argument}}
203*67e74705SXin Li void cb_memb_c_cdecl(memb_c_cdecl ptr);
204*67e74705SXin Li // expected-note@+3 {{candidate function not viable: no known conversion from 'void (NonVariadic::A::*)() __attribute__((thiscall))' to 'memb_c_thiscall' (aka 'void (NonVariadic::C::*)() __attribute__((thiscall))') for 1st argument}}
205*67e74705SXin Li // expected-note@+2 {{candidate function not viable: no known conversion from 'void (NonVariadic::A::*)() __attribute__((cdecl))' to 'memb_c_thiscall' (aka 'void (NonVariadic::C::*)() __attribute__((thiscall))') for 1st argument}}
206*67e74705SXin Li // expected-note@+1 {{candidate function not viable: no known conversion from 'void (NonVariadic::A::*)() __attribute__((thiscall))' to 'memb_c_thiscall' (aka 'void (NonVariadic::C::*)() __attribute__((thiscall))') for 1st argument}}
207*67e74705SXin Li void cb_memb_c_thiscall(memb_c_thiscall ptr);
208*67e74705SXin Li 
call_member()209*67e74705SXin Li void call_member() {
210*67e74705SXin Li   cb_memb_a_default(&A::member_default);
211*67e74705SXin Li   cb_memb_a_default(&A::member_cdecl); // expected-error {{no matching function for call to 'cb_memb_a_default'}}
212*67e74705SXin Li   cb_memb_a_default(&A::member_thiscall);
213*67e74705SXin Li 
214*67e74705SXin Li   cb_memb_a_cdecl(&A::member_default); // expected-error {{no matching function for call to 'cb_memb_a_cdecl'}}
215*67e74705SXin Li   cb_memb_a_cdecl(&A::member_cdecl);
216*67e74705SXin Li   cb_memb_a_cdecl(&A::member_thiscall); // expected-error {{no matching function for call to 'cb_memb_a_cdecl'}}
217*67e74705SXin Li 
218*67e74705SXin Li   cb_memb_a_thiscall(&A::member_default);
219*67e74705SXin Li   cb_memb_a_thiscall(&A::member_cdecl); // expected-error {{no matching function for call to 'cb_memb_a_thiscall'}}
220*67e74705SXin Li   cb_memb_a_thiscall(&A::member_thiscall);
221*67e74705SXin Li }
222*67e74705SXin Li 
call_member_inheritance()223*67e74705SXin Li void call_member_inheritance() {
224*67e74705SXin Li   cb_memb_b_default(&A::member_default);
225*67e74705SXin Li   cb_memb_b_default(&A::member_cdecl); // expected-error {{no matching function for call to 'cb_memb_b_default'}}
226*67e74705SXin Li   cb_memb_b_default(&A::member_thiscall);
227*67e74705SXin Li   cb_memb_c_default(&A::member_default); // expected-error {{no matching function for call to 'cb_memb_c_default'}}
228*67e74705SXin Li   cb_memb_c_default(&A::member_cdecl); // expected-error {{no matching function for call to 'cb_memb_c_default'}}
229*67e74705SXin Li   cb_memb_c_default(&A::member_thiscall); // expected-error {{no matching function for call to 'cb_memb_c_default'}}
230*67e74705SXin Li 
231*67e74705SXin Li   cb_memb_b_cdecl(&A::member_default); // expected-error {{no matching function for call to 'cb_memb_b_cdecl'}}
232*67e74705SXin Li   cb_memb_b_cdecl(&A::member_cdecl);
233*67e74705SXin Li   cb_memb_b_cdecl(&A::member_thiscall); // expected-error {{no matching function for call to 'cb_memb_b_cdecl'}}
234*67e74705SXin Li   cb_memb_c_cdecl(&A::member_default); // expected-error {{no matching function for call to 'cb_memb_c_cdecl'}}
235*67e74705SXin Li   cb_memb_c_cdecl(&A::member_cdecl); // expected-error {{no matching function for call to 'cb_memb_c_cdecl'}}
236*67e74705SXin Li   cb_memb_c_cdecl(&A::member_thiscall); // expected-error {{no matching function for call to 'cb_memb_c_cdecl'}}
237*67e74705SXin Li 
238*67e74705SXin Li   cb_memb_b_thiscall(&A::member_default);
239*67e74705SXin Li   cb_memb_b_thiscall(&A::member_cdecl); // expected-error {{no matching function for call to 'cb_memb_b_thiscall'}}
240*67e74705SXin Li   cb_memb_b_thiscall(&A::member_thiscall);
241*67e74705SXin Li   cb_memb_c_thiscall(&A::member_default); // expected-error {{no matching function for call to 'cb_memb_c_thiscall'}}
242*67e74705SXin Li   cb_memb_c_thiscall(&A::member_cdecl); // expected-error {{no matching function for call to 'cb_memb_c_thiscall'}}
243*67e74705SXin Li   cb_memb_c_thiscall(&A::member_thiscall); // expected-error {{no matching function for call to 'cb_memb_c_thiscall'}}
244*67e74705SXin Li }
245*67e74705SXin Li } // end namespace NonVariadic
246*67e74705SXin Li 
247*67e74705SXin Li namespace Variadic {
248*67e74705SXin Li struct A {
249*67e74705SXin Li   void            member_default(int, ...);
250*67e74705SXin Li   void __cdecl    member_cdecl(int, ...);
251*67e74705SXin Li   void __thiscall member_thiscall(int, ...); // expected-error {{variadic function cannot use thiscall calling convention}}
252*67e74705SXin Li };
253*67e74705SXin Li 
254*67e74705SXin Li struct B : public A {
255*67e74705SXin Li };
256*67e74705SXin Li 
257*67e74705SXin Li struct C {
258*67e74705SXin Li   void            member_default(int, ...);
259*67e74705SXin Li   void __cdecl    member_cdecl(int, ...);
260*67e74705SXin Li };
261*67e74705SXin Li 
262*67e74705SXin Li typedef void (           A::*memb_a_default)(int, ...);
263*67e74705SXin Li typedef void (__cdecl    A::*memb_a_cdecl)(int, ...);
264*67e74705SXin Li typedef void (           B::*memb_b_default)(int, ...);
265*67e74705SXin Li typedef void (__cdecl    B::*memb_b_cdecl)(int, ...);
266*67e74705SXin Li typedef void (           C::*memb_c_default)(int, ...);
267*67e74705SXin Li typedef void (__cdecl    C::*memb_c_cdecl)(int, ...);
268*67e74705SXin Li 
269*67e74705SXin Li void cb_memb_a_default(memb_a_default ptr);
270*67e74705SXin Li void cb_memb_a_cdecl(memb_a_cdecl ptr);
271*67e74705SXin Li void cb_memb_b_default(memb_b_default ptr);
272*67e74705SXin Li void cb_memb_b_cdecl(memb_b_cdecl ptr);
273*67e74705SXin Li // expected-note@+2 {{candidate function not viable: no known conversion from 'void (Variadic::A::*)(int, ...)' to 'memb_c_default' (aka 'void (Variadic::C::*)(int, ...)') for 1st argument}}
274*67e74705SXin Li // expected-note@+1 {{candidate function not viable: no known conversion from 'void (Variadic::A::*)(int, ...) __attribute__((cdecl))' to 'memb_c_default' (aka 'void (Variadic::C::*)(int, ...)') for 1st argument}}
275*67e74705SXin Li void cb_memb_c_default(memb_c_default ptr);
276*67e74705SXin Li // expected-note@+2 {{candidate function not viable: no known conversion from 'void (Variadic::A::*)(int, ...)' to 'memb_c_cdecl' (aka 'void (Variadic::C::*)(int, ...) __attribute__((cdecl))') for 1st argument}}
277*67e74705SXin Li // expected-note@+1 {{candidate function not viable: no known conversion from 'void (Variadic::A::*)(int, ...) __attribute__((cdecl))' to 'memb_c_cdecl' (aka 'void (Variadic::C::*)(int, ...) __attribute__((cdecl))') for 1st argument}}
278*67e74705SXin Li void cb_memb_c_cdecl(memb_c_cdecl ptr);
279*67e74705SXin Li 
call_member()280*67e74705SXin Li void call_member() {
281*67e74705SXin Li   cb_memb_a_default(&A::member_default);
282*67e74705SXin Li   cb_memb_a_default(&A::member_cdecl);
283*67e74705SXin Li 
284*67e74705SXin Li   cb_memb_a_cdecl(&A::member_default);
285*67e74705SXin Li   cb_memb_a_cdecl(&A::member_cdecl);
286*67e74705SXin Li }
287*67e74705SXin Li 
call_member_inheritance()288*67e74705SXin Li void call_member_inheritance() {
289*67e74705SXin Li   cb_memb_b_default(&A::member_default);
290*67e74705SXin Li   cb_memb_b_default(&A::member_cdecl);
291*67e74705SXin Li   cb_memb_c_default(&A::member_default); // expected-error {{no matching function for call to 'cb_memb_c_default'}}
292*67e74705SXin Li   cb_memb_c_default(&A::member_cdecl); // expected-error {{no matching function for call to 'cb_memb_c_default'}}
293*67e74705SXin Li 
294*67e74705SXin Li   cb_memb_b_cdecl(&A::member_default);
295*67e74705SXin Li   cb_memb_b_cdecl(&A::member_cdecl);
296*67e74705SXin Li   cb_memb_c_cdecl(&A::member_default); // expected-error {{no matching function for call to 'cb_memb_c_cdecl'}}
297*67e74705SXin Li   cb_memb_c_cdecl(&A::member_cdecl); // expected-error {{no matching function for call to 'cb_memb_c_cdecl'}}
298*67e74705SXin Li }
299*67e74705SXin Li } // end namespace Variadic
300*67e74705SXin Li 
301*67e74705SXin Li namespace MultiChunkDecls {
302*67e74705SXin Li 
303*67e74705SXin Li // Try to test declarators that have multiple DeclaratorChunks.
304*67e74705SXin Li struct A {
305*67e74705SXin Li   void __thiscall member_thiscall(int);
306*67e74705SXin Li };
307*67e74705SXin Li 
return_mptr(short)308*67e74705SXin Li void (A::*return_mptr(short))(int) {
309*67e74705SXin Li   return &A::member_thiscall;
310*67e74705SXin Li }
311*67e74705SXin Li 
312*67e74705SXin Li void (A::*(*return_fptr_mptr(char))(short))(int) {
313*67e74705SXin Li   return return_mptr;
314*67e74705SXin Li }
315*67e74705SXin Li 
316*67e74705SXin Li typedef void (A::*mptr_t)(int);
return_mptr_std(short)317*67e74705SXin Li mptr_t __stdcall return_mptr_std(short) {
318*67e74705SXin Li   return &A::member_thiscall;
319*67e74705SXin Li }
320*67e74705SXin Li 
321*67e74705SXin Li void (A::*(*return_fptr_std_mptr(char))(short))(int) {
322*67e74705SXin Li   return return_mptr_std; // expected-error {{cannot initialize return object of type 'void (MultiChunkDecls::A::*(*)(short))(int) __attribute__((thiscall))' with an lvalue of type 'mptr_t (short) __attribute__((stdcall))'}}
323*67e74705SXin Li }
324*67e74705SXin Li 
call_return()325*67e74705SXin Li void call_return() {
326*67e74705SXin Li   A o;
327*67e74705SXin Li   void (A::*(*fptr)(short))(int) = return_fptr_mptr('a');
328*67e74705SXin Li   void (A::*mptr)(int) = fptr(1);
329*67e74705SXin Li   (o.*mptr)(2);
330*67e74705SXin Li }
331*67e74705SXin Li 
332*67e74705SXin Li } // end namespace MultiChunkDecls
333*67e74705SXin Li 
334*67e74705SXin Li namespace MemberPointers {
335*67e74705SXin Li 
336*67e74705SXin Li struct A {
337*67e74705SXin Li   void __thiscall method_thiscall();
338*67e74705SXin Li   void __cdecl    method_cdecl();
339*67e74705SXin Li   void __stdcall  method_stdcall();
340*67e74705SXin Li   void __fastcall method_fastcall();
341*67e74705SXin Li };
342*67e74705SXin Li 
343*67e74705SXin Li void (           A::*mp1)() = &A::method_thiscall;
344*67e74705SXin Li void (__cdecl    A::*mp2)() = &A::method_cdecl;
345*67e74705SXin Li void (__stdcall  A::*mp3)() = &A::method_stdcall;
346*67e74705SXin Li void (__fastcall A::*mp4)() = &A::method_fastcall;
347*67e74705SXin Li 
348*67e74705SXin Li // Use a typedef to form the member pointer and verify that cdecl is adjusted.
349*67e74705SXin Li typedef void (           fun_default)();
350*67e74705SXin Li typedef void (__cdecl    fun_cdecl)();
351*67e74705SXin Li typedef void (__stdcall  fun_stdcall)();
352*67e74705SXin Li typedef void (__fastcall fun_fastcall)();
353*67e74705SXin Li 
354*67e74705SXin Li fun_default  A::*td1 = &A::method_thiscall;
355*67e74705SXin Li fun_cdecl    A::*td2 = &A::method_thiscall;
356*67e74705SXin Li fun_stdcall  A::*td3 = &A::method_stdcall;
357*67e74705SXin Li fun_fastcall A::*td4 = &A::method_fastcall;
358*67e74705SXin Li 
359*67e74705SXin Li // Round trip the function type through a template, and verify that only cdecl
360*67e74705SXin Li // gets adjusted.
361*67e74705SXin Li template<typename Fn> struct X { typedef Fn A::*p; };
362*67e74705SXin Li 
363*67e74705SXin Li X<void            ()>::p tmpl1 = &A::method_thiscall;
364*67e74705SXin Li X<void __cdecl    ()>::p tmpl2 = &A::method_thiscall;
365*67e74705SXin Li X<void __stdcall  ()>::p tmpl3 = &A::method_stdcall;
366*67e74705SXin Li X<void __fastcall ()>::p tmpl4 = &A::method_fastcall;
367*67e74705SXin Li 
368*67e74705SXin Li X<fun_default >::p tmpl5 = &A::method_thiscall;
369*67e74705SXin Li X<fun_cdecl   >::p tmpl6 = &A::method_thiscall;
370*67e74705SXin Li X<fun_stdcall >::p tmpl7 = &A::method_stdcall;
371*67e74705SXin Li X<fun_fastcall>::p tmpl8 = &A::method_fastcall;
372*67e74705SXin Li 
373*67e74705SXin Li // Make sure we adjust thiscall to cdecl when extracting the function type from
374*67e74705SXin Li // a member pointer.
375*67e74705SXin Li template <typename> struct Y;
376*67e74705SXin Li 
377*67e74705SXin Li template <typename Fn, typename C>
378*67e74705SXin Li struct Y<Fn C::*> {
379*67e74705SXin Li   typedef Fn *p;
380*67e74705SXin Li };
381*67e74705SXin Li 
382*67e74705SXin Li void __cdecl f_cdecl();
383*67e74705SXin Li Y<decltype(&A::method_thiscall)>::p tmpl9 = &f_cdecl;
384*67e74705SXin Li 
385*67e74705SXin Li 
386*67e74705SXin Li } // end namespace MemberPointers
387*67e74705SXin Li 
388*67e74705SXin Li // Test that lambdas that capture nothing convert to cdecl function pointers.
389*67e74705SXin Li namespace Lambdas {
390*67e74705SXin Li 
391*67e74705SXin Li void pass_fptr_cdecl   (void (__cdecl    *fp)());
392*67e74705SXin Li void pass_fptr_stdcall (void (__stdcall  *fp)()); // expected-note {{candidate function not viable}}
393*67e74705SXin Li void pass_fptr_fastcall(void (__fastcall *fp)()); // expected-note {{candidate function not viable}}
394*67e74705SXin Li 
conversion_to_fptr()395*67e74705SXin Li void conversion_to_fptr() {
396*67e74705SXin Li   pass_fptr_cdecl   ([]() { } );
397*67e74705SXin Li   pass_fptr_stdcall ([]() { } ); // expected-error {{no matching function for call}}
398*67e74705SXin Li   pass_fptr_fastcall([]() { } ); // expected-error {{no matching function for call}}
399*67e74705SXin Li }
400*67e74705SXin Li 
401*67e74705SXin Li }
402