blob: a4b68cdbc7d4856f5c34966389ed05be1d96df3d [file] [log] [blame]
Stephen Hines651f13c2014-04-23 16:59:28 -07001// RUN: %clang_cc1 -triple i686-pc-win32 -fms-extensions -verify %s
Stephen Hines6bcf27b2014-05-29 04:14:42 -07002// RUN: %clang_cc1 -triple i686-pc-mingw32 -verify %s
3// RUN: %clang_cc1 -triple i686-pc-mingw32 -fms-extensions -verify %s
Timur Iskhodzhanov33b52ad2013-02-22 12:42:50 +00004
Reid Kleckneref072032013-08-27 23:08:25 +00005typedef void void_fun_t();
6typedef void __cdecl cdecl_fun_t();
7
Timur Iskhodzhanov33b52ad2013-02-22 12:42:50 +00008// Pointers to free functions
Reid Kleckneref072032013-08-27 23:08:25 +00009void free_func_default(); // expected-note 2 {{previous declaration is here}}
10void __cdecl free_func_cdecl(); // expected-note 2 {{previous declaration is here}}
11void __stdcall free_func_stdcall(); // expected-note 2 {{previous declaration is here}}
Timur Iskhodzhanov33b52ad2013-02-22 12:42:50 +000012void __fastcall free_func_fastcall(); // expected-note 2 {{previous declaration is here}}
Stephen Hines176edba2014-12-01 14:53:08 -080013void __vectorcall free_func_vectorcall(); // expected-note 2 {{previous declaration is here}}
Timur Iskhodzhanov33b52ad2013-02-22 12:42:50 +000014
Reid Kleckneref072032013-08-27 23:08:25 +000015void __cdecl free_func_default();
Timur Iskhodzhanov33b52ad2013-02-22 12:42:50 +000016void __stdcall free_func_default(); // expected-error {{function declared 'stdcall' here was previously declared without calling convention}}
17void __fastcall free_func_default(); // expected-error {{function declared 'fastcall' here was previously declared without calling convention}}
18
Reid Kleckneref072032013-08-27 23:08:25 +000019void free_func_cdecl();
Timur Iskhodzhanov33b52ad2013-02-22 12:42:50 +000020void __stdcall free_func_cdecl(); // expected-error {{function declared 'stdcall' here was previously declared 'cdecl'}}
21void __fastcall free_func_cdecl(); // expected-error {{function declared 'fastcall' here was previously declared 'cdecl'}}
22
Reid Kleckneref072032013-08-27 23:08:25 +000023void free_func_stdcall();
Timur Iskhodzhanov33b52ad2013-02-22 12:42:50 +000024void __cdecl free_func_stdcall(); // expected-error {{function declared 'cdecl' here was previously declared 'stdcall'}}
Timur Iskhodzhanov33b52ad2013-02-22 12:42:50 +000025void __fastcall free_func_stdcall(); // expected-error {{function declared 'fastcall' here was previously declared 'stdcall'}}
26
27void __cdecl free_func_fastcall(); // expected-error {{function declared 'cdecl' here was previously declared 'fastcall'}}
28void __stdcall free_func_fastcall(); // expected-error {{function declared 'stdcall' here was previously declared 'fastcall'}}
29void free_func_fastcall();
30
Stephen Hines176edba2014-12-01 14:53:08 -080031void __cdecl free_func_vectorcall(); // expected-error {{function declared 'cdecl' here was previously declared 'vectorcall'}}
32void __stdcall free_func_vectorcall(); // expected-error {{function declared 'stdcall' here was previously declared 'vectorcall'}}
33void free_func_vectorcall();
34
Timur Iskhodzhanov33b52ad2013-02-22 12:42:50 +000035// Overloaded functions may have different calling conventions
36void __fastcall free_func_default(int);
37void __cdecl free_func_default(int *);
38
39void __thiscall free_func_cdecl(char *);
40void __cdecl free_func_cdecl(double);
41
Reid Klecknerc66e7e92013-07-31 21:00:18 +000042typedef void void_fun_t();
43typedef void __cdecl cdecl_fun_t();
Timur Iskhodzhanov33b52ad2013-02-22 12:42:50 +000044
45// Pointers to member functions
46struct S {
47 void member_default1(); // expected-note {{previous declaration is here}}
48 void member_default2();
49 void __cdecl member_cdecl1();
50 void __cdecl member_cdecl2(); // expected-note {{previous declaration is here}}
51 void __thiscall member_thiscall1();
52 void __thiscall member_thiscall2(); // expected-note {{previous declaration is here}}
Stephen Hines176edba2014-12-01 14:53:08 -080053 void __vectorcall member_vectorcall1();
54 void __vectorcall member_vectorcall2(); // expected-note {{previous declaration is here}}
Reid Klecknerc66e7e92013-07-31 21:00:18 +000055
Reid Kleckneref072032013-08-27 23:08:25 +000056 // Typedefs carrying the __cdecl convention are adjusted to __thiscall.
57 void_fun_t member_typedef_default; // expected-note {{previous declaration is here}}
58 cdecl_fun_t member_typedef_cdecl1; // expected-note {{previous declaration is here}}
59 cdecl_fun_t __cdecl member_typedef_cdecl2;
60 void_fun_t __stdcall member_typedef_stdcall;
Reid Klecknerc66e7e92013-07-31 21:00:18 +000061
Timur Iskhodzhanov33b52ad2013-02-22 12:42:50 +000062 // Static member functions can't be __thiscall
63 static void static_member_default1();
Reid Kleckneref072032013-08-27 23:08:25 +000064 static void static_member_default2();
65 static void static_member_default3(); // expected-note {{previous declaration is here}}
Timur Iskhodzhanov33b52ad2013-02-22 12:42:50 +000066 static void __cdecl static_member_cdecl1();
67 static void __cdecl static_member_cdecl2(); // expected-note {{previous declaration is here}}
68 static void __stdcall static_member_stdcall1();
69 static void __stdcall static_member_stdcall2();
70
71 // Variadic functions can't be other than default or __cdecl
72 void member_variadic_default(int x, ...);
73 void __cdecl member_variadic_cdecl(int x, ...);
74
75 static void static_member_variadic_default(int x, ...);
76 static void __cdecl static_member_variadic_cdecl(int x, ...);
77};
78
79void __cdecl S::member_default1() {} // expected-error {{function declared 'cdecl' here was previously declared without calling convention}}
80void __thiscall S::member_default2() {}
81
Reid Kleckneref072032013-08-27 23:08:25 +000082void __cdecl S::member_typedef_default() {} // expected-error {{function declared 'cdecl' here was previously declared without calling convention}}
83void __cdecl S::member_typedef_cdecl1() {} // expected-error {{function declared 'cdecl' here was previously declared without calling convention}}
84void __cdecl S::member_typedef_cdecl2() {}
Reid Klecknerc66e7e92013-07-31 21:00:18 +000085void __stdcall S::member_typedef_stdcall() {}
86
Timur Iskhodzhanov33b52ad2013-02-22 12:42:50 +000087void S::member_cdecl1() {}
88void __thiscall S::member_cdecl2() {} // expected-error {{function declared 'thiscall' here was previously declared 'cdecl'}}
89
90void S::member_thiscall1() {}
91void __cdecl S::member_thiscall2() {} // expected-error {{function declared 'cdecl' here was previously declared 'thiscall'}}
92
Stephen Hines176edba2014-12-01 14:53:08 -080093void S::member_vectorcall1() {}
94void __cdecl S::member_vectorcall2() {} // expected-error {{function declared 'cdecl' here was previously declared 'vectorcall'}}
95
Reid Kleckneref072032013-08-27 23:08:25 +000096void S::static_member_default1() {}
97void __cdecl S::static_member_default2() {}
98void __stdcall S::static_member_default3() {} // expected-error {{function declared 'stdcall' here was previously declared without calling convention}}
Timur Iskhodzhanov33b52ad2013-02-22 12:42:50 +000099
100void S::static_member_cdecl1() {}
101void __stdcall S::static_member_cdecl2() {} // expected-error {{function declared 'stdcall' here was previously declared 'cdecl'}}
102
Reid Kleckneref072032013-08-27 23:08:25 +0000103void __cdecl S::member_variadic_default(int x, ...) { (void)x; }
104void S::member_variadic_cdecl(int x, ...) { (void)x; }
Timur Iskhodzhanov33b52ad2013-02-22 12:42:50 +0000105
Reid Kleckneref072032013-08-27 23:08:25 +0000106void __cdecl S::static_member_variadic_default(int x, ...) { (void)x; }
107void S::static_member_variadic_cdecl(int x, ...) { (void)x; }
Timur Iskhodzhanov33b52ad2013-02-22 12:42:50 +0000108
Reid Klecknerc66e7e92013-07-31 21:00:18 +0000109// Declare a template using a calling convention.
110template <class CharT> inline int __cdecl mystrlen(const CharT *str) {
111 int i;
112 for (i = 0; str[i]; i++) { }
113 return i;
114}
115extern int sse_strlen(const char *str);
116template <> inline int __cdecl mystrlen(const char *str) {
117 return sse_strlen(str);
118}
119void use_tmpl(const char *str, const int *ints) {
120 mystrlen(str);
121 mystrlen(ints);
122}
Reid Kleckneref072032013-08-27 23:08:25 +0000123
124struct MixedCCStaticOverload {
125 static void overloaded(int a);
126 static void __stdcall overloaded(short a);
127};
128
129void MixedCCStaticOverload::overloaded(int a) {}
130void MixedCCStaticOverload::overloaded(short a) {}
131
132// Friend function decls are cdecl by default, not thiscall. Friend method
133// decls should always be redeclarations, because the class cannot be
134// incomplete.
135struct FriendClass {
136 void friend_method() {}
137};
138void __stdcall friend_stdcall1() {}
139class MakeFriendDecls {
140 int x;
141 friend void FriendClass::friend_method();
142 friend void friend_default();
143 friend void friend_stdcall1();
144 friend void __stdcall friend_stdcall2();
145 friend void friend_stdcall3(); // expected-note {{previous declaration is here}}
146};
147void friend_default() {}
148void __stdcall friend_stdcall3() {} // expected-error {{function declared 'stdcall' here was previously declared without calling convention}}
149void __stdcall friend_stdcall2() {}
150
151// Test functions with multiple attributes.
152void __attribute__((noreturn)) __stdcall __attribute__((regparm(1))) multi_attribute(int x);
153void multi_attribute(int x) { __builtin_unreachable(); }
154
155
Stephen Hines176edba2014-12-01 14:53:08 -0800156// expected-error@+3 {{vectorcall and cdecl attributes are not compatible}}
Reid Kleckneref072032013-08-27 23:08:25 +0000157// expected-error@+2 {{stdcall and cdecl attributes are not compatible}}
158// expected-error@+1 {{fastcall and cdecl attributes are not compatible}}
Stephen Hines176edba2014-12-01 14:53:08 -0800159void __cdecl __cdecl __stdcall __cdecl __fastcall __vectorcall multi_cc(int x);
Reid Kleckner35bc0052013-09-10 01:04:45 +0000160
161template <typename T> void __stdcall StdcallTemplate(T) {}
162template <> void StdcallTemplate<int>(int) {}
163template <> void __stdcall StdcallTemplate<short>(short) {}
164
165// FIXME: Note the template, not the implicit instantiation.
166// expected-error@+2 {{function declared 'cdecl' here was previously declared 'stdcall}}
167// expected-note@+1 {{previous declaration is here}}
168template <> void __cdecl StdcallTemplate<long>(long) {}
169
170struct ExactlyInt {
171 template <typename T> static int cast_to_int(T) {
172 return T::this_is_not_an_int();
173 }
174};
175template <> inline int ExactlyInt::cast_to_int<int>(int x) { return x; }
Rafael Espindolacdf7cfc2013-11-18 20:05:33 +0000176
177namespace test2 {
178 class foo {
179 template <typename T> void bar(T v);
180 };
181 extern template void foo::bar(const void *);
182}
Rafael Espindolaf4966552013-11-18 22:40:04 +0000183
184namespace test3 {
185 struct foo {
186 typedef void bar();
187 };
188 bool zed(foo::bar *);
189 void bah() {}
190 void baz() { zed(bah); }
191}
Bill Wendling579d45f2013-11-20 06:45:19 +0000192
193namespace test4 {
194 class foo {
195 template <typename T> static void bar(T v);
196 };
197 extern template void foo::bar(const void *);
198}
Bill Wendling37c07bf2013-12-02 02:05:28 +0000199
200namespace test5 {
201 template <class T>
202 class valarray {
203 void bar();
204 };
205 extern template void valarray<int>::bar();
206}
Stephen Hines651f13c2014-04-23 16:59:28 -0700207
208namespace test6 {
209 struct foo {
210 int bar();
211 };
212 typedef int bar_t();
213 void zed(bar_t foo::*) {
214 }
215 void baz() {
216 zed(&foo::bar);
217 }
218}
219
220namespace test7 {
221 template <typename T>
222 struct S {
223 void f(T t) {
224 t = 42;
225 }
226 };
227 template<> void S<void*>::f(void*);
228 void g(S<void*> s, void* p) {
229 s.f(p);
230 }
231}
232
233namespace test8 {
234 template <typename T>
235 struct S {
236 void f(T t) { // expected-note {{previous declaration is here}}
237 t = 42; // expected-error {{assigning to 'void *' from incompatible type 'int'}}
238 }
239 };
240 template<> void __cdecl S<void*>::f(void*); // expected-error {{function declared 'cdecl' here was previously declared without calling convention}}
241 void g(S<void*> s, void* p) {
242 s.f(p); // expected-note {{in instantiation of member function 'test8::S<void *>::f' requested here}}
243 }
244}