1 // RUN: %clang_cc1 %s -triple i386-mingw32 -std=c++14 -fsyntax-only -Wno-unused-getter-return-value -Wno-unused-value -Wmicrosoft -verify -fms-extensions -fms-compatibility -fdelayed-template-parsing
3 /* Microsoft attribute tests */
4 [repeatable][source_annotation_attribute( Parameter|ReturnValue )]
5 struct SA_Post{ SA_Post(); int attr; };
7 [returnvalue:SA_Post( attr=1)]
8 int foo1([SA_Post(attr=1)] void *param);
11 [returnvalue:SA_Post(attr=1)]
12 int foo2([SA_Post(attr=1)] void *param);
16 [returnvalue:SA_Post(attr=1)]
17 int foo3([SA_Post(attr=1)] void *param);
21 [returnvalue:SA_Post(attr=1)]
22 int foo5([SA_Post(attr=1)] void *param);
27 class_attr([SA_Pre(Null=SA_No,NullTerminated=SA_Yes)] int a)
36 __uuidof(0); // expected-error {{you need to include <guiddef.h> before using the '__uuidof' operator}}
44 unsigned char Data4[8];
47 struct __declspec(uuid(L"00000000-0000-0000-1234-000000000047")) uuid_attr_bad1 { };// expected-error {{'uuid' attribute requires a string}}
48 struct __declspec(uuid(3)) uuid_attr_bad2 { };// expected-error {{'uuid' attribute requires a string}}
49 struct __declspec(uuid("0000000-0000-0000-1234-0000500000047")) uuid_attr_bad3 { };// expected-error {{uuid attribute contains a malformed GUID}}
50 struct __declspec(uuid("0000000-0000-0000-Z234-000000000047")) uuid_attr_bad4 { };// expected-error {{uuid attribute contains a malformed GUID}}
51 struct __declspec(uuid("000000000000-0000-1234-000000000047")) uuid_attr_bad5 { };// expected-error {{uuid attribute contains a malformed GUID}}
53 __declspec(uuid("000000A0-0000-0000-C000-000000000046")) int i; // expected-warning {{'uuid' attribute only applies to classes}}
55 struct __declspec(uuid("000000A0-0000-0000-C000-000000000046"))
57 struct struct_without_uuid { };
59 struct __declspec(uuid("000000A0-0000-0000-C000-000000000049"))
63 struct_with_uuid2 {} ;
67 struct_with_uuid var_with_uuid[1];
68 struct_without_uuid var_without_uuid[1];
70 __uuidof(struct_with_uuid);
71 __uuidof(struct_with_uuid2);
72 __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 __uuidof(struct_with_uuid[1]);
76 __uuidof(struct_with_uuid*[1]); // expected-error {{cannot call operator __uuidof on a type with no GUID}}
77 __uuidof(const struct_with_uuid[1][1]);
78 __uuidof(const struct_with_uuid*[1][1]); // expected-error {{cannot call operator __uuidof on a type with no GUID}}
80 __uuidof(var_with_uuid);
81 __uuidof(var_without_uuid);// expected-error {{cannot call operator __uuidof on a type with no GUID}}
82 __uuidof(var_with_uuid[1]);
83 __uuidof(var_without_uuid[1]);// expected-error {{cannot call operator __uuidof on a type with no GUID}}
84 __uuidof(&var_with_uuid[1]);
85 __uuidof(&var_without_uuid[1]);// expected-error {{cannot call operator __uuidof on a type with no GUID}}
88 __uuidof(1);// expected-error {{cannot call operator __uuidof on a type with no GUID}}
102 template <class T, const GUID* g = &__uuidof(T)> // expected-note {{template parameter is declared here}}
103 class COM_CLASS_TEMPLATE { };
105 typedef 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}}
106 typedef COM_CLASS_TEMPLATE<struct_with_uuid> COM_TYPE_2;
108 template <class T, const GUID& g>
109 class COM_CLASS_TEMPLATE_REF { };
110 typedef COM_CLASS_TEMPLATE_REF<struct_with_uuid, __uuidof(struct_with_uuid)> COM_TYPE_REF;
112 struct late_defined_uuid;
114 void test_late_defined_uuid() {
115 __uuidof(late_defined_uuid);
117 struct __declspec(uuid("000000A0-0000-0000-C000-000000000049")) late_defined_uuid;
119 COM_CLASS_TEMPLATE_REF<int, __uuidof(struct_with_uuid)> good_template_arg;
121 COM_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}}
124 struct __declspec(uuid("{12345678-1234-1234-1234-1234567890aB}")) uuid;
125 struct __declspec(uuid("{12345678-1234-1234-1234-1234567890aB}")) uuid2;
127 template <typename T, typename T2>
132 struct inher : public thing<empty, uuid2> {};
134 struct __declspec(uuid("{12345678-1234-1234-1234-1234567890aB}")) uuid;
135 const struct _GUID *w = &__uuidof(inher); // expected-error{{cannot call operator __uuidof on a type with no GUID}}
136 const struct _GUID *x = &__uuidof(thing<uuid, inher>);
137 const struct _GUID *y = &__uuidof(thing<uuid2, uuid>); // expected-error{{cannot call operator __uuidof on a type with multiple GUIDs}}
138 thing<uuid2, uuid> thing_obj = thing<uuid2, uuid>();
139 const struct _GUID *z = &__uuidof(thing_obj); // expected-error{{cannot call operator __uuidof on a type with multiple GUIDs}}
144 CtorCall& operator=(const CtorCall& that);
149 CtorCall& CtorCall::operator=(const CtorCall& that)
152 this->CtorCall::~CtorCall();
153 this->CtorCall::CtorCall(that); // expected-warning {{explicit constructor calls are a Microsoft extension}}
168 typename C1<T>:: /*template*/ Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
172 void missing_template_keyword(){
173 typename C1<T>:: /*template*/ Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
182 template <typename T>
183 class SimpleTemplate {};
186 void redundant_typename() {
187 typename T t;// expected-warning {{expected a qualified name after 'typename'}}
188 typename AAAA a;// expected-warning {{expected a qualified name after 'typename'}}
192 typedef typename T* pointerT;// expected-warning {{expected a qualified name after 'typename'}}
193 typedef typename SimpleTemplate<int> templateT;// expected-warning {{expected a qualified name after 'typename'}}
199 int k = typename var;// expected-error {{expected a qualified name after 'typename'}}
202 template <typename T>
203 struct TypenameWrongPlace {
204 typename typedef T::D D;// expected-warning {{expected a qualified name after 'typename'}}
207 extern TypenameWrongPlace<AAAA> PR16925;
209 __interface MicrosoftInterface;
210 __interface MicrosoftInterface {
211 void foo1() = 0; // expected-note {{overridden virtual function is here}}
212 virtual void foo2() = 0;
215 __interface MicrosoftDerivedInterface : public MicrosoftInterface {
216 void foo1(); // expected-warning {{'foo1' overrides a member function but is not marked 'override'}}
217 void foo2() override;
221 void interface_test() {
222 MicrosoftInterface* a;
224 MicrosoftDerivedInterface* b;
228 __int64 x7 = __int64(0);
229 _int64 x8 = _int64(0);
230 static_assert(sizeof(_int64) == 8, "");
231 static_assert(sizeof(_int32) == 4, "");
232 static_assert(sizeof(_int16) == 2, "");
233 static_assert(sizeof(_int8) == 1, "");
235 int __identifier(generic) = 3;
236 int __identifier(int) = 4;
237 struct __identifier(class) { __identifier(class) *__identifier(for); };
238 __identifier(class) __identifier(struct) = { &__identifier(struct) };
240 int __identifier for; // expected-error {{missing '(' after '__identifier'}}
241 int __identifier(else} = __identifier(for); // expected-error {{missing ')' after identifier}} expected-note {{to match this '('}}
242 #define identifier_weird(x) __identifier(x
243 int k = identifier_weird(if)); // expected-error {{use of undeclared identifier 'if'}}
245 // This is a bit weird, but the alternative tokens aren't keywords, and this
246 // behavior matches MSVC. FIXME: Consider supporting this anyway.
247 extern int __identifier(and) r; // expected-error {{cannot convert '&&' token to an identifier}}
250 __identifier(() // expected-error {{cannot convert '(' token to an identifier}}
251 __identifier(void) // expected-error {{use of undeclared identifier 'void'}}
252 __identifier()) // expected-error {{cannot convert ')' token to an identifier}}
253 // FIXME: We should pick a friendlier display name for this token kind.
254 __identifier(1) // expected-error {{cannot convert <numeric_constant> token to an identifier}}
255 __identifier(+) // expected-error {{cannot convert '+' token to an identifier}}
256 __identifier("foo") // expected-error {{cannot convert <string_literal> token to an identifier}}
257 __identifier(;) // expected-error {{cannot convert ';' token to an identifier}}
260 class inline_definition_pure_spec {
261 virtual int f() = 0 { return 0; }// expected-warning {{function definition with pure-specifier is a Microsoft extension}}
262 virtual int f2() = 0;
265 struct pure_virtual_dtor {
266 virtual ~pure_virtual_dtor() = 0;
268 pure_virtual_dtor::~pure_virtual_dtor() { }
270 struct pure_virtual_dtor_inline {
271 virtual ~pure_virtual_dtor_inline() = 0 { }// expected-warning {{function definition with pure-specifier is a Microsoft extension}}
276 // Necessary to force instantiation in -fdelayed-template-parsing mode.
277 test_late_defined_uuid<int>();
278 redundant_typename<int>();
279 missing_template_keyword<int>();
282 namespace access_protected_PTM {
285 void f(); // expected-note {{must name member using the type of the current context 'access_protected_PTM::B'}}
291 static void test_access_static();
294 void B::test_access() {
295 &A::f; // expected-error {{'f' is a protected member of 'access_protected_PTM::A'}}
298 void B::test_access_static() {
303 namespace Inheritance {
304 class __single_inheritance A;
305 class __multiple_inheritance B;
306 class __virtual_inheritance C;
309 struct StructWithProperty {
310 __declspec(property) int V0; // expected-error {{expected '(' after 'property'}}
311 __declspec(property()) int V1; // expected-error {{property does not specify a getter or a putter}}
312 __declspec(property(set)) int V2; // expected-error {{putter for property must be specified as 'put', not 'set'}} expected-error {{expected '=' after 'set'}}
313 __declspec(property(ptu)) int V3; // expected-error {{missing 'get=' or 'put='}}
314 __declspec(property(ptu=PutV)) int V4; // expected-error {{expected 'get' or 'put' in property declaration}}
315 __declspec(property(get)) int V5; // expected-error {{expected '=' after 'get'}}
316 __declspec(property(get&)) int V6; // expected-error {{expected '=' after 'get'}}
317 __declspec(property(get=)) int V7; // expected-error {{expected name of accessor method}}
318 __declspec(property(get=GetV)) int V8; // no-warning
319 __declspec(property(get=GetV=)) int V9; // expected-error {{expected ',' or ')' at end of property accessor list}}
320 __declspec(property(get=GetV,)) int V10; // expected-error {{expected 'get' or 'put' in property declaration}}
321 __declspec(property(get=GetV,put=SetV)) int V11; // no-warning
322 __declspec(property(get=GetV,put=SetV,get=GetV)) int V12; // expected-error {{property declaration specifies 'get' accessor twice}}
323 __declspec(property(get=GetV)) int V13 = 3; // expected-error {{property declaration cannot have an in-class initializer}}
325 int GetV() { return 123; }
328 void TestProperty() {
329 StructWithProperty sp;
331 sp.V8 = 0; // expected-error {{no setter defined for property 'V8'}}
339 //expected-warning@+1 {{C++ operator 'and' (aka '&&') used as a macro name}}
342 struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) __declspec(novtable) IUnknown {};
344 typedef bool (__stdcall __stdcall *blarg)(int);
346 void local_callconv() {
347 bool (__stdcall *p)(int);
351 int foo() { return 12; }
352 __declspec(property(get=foo) deprecated) int t; // expected-note {{'t' has been explicitly marked deprecated here}}
355 // Technically, this is legal (though it does nothing)
356 __declspec() void quux( void ) {
358 int i = s.t; // expected-warning {{'t' is deprecated}}
364 __declspec(align(16)) int *buffer = (int *)_alloca(9);
368 struct NullptrArg {};
369 NullptrArg<nullptr> a;
371 // Ignored type qualifiers after comma in declarator lists
372 typedef int ignored_quals_dummy1, const volatile __ptr32 __ptr64 __w64 __unaligned __sptr __uptr ignored_quals1; // expected-warning {{qualifiers after comma in declarator list are ignored}}
373 typedef void(*ignored_quals_dummy2)(), __fastcall ignored_quals2; // expected-warning {{qualifiers after comma in declarator list are ignored}}
374 typedef void(*ignored_quals_dummy3)(), __stdcall ignored_quals3; // expected-warning {{qualifiers after comma in declarator list are ignored}}
375 typedef void(*ignored_quals_dummy4)(), __thiscall ignored_quals4; // expected-warning {{qualifiers after comma in declarator list are ignored}}
376 typedef void(*ignored_quals_dummy5)(), __cdecl ignored_quals5; // expected-warning {{qualifiers after comma in declarator list are ignored}}
377 typedef void(*ignored_quals_dummy6)(), __vectorcall ignored_quals6; // expected-warning {{qualifiers after comma in declarator list are ignored}}
381 template <typename T>
384 __assume(f(t)); // expected-warning{{the argument to '__assume' has side effects that will be discarded}}
386 constexpr bool g() { return false; }
388 constexpr A<int> h() {
389 A<int> b(0); // expected-note {{in instantiation of member function}}
392 static_assert(h().g() == false, "");
396 __declspec(align(16)) struct align_before_key1 {};
397 __declspec(align(16)) struct align_before_key2 {} align_before_key2_var;
398 __declspec(align(16)) struct align_before_key3 {} *align_before_key3_var;
399 static_assert(__alignof(struct align_before_key1) == 16, "");
400 static_assert(__alignof(struct align_before_key2) == 16, "");
401 static_assert(__alignof(struct align_before_key3) == 16, "");
406 template <typename T>