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