blob: d8a597a8cc5b6689a03d0979ff272e594ee505c7 [file] [log] [blame]
Francois Pichetb2d899e2012-04-17 12:35:05 +00001// RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-extensions -fms-compatibility -fdelayed-template-parsing
Nick Lewycky141ecfe2010-10-12 16:46:35 +00002
3/* Microsoft attribute tests */
4[repeatable][source_annotation_attribute( Parameter|ReturnValue )]
5struct SA_Post{ SA_Post(); int attr; };
6
7[returnvalue:SA_Post( attr=1)]
8int foo1([SA_Post(attr=1)] void *param);
9
10namespace {
11 [returnvalue:SA_Post(attr=1)]
12 int foo2([SA_Post(attr=1)] void *param);
13}
14
15class T {
16 [returnvalue:SA_Post(attr=1)]
17 int foo3([SA_Post(attr=1)] void *param);
18};
19
20extern "C" {
21 [returnvalue:SA_Post(attr=1)]
22 int foo5([SA_Post(attr=1)] void *param);
23}
24
Francois Pichetdfaa5fb2011-01-31 04:54:32 +000025class class_attr {
26public:
27 class_attr([SA_Pre(Null=SA_No,NullTerminated=SA_Yes)] int a)
28 {
29 }
30};
31
32
Nick Lewycky141ecfe2010-10-12 16:46:35 +000033
Francois Pichet913b7bf2010-12-20 03:51:03 +000034void uuidof_test1()
35{
36 __uuidof(0); // expected-error {{you need to include <guiddef.h> before using the '__uuidof' operator}}
37}
38
39typedef struct _GUID
40{
41 unsigned long Data1;
42 unsigned short Data2;
43 unsigned short Data3;
44 unsigned char Data4[8];
45} GUID;
46
47struct __declspec(uuid(L"00000000-0000-0000-1234-000000000047")) uuid_attr_bad1 { };// expected-error {{'uuid' attribute requires parameter 1 to be a string}}
48struct __declspec(uuid(3)) uuid_attr_bad2 { };// expected-error {{'uuid' attribute requires parameter 1 to be a string}}
49struct __declspec(uuid("0000000-0000-0000-1234-0000500000047")) uuid_attr_bad3 { };// expected-error {{uuid attribute contains a malformed GUID}}
50struct __declspec(uuid("0000000-0000-0000-Z234-000000000047")) uuid_attr_bad4 { };// expected-error {{uuid attribute contains a malformed GUID}}
51struct __declspec(uuid("000000000000-0000-1234-000000000047")) uuid_attr_bad5 { };// expected-error {{uuid attribute contains a malformed GUID}}
52
53
54
55struct __declspec(uuid("000000A0-0000-0000-C000-000000000046"))
56struct_with_uuid { };
57struct struct_without_uuid { };
58
Francois Pichet6915c522010-12-27 01:32:00 +000059struct __declspec(uuid("000000A0-0000-0000-C000-000000000049"))
60struct_with_uuid2;
61
62struct
63struct_with_uuid2 {} ;
Francois Pichet913b7bf2010-12-20 03:51:03 +000064
65int uuid_sema_test()
66{
67 struct_with_uuid var_with_uuid[1];
68 struct_without_uuid var_without_uuid[1];
69
70 __uuidof(struct_with_uuid);
Francois Pichet6915c522010-12-27 01:32:00 +000071 __uuidof(struct_with_uuid2);
Francois Pichet913b7bf2010-12-20 03:51:03 +000072 __uuidof(struct_without_uuid); // expected-error {{cannot call operator __uuidof on a type with no GUID}}
73 __uuidof(struct_with_uuid*);
74 __uuidof(struct_without_uuid*); // expected-error {{cannot call operator __uuidof on a type with no GUID}}
75
76 __uuidof(var_with_uuid);
77 __uuidof(var_without_uuid);// expected-error {{cannot call operator __uuidof on a type with no GUID}}
78 __uuidof(var_with_uuid[1]);
79 __uuidof(var_without_uuid[1]);// expected-error {{cannot call operator __uuidof on a type with no GUID}}
80 __uuidof(&var_with_uuid[1]);
81 __uuidof(&var_without_uuid[1]);// expected-error {{cannot call operator __uuidof on a type with no GUID}}
82
83 __uuidof(0);
84 __uuidof(1);// expected-error {{cannot call operator __uuidof on a type with no GUID}}
85}
Francois Pichet6915c522010-12-27 01:32:00 +000086
87
88template <class T>
89void template_uuid()
90{
91 T expr;
92
93 __uuidof(T);
94 __uuidof(expr);
95}
Francois Pichetdbee3412011-01-18 05:04:39 +000096
97
Francois Picheta97d24f2011-04-28 04:39:50 +000098template <class T, const GUID* g = &__uuidof(T)>
99class COM_CLASS_TEMPLATE { };
100
101typedef COM_CLASS_TEMPLATE<struct_with_uuid, &__uuidof(struct_with_uuid)> COM_TYPE_1;
102typedef COM_CLASS_TEMPLATE<struct_with_uuid> COM_TYPE_2;
103
Francois Picheta343a412011-04-29 09:08:14 +0000104template <class T, const GUID& g>
105class COM_CLASS_TEMPLATE_REF { };
Francois Pichete275a182012-04-16 04:08:35 +0000106typedef COM_CLASS_TEMPLATE_REF<struct_with_uuid, __uuidof(struct_with_uuid)> COM_TYPE_REF;
Francois Picheta97d24f2011-04-28 04:39:50 +0000107
Francois Pichet20e3c9e2011-05-10 00:08:32 +0000108 struct late_defined_uuid;
109 template<typename T>
110 void test_late_defined_uuid() {
111 __uuidof(late_defined_uuid);
112 }
113 struct __declspec(uuid("000000A0-0000-0000-C000-000000000049")) late_defined_uuid;
114
Francois Pichetdbee3412011-01-18 05:04:39 +0000115
116class CtorCall {
117public:
118 CtorCall& operator=(const CtorCall& that);
119
120 int a;
121};
122
123CtorCall& CtorCall::operator=(const CtorCall& that)
124{
125 if (this != &that) {
126 this->CtorCall::~CtorCall();
127 this->CtorCall::CtorCall(that); // expected-warning {{explicit constructor calls are a Microsoft extension}}
128 }
129 return *this;
130}
Francois Pichet4147d302011-03-27 19:41:34 +0000131
132template <class A>
133class C1 {
134public:
135 template <int B>
136 class Iterator {
137 };
138};
139
140template<class T>
141class C2 {
142 typename C1<T>:: /*template*/ Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
143};
144
145template <class T>
Francois Pichet20e3c9e2011-05-10 00:08:32 +0000146void missing_template_keyword(){
Francois Pichet4147d302011-03-27 19:41:34 +0000147 typename C1<T>:: /*template*/ Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
148}
149
Francois Picheta5d318a2011-04-24 11:24:13 +0000150
151
152class AAAA { };
153
Richard Smith23756772012-05-14 22:43:34 +0000154template <typename T>
155class SimpleTemplate {};
156
Francois Picheta5d318a2011-04-24 11:24:13 +0000157template <class T>
158void redundant_typename() {
159 typename T t;// expected-warning {{expected a qualified name after 'typename'}}
160 typename AAAA a;// expected-warning {{expected a qualified name after 'typename'}}
Richard Smith23756772012-05-14 22:43:34 +0000161
Francois Picheta5d318a2011-04-24 11:24:13 +0000162 t = 3;
Richard Smith23756772012-05-14 22:43:34 +0000163
164 typedef typename T* pointerT;// expected-warning {{expected a qualified name after 'typename'}}
165 typedef typename SimpleTemplate<int> templateT;// expected-warning {{expected a qualified name after 'typename'}}
166
167 pointerT pT = &t;
168 *pT = 4;
169
170 int var;
171 int k = typename var;// expected-error {{expected a qualified name after 'typename'}}
Francois Picheta5d318a2011-04-24 11:24:13 +0000172}
173
Joao Matos17d35c32012-08-31 22:18:20 +0000174
175__interface MicrosoftInterface;
176__interface MicrosoftInterface {
177 void foo1() = 0;
178 virtual void foo2() = 0;
179};
180
181__interface MicrosoftDerivedInterface : public MicrosoftInterface {
182 void foo1();
183 void foo2() override;
184 void foo3();
185};
186
187void interface_test() {
188 MicrosoftInterface* a;
189 a->foo1();
190 MicrosoftDerivedInterface* b;
191 b->foo2();
192}
193
194__int64 x7 = __int64(0);
Francois Pichet1e862692011-05-06 20:48:22 +0000195
196
Francois Pichet563a6452011-05-25 10:19:49 +0000197namespace If_exists_test {
Francois Pichet1e862692011-05-06 20:48:22 +0000198
199class IF_EXISTS {
200private:
201 typedef int Type;
202};
203
204int __if_exists_test() {
Francois Pichet1e862692011-05-06 20:48:22 +0000205 int b=0;
Francois Pichet1e862692011-05-06 20:48:22 +0000206 __if_exists(IF_EXISTS::Type) {
207 b++;
208 b++;
209 }
Francois Pichet1e862692011-05-06 20:48:22 +0000210 __if_exists(IF_EXISTS::Type_not) {
211 this wont compile.
212 }
Francois Pichet1e862692011-05-06 20:48:22 +0000213 __if_not_exists(IF_EXISTS::Type) {
214 this wont compile.
215 }
Francois Pichet1e862692011-05-06 20:48:22 +0000216 __if_not_exists(IF_EXISTS::Type_not) {
217 b++;
218 b++;
219 }
Francois Pichetf9860382011-05-07 17:30:27 +0000220}
Francois Pichet1e862692011-05-06 20:48:22 +0000221
Francois Pichetf9860382011-05-07 17:30:27 +0000222
223__if_exists(IF_EXISTS::Type) {
224 int var23;
225}
226
227__if_exists(IF_EXISTS::Type_not) {
228 this wont compile.
229}
230
231__if_not_exists(IF_EXISTS::Type) {
232 this wont compile.
233}
234
235__if_not_exists(IF_EXISTS::Type_not) {
236 int var244;
Francois Pichet1e862692011-05-06 20:48:22 +0000237}
Francois Picheta23ae3f2011-05-07 17:47:38 +0000238
Francois Pichet9d24a8b2011-12-12 23:24:39 +0000239int __if_exists_init_list() {
240
Joao Matos17d35c32012-08-31 22:18:20 +0000241 int array1[] = {
242 0,
243 __if_exists(IF_EXISTS::Type) {2, }
244 3
245 };
Francois Pichet9d24a8b2011-12-12 23:24:39 +0000246
Joao Matos17d35c32012-08-31 22:18:20 +0000247 int array2[] = {
248 0,
249 __if_exists(IF_EXISTS::Type_not) { this wont compile }
250 3
251 };
Francois Pichet9d24a8b2011-12-12 23:24:39 +0000252
Joao Matos17d35c32012-08-31 22:18:20 +0000253 int array3[] = {
254 0,
255 __if_not_exists(IF_EXISTS::Type_not) {2, }
256 3
257 };
258
259 int array4[] = {
260 0,
261 __if_not_exists(IF_EXISTS::Type) { this wont compile }
262 3
263 };
Francois Pichet9d24a8b2011-12-12 23:24:39 +0000264
265}
266
267
Francois Pichet563a6452011-05-25 10:19:49 +0000268class IF_EXISTS_CLASS_TEST {
269 __if_exists(IF_EXISTS::Type) {
270 // __if_exists, __if_not_exists can nest
271 __if_not_exists(IF_EXISTS::Type_not) {
272 int var123;
273 }
274 int var23;
275 }
276
277 __if_exists(IF_EXISTS::Type_not) {
278 this wont compile.
279 }
280
281 __if_not_exists(IF_EXISTS::Type) {
282 this wont compile.
283 }
284
285 __if_not_exists(IF_EXISTS::Type_not) {
286 int var244;
287 }
288};
289
290}
291
292
Francois Picheta23ae3f2011-05-07 17:47:38 +0000293int __identifier(generic) = 3;
294
Francois Pichet6a247472011-05-11 02:14:46 +0000295class inline_definition_pure_spec {
296 virtual int f() = 0 { return 0; }// expected-warning {{function definition with pure-specifier is a Microsoft extension}}
297 virtual int f2() = 0;
298};
299
Francois Pichet20e3c9e2011-05-10 00:08:32 +0000300
301int main () {
302 // Necessary to force instantiation in -fdelayed-template-parsing mode.
303 test_late_defined_uuid<int>();
304 redundant_typename<int>();
305 missing_template_keyword<int>();
306}
307
John McCall6c202222012-05-22 21:28:07 +0000308namespace access_protected_PTM {
309 class A {
310 protected:
311 void f(); // expected-note {{must name member using the type of the current context 'access_protected_PTM::B'}}
312 };
Francois Pichetb2d899e2012-04-17 12:35:05 +0000313
John McCall6c202222012-05-22 21:28:07 +0000314 class B : public A{
315 public:
316 void test_access();
317 static void test_access_static();
318 };
Francois Pichetb2d899e2012-04-17 12:35:05 +0000319
John McCall6c202222012-05-22 21:28:07 +0000320 void B::test_access() {
321 &A::f; // expected-error {{'f' is a protected member of 'access_protected_PTM::A'}}
322 }
323
324 void B::test_access_static() {
325 &A::f;
326 }
327}
John McCallc052dbb2012-05-22 21:28:12 +0000328
329namespace Inheritance {
330 class __single_inheritance A;
331 class __multiple_inheritance B;
332 class __virtual_inheritance C;
333}
John McCall76da55d2013-04-16 07:28:30 +0000334
335struct StructWithProperty {
336 __declspec(property) int V0; // expected-error {{expected '(' after 'property'}}
337 __declspec(property()) int V1; // expected-error {{property does not specify a getter or a putter}}
338 __declspec(property(set)) int V2; // expected-error {{putter for property must be specified as 'put', not 'set'}} expected-error {{expected '=' after 'set'}}
339 __declspec(property(ptu)) int V3; // expected-error {{missing 'get=' or 'put='}}
340 __declspec(property(ptu=PutV)) int V4; // expected-error {{expected 'get' or 'put' in property declaration}}
341 __declspec(property(get)) int V5; // expected-error {{expected '=' after 'get'}}
342 __declspec(property(get&)) int V6; // expected-error {{expected '=' after 'get'}}
343 __declspec(property(get=)) int V7; // expected-error {{expected name of accessor method}}
344 __declspec(property(get=GetV)) int V8; // no-warning
345 __declspec(property(get=GetV=)) int V9; // expected-error {{expected ',' or ')' at end of property accessor list}}
346 __declspec(property(get=GetV,)) int V10; // expected-error {{expected 'get' or 'put' in property declaration}}
347 __declspec(property(get=GetV,put=SetV)) int V11; // no-warning
348 __declspec(property(get=GetV,put=SetV,get=GetV)) int V12; // expected-error {{property declaration specifies 'get' accessor twice}}
349
350 int GetV() { return 123; }
351 void SetV(int v) {}
352};
353void TestProperty() {
354 StructWithProperty sp;
355 sp.V8;
356 sp.V8 = 0; // expected-error {{no setter defined for property 'V8'}}
357 int i = sp.V11;
358 sp.V11 = i++;
359 sp.V11 += 8;
360 sp.V11++;
361 ++sp.V11;
362}