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