blob: b6f7b2d4ab507e7c6c9aecb5e6d895a973d608f8 [file] [log] [blame]
Timur Iskhodzhanovf2afe632013-02-22 12:42:50 +00001// RUN: %clang_cc1 -triple i686-pc-win32 -cxx-abi microsoft -fms-extensions -verify %s
2
Reid Kleckner78af0702013-08-27 23:08:25 +00003typedef void void_fun_t();
4typedef void __cdecl cdecl_fun_t();
5
Timur Iskhodzhanovf2afe632013-02-22 12:42:50 +00006// Pointers to free functions
Reid Kleckner78af0702013-08-27 23:08:25 +00007void free_func_default(); // expected-note 2 {{previous declaration is here}}
8void __cdecl free_func_cdecl(); // expected-note 2 {{previous declaration is here}}
9void __stdcall free_func_stdcall(); // expected-note 2 {{previous declaration is here}}
Timur Iskhodzhanovf2afe632013-02-22 12:42:50 +000010void __fastcall free_func_fastcall(); // expected-note 2 {{previous declaration is here}}
11
Reid Kleckner78af0702013-08-27 23:08:25 +000012void __cdecl free_func_default();
Timur Iskhodzhanovf2afe632013-02-22 12:42:50 +000013void __stdcall free_func_default(); // expected-error {{function declared 'stdcall' here was previously declared without calling convention}}
14void __fastcall free_func_default(); // expected-error {{function declared 'fastcall' here was previously declared without calling convention}}
15
Reid Kleckner78af0702013-08-27 23:08:25 +000016void free_func_cdecl();
Timur Iskhodzhanovf2afe632013-02-22 12:42:50 +000017void __stdcall free_func_cdecl(); // expected-error {{function declared 'stdcall' here was previously declared 'cdecl'}}
18void __fastcall free_func_cdecl(); // expected-error {{function declared 'fastcall' here was previously declared 'cdecl'}}
19
Reid Kleckner78af0702013-08-27 23:08:25 +000020void free_func_stdcall();
Timur Iskhodzhanovf2afe632013-02-22 12:42:50 +000021void __cdecl free_func_stdcall(); // expected-error {{function declared 'cdecl' here was previously declared 'stdcall'}}
Timur Iskhodzhanovf2afe632013-02-22 12:42:50 +000022void __fastcall free_func_stdcall(); // expected-error {{function declared 'fastcall' here was previously declared 'stdcall'}}
23
24void __cdecl free_func_fastcall(); // expected-error {{function declared 'cdecl' here was previously declared 'fastcall'}}
25void __stdcall free_func_fastcall(); // expected-error {{function declared 'stdcall' here was previously declared 'fastcall'}}
26void free_func_fastcall();
27
28// Overloaded functions may have different calling conventions
29void __fastcall free_func_default(int);
30void __cdecl free_func_default(int *);
31
32void __thiscall free_func_cdecl(char *);
33void __cdecl free_func_cdecl(double);
34
Reid Klecknera09e44c2013-07-31 21:00:18 +000035typedef void void_fun_t();
36typedef void __cdecl cdecl_fun_t();
Timur Iskhodzhanovf2afe632013-02-22 12:42:50 +000037
38// Pointers to member functions
39struct S {
40 void member_default1(); // expected-note {{previous declaration is here}}
41 void member_default2();
42 void __cdecl member_cdecl1();
43 void __cdecl member_cdecl2(); // expected-note {{previous declaration is here}}
44 void __thiscall member_thiscall1();
45 void __thiscall member_thiscall2(); // expected-note {{previous declaration is here}}
Reid Klecknera09e44c2013-07-31 21:00:18 +000046
Reid Kleckner78af0702013-08-27 23:08:25 +000047 // Typedefs carrying the __cdecl convention are adjusted to __thiscall.
48 void_fun_t member_typedef_default; // expected-note {{previous declaration is here}}
49 cdecl_fun_t member_typedef_cdecl1; // expected-note {{previous declaration is here}}
50 cdecl_fun_t __cdecl member_typedef_cdecl2;
51 void_fun_t __stdcall member_typedef_stdcall;
Reid Klecknera09e44c2013-07-31 21:00:18 +000052
Timur Iskhodzhanovf2afe632013-02-22 12:42:50 +000053 // Static member functions can't be __thiscall
54 static void static_member_default1();
Reid Kleckner78af0702013-08-27 23:08:25 +000055 static void static_member_default2();
56 static void static_member_default3(); // expected-note {{previous declaration is here}}
Timur Iskhodzhanovf2afe632013-02-22 12:42:50 +000057 static void __cdecl static_member_cdecl1();
58 static void __cdecl static_member_cdecl2(); // expected-note {{previous declaration is here}}
59 static void __stdcall static_member_stdcall1();
60 static void __stdcall static_member_stdcall2();
61
62 // Variadic functions can't be other than default or __cdecl
63 void member_variadic_default(int x, ...);
64 void __cdecl member_variadic_cdecl(int x, ...);
65
66 static void static_member_variadic_default(int x, ...);
67 static void __cdecl static_member_variadic_cdecl(int x, ...);
68};
69
70void __cdecl S::member_default1() {} // expected-error {{function declared 'cdecl' here was previously declared without calling convention}}
71void __thiscall S::member_default2() {}
72
Reid Kleckner78af0702013-08-27 23:08:25 +000073void __cdecl S::member_typedef_default() {} // expected-error {{function declared 'cdecl' here was previously declared without calling convention}}
74void __cdecl S::member_typedef_cdecl1() {} // expected-error {{function declared 'cdecl' here was previously declared without calling convention}}
75void __cdecl S::member_typedef_cdecl2() {}
Reid Klecknera09e44c2013-07-31 21:00:18 +000076void __stdcall S::member_typedef_stdcall() {}
77
Timur Iskhodzhanovf2afe632013-02-22 12:42:50 +000078void S::member_cdecl1() {}
79void __thiscall S::member_cdecl2() {} // expected-error {{function declared 'thiscall' here was previously declared 'cdecl'}}
80
81void S::member_thiscall1() {}
82void __cdecl S::member_thiscall2() {} // expected-error {{function declared 'cdecl' here was previously declared 'thiscall'}}
83
Reid Kleckner78af0702013-08-27 23:08:25 +000084void S::static_member_default1() {}
85void __cdecl S::static_member_default2() {}
86void __stdcall S::static_member_default3() {} // expected-error {{function declared 'stdcall' here was previously declared without calling convention}}
Timur Iskhodzhanovf2afe632013-02-22 12:42:50 +000087
88void S::static_member_cdecl1() {}
89void __stdcall S::static_member_cdecl2() {} // expected-error {{function declared 'stdcall' here was previously declared 'cdecl'}}
90
Reid Kleckner78af0702013-08-27 23:08:25 +000091void __cdecl S::member_variadic_default(int x, ...) { (void)x; }
92void S::member_variadic_cdecl(int x, ...) { (void)x; }
Timur Iskhodzhanovf2afe632013-02-22 12:42:50 +000093
Reid Kleckner78af0702013-08-27 23:08:25 +000094void __cdecl S::static_member_variadic_default(int x, ...) { (void)x; }
95void S::static_member_variadic_cdecl(int x, ...) { (void)x; }
Timur Iskhodzhanovf2afe632013-02-22 12:42:50 +000096
Reid Klecknera09e44c2013-07-31 21:00:18 +000097// Declare a template using a calling convention.
98template <class CharT> inline int __cdecl mystrlen(const CharT *str) {
99 int i;
100 for (i = 0; str[i]; i++) { }
101 return i;
102}
103extern int sse_strlen(const char *str);
104template <> inline int __cdecl mystrlen(const char *str) {
105 return sse_strlen(str);
106}
107void use_tmpl(const char *str, const int *ints) {
108 mystrlen(str);
109 mystrlen(ints);
110}
Reid Kleckner78af0702013-08-27 23:08:25 +0000111
112struct MixedCCStaticOverload {
113 static void overloaded(int a);
114 static void __stdcall overloaded(short a);
115};
116
117void MixedCCStaticOverload::overloaded(int a) {}
118void MixedCCStaticOverload::overloaded(short a) {}
119
120// Friend function decls are cdecl by default, not thiscall. Friend method
121// decls should always be redeclarations, because the class cannot be
122// incomplete.
123struct FriendClass {
124 void friend_method() {}
125};
126void __stdcall friend_stdcall1() {}
127class MakeFriendDecls {
128 int x;
129 friend void FriendClass::friend_method();
130 friend void friend_default();
131 friend void friend_stdcall1();
132 friend void __stdcall friend_stdcall2();
133 friend void friend_stdcall3(); // expected-note {{previous declaration is here}}
134};
135void friend_default() {}
136void __stdcall friend_stdcall3() {} // expected-error {{function declared 'stdcall' here was previously declared without calling convention}}
137void __stdcall friend_stdcall2() {}
138
139// Test functions with multiple attributes.
140void __attribute__((noreturn)) __stdcall __attribute__((regparm(1))) multi_attribute(int x);
141void multi_attribute(int x) { __builtin_unreachable(); }
142
143
144// expected-error@+2 {{stdcall and cdecl attributes are not compatible}}
145// expected-error@+1 {{fastcall and cdecl attributes are not compatible}}
146void __cdecl __cdecl __stdcall __cdecl __fastcall multi_cc(int x);
Reid Kleckner76808052013-09-10 01:04:45 +0000147
148template <typename T> void __stdcall StdcallTemplate(T) {}
149template <> void StdcallTemplate<int>(int) {}
150template <> void __stdcall StdcallTemplate<short>(short) {}
151
152// FIXME: Note the template, not the implicit instantiation.
153// expected-error@+2 {{function declared 'cdecl' here was previously declared 'stdcall}}
154// expected-note@+1 {{previous declaration is here}}
155template <> void __cdecl StdcallTemplate<long>(long) {}
156
157struct ExactlyInt {
158 template <typename T> static int cast_to_int(T) {
159 return T::this_is_not_an_int();
160 }
161};
162template <> inline int ExactlyInt::cast_to_int<int>(int x) { return x; }