blob: c2d749a288fc84e5f110940639822da74b5217ff [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
Aaron Ballman3cd6feb2013-07-30 01:31:03 +00007[returnvalue:SA_Post( attr=1)]
Nick Lewycky141ecfe2010-10-12 16:46:35 +00008int foo1([SA_Post(attr=1)] void *param);
9
10namespace {
Aaron Ballman3cd6feb2013-07-30 01:31:03 +000011 [returnvalue:SA_Post(attr=1)]
Nick Lewycky141ecfe2010-10-12 16:46:35 +000012 int foo2([SA_Post(attr=1)] void *param);
13}
14
15class T {
Aaron Ballman3cd6feb2013-07-30 01:31:03 +000016 [returnvalue:SA_Post(attr=1)]
Nick Lewycky141ecfe2010-10-12 16:46:35 +000017 int foo3([SA_Post(attr=1)] void *param);
18};
19
20extern "C" {
Aaron Ballman3cd6feb2013-07-30 01:31:03 +000021 [returnvalue:SA_Post(attr=1)]
Nick Lewycky141ecfe2010-10-12 16:46:35 +000022 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()
Aaron Ballman3cd6feb2013-07-30 01:31:03 +000035{
Francois Pichet913b7bf2010-12-20 03:51:03 +000036 __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
Aaron Ballman3cd6feb2013-07-30 01:31:03 +000047struct __declspec(uuid(L"00000000-0000-0000-1234-000000000047")) uuid_attr_bad1 { };// expected-error {{'uuid' attribute requires a string}}
48struct __declspec(uuid(3)) uuid_attr_bad2 { };// expected-error {{'uuid' attribute requires a string}}
Francois Pichet913b7bf2010-12-20 03:51:03 +000049struct __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
Aaron Ballman3cd6feb2013-07-30 01:31:03 +000062struct
Francois Pichet6915c522010-12-27 01:32:00 +000063struct_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;
Aaron Ballman3cd6feb2013-07-30 01:31:03 +000092
Francois Pichet6915c522010-12-27 01:32:00 +000093 __uuidof(T);
94 __uuidof(expr);
95}
Francois Pichetdbee3412011-01-18 05:04:39 +000096
97
David Majnemerd1282ec2013-08-23 05:39:39 +000098template <class T, const GUID* g = &__uuidof(T)> // expected-note {{template parameter is declared here}}
Francois Picheta97d24f2011-04-28 04:39:50 +000099class COM_CLASS_TEMPLATE { };
100
David Majnemerd1282ec2013-08-23 05:39:39 +0000101typedef COM_CLASS_TEMPLATE<struct_with_uuid, &*&__uuidof(struct_with_uuid)> COM_TYPE_1; // expected-warning {{non-type template argument containing a dereference operation is a Microsoft extension}}
Francois Picheta97d24f2011-04-28 04:39:50 +0000102typedef 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
David Majnemerd1282ec2013-08-23 05:39:39 +0000115COM_CLASS_TEMPLATE_REF<int, __uuidof(struct_with_uuid)> good_template_arg;
116
117COM_CLASS_TEMPLATE<int, __uuidof(struct_with_uuid)> bad_template_arg; // expected-error {{non-type template argument of type 'const _GUID' is not a constant expression}}
Francois Pichetdbee3412011-01-18 05:04:39 +0000118
Aaron Ballman3cd6feb2013-07-30 01:31:03 +0000119class CtorCall {
Francois Pichetdbee3412011-01-18 05:04:39 +0000120public:
121 CtorCall& operator=(const CtorCall& that);
122
123 int a;
124};
125
126CtorCall& CtorCall::operator=(const CtorCall& that)
127{
128 if (this != &that) {
129 this->CtorCall::~CtorCall();
130 this->CtorCall::CtorCall(that); // expected-warning {{explicit constructor calls are a Microsoft extension}}
131 }
132 return *this;
133}
Francois Pichet4147d302011-03-27 19:41:34 +0000134
135template <class A>
136class C1 {
137public:
138 template <int B>
139 class Iterator {
140 };
141};
Aaron Ballman3cd6feb2013-07-30 01:31:03 +0000142
Francois Pichet4147d302011-03-27 19:41:34 +0000143template<class T>
144class C2 {
145 typename C1<T>:: /*template*/ Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
146};
147
148template <class T>
Francois Pichet20e3c9e2011-05-10 00:08:32 +0000149void missing_template_keyword(){
Francois Pichet4147d302011-03-27 19:41:34 +0000150 typename C1<T>:: /*template*/ Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
151}
152
Francois Picheta5d318a2011-04-24 11:24:13 +0000153
154
David Majnemer67ac9982013-09-03 22:36:22 +0000155class AAAA {
156 typedef int D;
157};
Francois Picheta5d318a2011-04-24 11:24:13 +0000158
Richard Smith23756772012-05-14 22:43:34 +0000159template <typename T>
160class SimpleTemplate {};
161
Francois Picheta5d318a2011-04-24 11:24:13 +0000162template <class T>
163void redundant_typename() {
164 typename T t;// expected-warning {{expected a qualified name after 'typename'}}
165 typename AAAA a;// expected-warning {{expected a qualified name after 'typename'}}
Richard Smith23756772012-05-14 22:43:34 +0000166
Francois Picheta5d318a2011-04-24 11:24:13 +0000167 t = 3;
Aaron Ballman3cd6feb2013-07-30 01:31:03 +0000168
Richard Smith23756772012-05-14 22:43:34 +0000169 typedef typename T* pointerT;// expected-warning {{expected a qualified name after 'typename'}}
170 typedef typename SimpleTemplate<int> templateT;// expected-warning {{expected a qualified name after 'typename'}}
171
172 pointerT pT = &t;
173 *pT = 4;
174
175 int var;
176 int k = typename var;// expected-error {{expected a qualified name after 'typename'}}
Francois Picheta5d318a2011-04-24 11:24:13 +0000177}
178
David Majnemer67ac9982013-09-03 22:36:22 +0000179template <typename T>
180struct TypenameWrongPlace {
181 typename typedef T::D D;// expected-warning {{expected a qualified name after 'typename'}}
182};
183
184extern TypenameWrongPlace<AAAA> PR16925;
Joao Matos17d35c32012-08-31 22:18:20 +0000185
186__interface MicrosoftInterface;
187__interface MicrosoftInterface {
188 void foo1() = 0;
189 virtual void foo2() = 0;
190};
191
192__interface MicrosoftDerivedInterface : public MicrosoftInterface {
193 void foo1();
194 void foo2() override;
195 void foo3();
196};
197
198void interface_test() {
199 MicrosoftInterface* a;
200 a->foo1();
201 MicrosoftDerivedInterface* b;
202 b->foo2();
203}
204
205__int64 x7 = __int64(0);
Francois Pichet1e862692011-05-06 20:48:22 +0000206
207
Francois Pichet563a6452011-05-25 10:19:49 +0000208namespace If_exists_test {
Francois Pichet1e862692011-05-06 20:48:22 +0000209
210class IF_EXISTS {
211private:
212 typedef int Type;
213};
214
215int __if_exists_test() {
Francois Pichet1e862692011-05-06 20:48:22 +0000216 int b=0;
Francois Pichet1e862692011-05-06 20:48:22 +0000217 __if_exists(IF_EXISTS::Type) {
218 b++;
219 b++;
220 }
Francois Pichet1e862692011-05-06 20:48:22 +0000221 __if_exists(IF_EXISTS::Type_not) {
222 this wont compile.
223 }
Francois Pichet1e862692011-05-06 20:48:22 +0000224 __if_not_exists(IF_EXISTS::Type) {
225 this wont compile.
226 }
Francois Pichet1e862692011-05-06 20:48:22 +0000227 __if_not_exists(IF_EXISTS::Type_not) {
228 b++;
229 b++;
230 }
Francois Pichetf9860382011-05-07 17:30:27 +0000231}
Francois Pichet1e862692011-05-06 20:48:22 +0000232
Francois Pichetf9860382011-05-07 17:30:27 +0000233
234__if_exists(IF_EXISTS::Type) {
235 int var23;
236}
237
238__if_exists(IF_EXISTS::Type_not) {
239 this wont compile.
240}
241
242__if_not_exists(IF_EXISTS::Type) {
243 this wont compile.
244}
245
246__if_not_exists(IF_EXISTS::Type_not) {
247 int var244;
Francois Pichet1e862692011-05-06 20:48:22 +0000248}
Francois Picheta23ae3f2011-05-07 17:47:38 +0000249
Francois Pichet9d24a8b2011-12-12 23:24:39 +0000250int __if_exists_init_list() {
251
Joao Matos17d35c32012-08-31 22:18:20 +0000252 int array1[] = {
Aaron Ballman3cd6feb2013-07-30 01:31:03 +0000253 0,
Joao Matos17d35c32012-08-31 22:18:20 +0000254 __if_exists(IF_EXISTS::Type) {2, }
255 3
256 };
Francois Pichet9d24a8b2011-12-12 23:24:39 +0000257
Joao Matos17d35c32012-08-31 22:18:20 +0000258 int array2[] = {
Aaron Ballman3cd6feb2013-07-30 01:31:03 +0000259 0,
Joao Matos17d35c32012-08-31 22:18:20 +0000260 __if_exists(IF_EXISTS::Type_not) { this wont compile }
261 3
262 };
Francois Pichet9d24a8b2011-12-12 23:24:39 +0000263
Joao Matos17d35c32012-08-31 22:18:20 +0000264 int array3[] = {
Aaron Ballman3cd6feb2013-07-30 01:31:03 +0000265 0,
Joao Matos17d35c32012-08-31 22:18:20 +0000266 __if_not_exists(IF_EXISTS::Type_not) {2, }
267 3
268 };
269
270 int array4[] = {
Aaron Ballman3cd6feb2013-07-30 01:31:03 +0000271 0,
Joao Matos17d35c32012-08-31 22:18:20 +0000272 __if_not_exists(IF_EXISTS::Type) { this wont compile }
273 3
274 };
Francois Pichet9d24a8b2011-12-12 23:24:39 +0000275
276}
277
278
Francois Pichet563a6452011-05-25 10:19:49 +0000279class IF_EXISTS_CLASS_TEST {
280 __if_exists(IF_EXISTS::Type) {
281 // __if_exists, __if_not_exists can nest
282 __if_not_exists(IF_EXISTS::Type_not) {
283 int var123;
284 }
285 int var23;
286 }
287
288 __if_exists(IF_EXISTS::Type_not) {
289 this wont compile.
290 }
291
292 __if_not_exists(IF_EXISTS::Type) {
293 this wont compile.
294 }
295
296 __if_not_exists(IF_EXISTS::Type_not) {
297 int var244;
298 }
299};
300
301}
302
303
Francois Picheta23ae3f2011-05-07 17:47:38 +0000304int __identifier(generic) = 3;
305
Francois Pichet6a247472011-05-11 02:14:46 +0000306class inline_definition_pure_spec {
307 virtual int f() = 0 { return 0; }// expected-warning {{function definition with pure-specifier is a Microsoft extension}}
308 virtual int f2() = 0;
309};
310
Francois Pichet20e3c9e2011-05-10 00:08:32 +0000311
312int main () {
313 // Necessary to force instantiation in -fdelayed-template-parsing mode.
Aaron Ballman3cd6feb2013-07-30 01:31:03 +0000314 test_late_defined_uuid<int>();
Francois Pichet20e3c9e2011-05-10 00:08:32 +0000315 redundant_typename<int>();
316 missing_template_keyword<int>();
317}
318
John McCall6c202222012-05-22 21:28:07 +0000319namespace access_protected_PTM {
320 class A {
321 protected:
322 void f(); // expected-note {{must name member using the type of the current context 'access_protected_PTM::B'}}
323 };
Francois Pichetb2d899e2012-04-17 12:35:05 +0000324
John McCall6c202222012-05-22 21:28:07 +0000325 class B : public A{
326 public:
327 void test_access();
328 static void test_access_static();
329 };
Francois Pichetb2d899e2012-04-17 12:35:05 +0000330
John McCall6c202222012-05-22 21:28:07 +0000331 void B::test_access() {
332 &A::f; // expected-error {{'f' is a protected member of 'access_protected_PTM::A'}}
333 }
334
335 void B::test_access_static() {
336 &A::f;
337 }
338}
John McCallc052dbb2012-05-22 21:28:12 +0000339
340namespace Inheritance {
341 class __single_inheritance A;
342 class __multiple_inheritance B;
343 class __virtual_inheritance C;
344}
John McCall76da55d2013-04-16 07:28:30 +0000345
346struct StructWithProperty {
347 __declspec(property) int V0; // expected-error {{expected '(' after 'property'}}
348 __declspec(property()) int V1; // expected-error {{property does not specify a getter or a putter}}
349 __declspec(property(set)) int V2; // expected-error {{putter for property must be specified as 'put', not 'set'}} expected-error {{expected '=' after 'set'}}
350 __declspec(property(ptu)) int V3; // expected-error {{missing 'get=' or 'put='}}
351 __declspec(property(ptu=PutV)) int V4; // expected-error {{expected 'get' or 'put' in property declaration}}
352 __declspec(property(get)) int V5; // expected-error {{expected '=' after 'get'}}
353 __declspec(property(get&)) int V6; // expected-error {{expected '=' after 'get'}}
354 __declspec(property(get=)) int V7; // expected-error {{expected name of accessor method}}
355 __declspec(property(get=GetV)) int V8; // no-warning
356 __declspec(property(get=GetV=)) int V9; // expected-error {{expected ',' or ')' at end of property accessor list}}
357 __declspec(property(get=GetV,)) int V10; // expected-error {{expected 'get' or 'put' in property declaration}}
358 __declspec(property(get=GetV,put=SetV)) int V11; // no-warning
359 __declspec(property(get=GetV,put=SetV,get=GetV)) int V12; // expected-error {{property declaration specifies 'get' accessor twice}}
360
361 int GetV() { return 123; }
362 void SetV(int v) {}
363};
364void TestProperty() {
365 StructWithProperty sp;
366 sp.V8;
367 sp.V8 = 0; // expected-error {{no setter defined for property 'V8'}}
368 int i = sp.V11;
369 sp.V11 = i++;
370 sp.V11 += 8;
371 sp.V11++;
372 ++sp.V11;
373}