17c73083bSBob Wilson // RUN: %clang_cc1 %s -triple i386-pc-win32 -std=c++14 -fsyntax-only -Wno-unused-getter-return-value -Wno-unused-value -Wmicrosoft -verify -fms-extensions -fms-compatibility -fdelayed-template-parsing
2c2bc5ac1SFrancois Pichet 
3c2bc5ac1SFrancois Pichet /* Microsoft attribute tests */
4c2bc5ac1SFrancois Pichet [repeatable][source_annotation_attribute( Parameter|ReturnValue )]
5c2bc5ac1SFrancois Pichet struct SA_Post{ SA_Post(); int attr; };
6c2bc5ac1SFrancois Pichet 
7c2bc5ac1SFrancois Pichet [returnvalue:SA_Post( attr=1)]
8c2bc5ac1SFrancois Pichet int foo1([SA_Post(attr=1)] void *param);
9c2bc5ac1SFrancois Pichet 
10c2bc5ac1SFrancois Pichet namespace {
11c2bc5ac1SFrancois Pichet   [returnvalue:SA_Post(attr=1)]
12c2bc5ac1SFrancois Pichet   int foo2([SA_Post(attr=1)] void *param);
13c2bc5ac1SFrancois Pichet }
14c2bc5ac1SFrancois Pichet 
15c2bc5ac1SFrancois Pichet class T {
16c2bc5ac1SFrancois Pichet   [returnvalue:SA_Post(attr=1)]
17c2bc5ac1SFrancois Pichet   int foo3([SA_Post(attr=1)] void *param);
18c2bc5ac1SFrancois Pichet };
19c2bc5ac1SFrancois Pichet 
20c2bc5ac1SFrancois Pichet extern "C" {
21c2bc5ac1SFrancois Pichet   [returnvalue:SA_Post(attr=1)]
22c2bc5ac1SFrancois Pichet   int foo5([SA_Post(attr=1)] void *param);
23c2bc5ac1SFrancois Pichet }
24c2bc5ac1SFrancois Pichet 
2579f3a870SFrancois Pichet class class_attr {
2679f3a870SFrancois Pichet public:
2779f3a870SFrancois Pichet   class_attr([SA_Pre(Null=SA_No,NullTerminated=SA_Yes)]  int a)
2879f3a870SFrancois Pichet   {
2979f3a870SFrancois Pichet   }
3079f3a870SFrancois Pichet };
3179f3a870SFrancois Pichet 
3279f3a870SFrancois Pichet 
33c2bc5ac1SFrancois Pichet 
uuidof_test1()349dddd40aSFrancois Pichet void uuidof_test1()
359dddd40aSFrancois Pichet {
36bab6df86SRichard Smith   __uuidof(0);
379dddd40aSFrancois Pichet }
389dddd40aSFrancois Pichet 
399dddd40aSFrancois Pichet typedef struct _GUID
409dddd40aSFrancois Pichet {
419dddd40aSFrancois Pichet     unsigned long  Data1;
429dddd40aSFrancois Pichet     unsigned short Data2;
439dddd40aSFrancois Pichet     unsigned short Data3;
449dddd40aSFrancois Pichet     unsigned char  Data4[8];
459dddd40aSFrancois Pichet } GUID;
469dddd40aSFrancois Pichet 
473bf758cdSAaron Ballman struct __declspec(uuid(L"00000000-0000-0000-1234-000000000047")) uuid_attr_bad1 { };// expected-error {{'uuid' attribute requires a string}}
483bf758cdSAaron Ballman struct __declspec(uuid(3)) uuid_attr_bad2 { };// expected-error {{'uuid' attribute requires a string}}
499dddd40aSFrancois Pichet struct __declspec(uuid("0000000-0000-0000-1234-0000500000047")) uuid_attr_bad3 { };// expected-error {{uuid attribute contains a malformed GUID}}
509dddd40aSFrancois Pichet struct __declspec(uuid("0000000-0000-0000-Z234-000000000047")) uuid_attr_bad4 { };// expected-error {{uuid attribute contains a malformed GUID}}
519dddd40aSFrancois Pichet struct __declspec(uuid("000000000000-0000-1234-000000000047")) uuid_attr_bad5 { };// expected-error {{uuid attribute contains a malformed GUID}}
5205e1dadaSNico Weber [uuid("000000000000-0000-1234-000000000047")] struct uuid_attr_bad6 { };// expected-error {{uuid attribute contains a malformed GUID}}
539dddd40aSFrancois Pichet 
54adf66b61SAaron Ballman __declspec(uuid("000000A0-0000-0000-C000-000000000046")) int i; // expected-warning {{'uuid' attribute only applies to structs, unions, classes, and enums}}
559dddd40aSFrancois Pichet 
569dddd40aSFrancois Pichet struct __declspec(uuid("000000A0-0000-0000-C000-000000000046"))
579dddd40aSFrancois Pichet struct_with_uuid { };
589dddd40aSFrancois Pichet struct struct_without_uuid { };
599dddd40aSFrancois Pichet 
60*8c7b64b5SMartin Boehme struct base {
61*8c7b64b5SMartin Boehme   int a;
62*8c7b64b5SMartin Boehme };
63*8c7b64b5SMartin Boehme struct derived : base {
64*8c7b64b5SMartin Boehme   // Can't apply a UUID to a using declaration.
65*8c7b64b5SMartin Boehme   [uuid("000000A0-0000-0000-C000-00000000004A")] using base::a; // expected-error {{expected member name}}
66*8c7b64b5SMartin Boehme };
67*8c7b64b5SMartin Boehme 
68b7577657SFrancois Pichet struct __declspec(uuid("000000A0-0000-0000-C000-000000000049"))
69b7577657SFrancois Pichet struct_with_uuid2;
70b7577657SFrancois Pichet 
71469891e7SNico Weber [uuid("000000A0-0000-0000-C000-000000000049")] struct struct_with_uuid3; // expected-warning{{specifying 'uuid' as an ATL attribute is deprecated; use __declspec instead}}
7205e1dadaSNico Weber 
73b7577657SFrancois Pichet struct
74b7577657SFrancois Pichet struct_with_uuid2 {} ;
759dddd40aSFrancois Pichet 
76e516eab1SReid Kleckner enum __declspec(uuid("000000A0-0000-0000-C000-000000000046"))
77e516eab1SReid Kleckner enum_with_uuid { };
78e516eab1SReid Kleckner enum enum_without_uuid { };
79e516eab1SReid Kleckner 
80adf66b61SAaron Ballman int __declspec(uuid("000000A0-0000-0000-C000-000000000046")) inappropriate_uuid; // expected-warning {{'uuid' attribute only applies to}}
81e516eab1SReid Kleckner 
uuid_sema_test()829dddd40aSFrancois Pichet int uuid_sema_test()
839dddd40aSFrancois Pichet {
849dddd40aSFrancois Pichet    struct_with_uuid var_with_uuid[1];
859dddd40aSFrancois Pichet    struct_without_uuid var_without_uuid[1];
869dddd40aSFrancois Pichet 
879dddd40aSFrancois Pichet    __uuidof(struct_with_uuid);
88b7577657SFrancois Pichet    __uuidof(struct_with_uuid2);
8905e1dadaSNico Weber    __uuidof(struct_with_uuid3);
909dddd40aSFrancois Pichet    __uuidof(struct_without_uuid); // expected-error {{cannot call operator __uuidof on a type with no GUID}}
919dddd40aSFrancois Pichet    __uuidof(struct_with_uuid*);
929dddd40aSFrancois Pichet    __uuidof(struct_without_uuid*); // expected-error {{cannot call operator __uuidof on a type with no GUID}}
9368c880b5SDavid Majnemer    __uuidof(struct_with_uuid[1]);
9468c880b5SDavid Majnemer    __uuidof(struct_with_uuid*[1]); // expected-error {{cannot call operator __uuidof on a type with no GUID}}
9568c880b5SDavid Majnemer    __uuidof(const struct_with_uuid[1][1]);
9668c880b5SDavid Majnemer    __uuidof(const struct_with_uuid*[1][1]); // expected-error {{cannot call operator __uuidof on a type with no GUID}}
979dddd40aSFrancois Pichet 
98e516eab1SReid Kleckner    __uuidof(enum_with_uuid);
99e516eab1SReid Kleckner    __uuidof(enum_without_uuid); // expected-error {{cannot call operator __uuidof on a type with no GUID}}
100e516eab1SReid Kleckner    __uuidof(enum_with_uuid*);
101e516eab1SReid Kleckner    __uuidof(enum_without_uuid*); // expected-error {{cannot call operator __uuidof on a type with no GUID}}
102e516eab1SReid Kleckner    __uuidof(enum_with_uuid[1]);
103e516eab1SReid Kleckner    __uuidof(enum_with_uuid*[1]); // expected-error {{cannot call operator __uuidof on a type with no GUID}}
104e516eab1SReid Kleckner    __uuidof(const enum_with_uuid[1][1]);
105e516eab1SReid Kleckner    __uuidof(const enum_with_uuid*[1][1]); // expected-error {{cannot call operator __uuidof on a type with no GUID}}
106e516eab1SReid Kleckner 
1079dddd40aSFrancois Pichet    __uuidof(var_with_uuid);
1089dddd40aSFrancois Pichet    __uuidof(var_without_uuid);// expected-error {{cannot call operator __uuidof on a type with no GUID}}
1099dddd40aSFrancois Pichet    __uuidof(var_with_uuid[1]);
1109dddd40aSFrancois Pichet    __uuidof(var_without_uuid[1]);// expected-error {{cannot call operator __uuidof on a type with no GUID}}
1119dddd40aSFrancois Pichet    __uuidof(&var_with_uuid[1]);
1129dddd40aSFrancois Pichet    __uuidof(&var_without_uuid[1]);// expected-error {{cannot call operator __uuidof on a type with no GUID}}
1139dddd40aSFrancois Pichet 
1149dddd40aSFrancois Pichet    __uuidof(0);
1159dddd40aSFrancois Pichet    __uuidof(1);// expected-error {{cannot call operator __uuidof on a type with no GUID}}
1169dddd40aSFrancois Pichet }
117b7577657SFrancois Pichet 
118b7577657SFrancois Pichet 
119b7577657SFrancois Pichet template <class T>
template_uuid()120b7577657SFrancois Pichet void template_uuid()
121b7577657SFrancois Pichet {
122b7577657SFrancois Pichet    T expr;
123b7577657SFrancois Pichet 
124b7577657SFrancois Pichet    __uuidof(T);
125b7577657SFrancois Pichet    __uuidof(expr);
126b7577657SFrancois Pichet }
12764225794SFrancois Pichet 
12864225794SFrancois Pichet 
12961c39a1cSDavid Majnemer template <class T, const GUID* g = &__uuidof(T)> // expected-note {{template parameter is declared here}}
130a1c1352aSFrancois Pichet class COM_CLASS_TEMPLATE  { };
131a1c1352aSFrancois Pichet 
13261c39a1cSDavid Majnemer 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}}
133a1c1352aSFrancois Pichet typedef COM_CLASS_TEMPLATE<struct_with_uuid> COM_TYPE_2;
134a1c1352aSFrancois Pichet 
135c8679757SFrancois Pichet template <class T, const GUID& g>
136c8679757SFrancois Pichet class COM_CLASS_TEMPLATE_REF  { };
1370066db90SFrancois Pichet typedef COM_CLASS_TEMPLATE_REF<struct_with_uuid, __uuidof(struct_with_uuid)> COM_TYPE_REF;
138a1c1352aSFrancois Pichet 
1392f019ed2SFrancois Pichet   struct late_defined_uuid;
1402f019ed2SFrancois Pichet   template<typename T>
test_late_defined_uuid()1412f019ed2SFrancois Pichet   void test_late_defined_uuid() {
1422f019ed2SFrancois Pichet     __uuidof(late_defined_uuid);
1432f019ed2SFrancois Pichet   }
1442f019ed2SFrancois Pichet   struct __declspec(uuid("000000A0-0000-0000-C000-000000000049")) late_defined_uuid;
1452f019ed2SFrancois Pichet 
14661c39a1cSDavid Majnemer COM_CLASS_TEMPLATE_REF<int, __uuidof(struct_with_uuid)> good_template_arg;
14761c39a1cSDavid Majnemer 
148bab6df86SRichard Smith COM_CLASS_TEMPLATE<int, __uuidof(struct_with_uuid)> bad_template_arg; // expected-error {{non-type template argument for template parameter of pointer type 'const GUID *' (aka 'const _GUID *') must have its address taken}}
14964225794SFrancois Pichet 
15059c0ec23SDavid Majnemer namespace PR16911 {
15159c0ec23SDavid Majnemer struct __declspec(uuid("{12345678-1234-1234-1234-1234567890aB}")) uuid;
15259c0ec23SDavid Majnemer struct __declspec(uuid("{12345678-1234-1234-1234-1234567890aB}")) uuid2;
15359c0ec23SDavid Majnemer 
15459c0ec23SDavid Majnemer template <typename T, typename T2>
15559c0ec23SDavid Majnemer struct thing {
15659c0ec23SDavid Majnemer };
15759c0ec23SDavid Majnemer 
15859c0ec23SDavid Majnemer struct empty {};
15959c0ec23SDavid Majnemer struct inher : public thing<empty, uuid2> {};
16059c0ec23SDavid Majnemer 
16159c0ec23SDavid Majnemer struct __declspec(uuid("{12345678-1234-1234-1234-1234567890aB}")) uuid;
16259c0ec23SDavid Majnemer const struct _GUID *w = &__uuidof(inher); // expected-error{{cannot call operator __uuidof on a type with no GUID}}
16359c0ec23SDavid Majnemer const struct _GUID *x = &__uuidof(thing<uuid, inher>);
16459c0ec23SDavid Majnemer const struct _GUID *y = &__uuidof(thing<uuid2, uuid>); // expected-error{{cannot call operator __uuidof on a type with multiple GUIDs}}
16559c0ec23SDavid Majnemer thing<uuid2, uuid> thing_obj = thing<uuid2, uuid>();
16659c0ec23SDavid Majnemer const struct _GUID *z = &__uuidof(thing_obj); // expected-error{{cannot call operator __uuidof on a type with multiple GUIDs}}
16759c0ec23SDavid Majnemer }
16859c0ec23SDavid Majnemer 
16964225794SFrancois Pichet class CtorCall {
17064225794SFrancois Pichet public:
17164225794SFrancois Pichet   CtorCall& operator=(const CtorCall& that);
17264225794SFrancois Pichet 
17364225794SFrancois Pichet   int a;
17464225794SFrancois Pichet };
17564225794SFrancois Pichet 
operator =(const CtorCall & that)17664225794SFrancois Pichet CtorCall& CtorCall::operator=(const CtorCall& that)
17764225794SFrancois Pichet {
17864225794SFrancois Pichet     if (this != &that) {
17964225794SFrancois Pichet         this->CtorCall::~CtorCall();
18064225794SFrancois Pichet         this->CtorCall::CtorCall(that); // expected-warning {{explicit constructor calls are a Microsoft extension}}
18164225794SFrancois Pichet     }
18264225794SFrancois Pichet     return *this;
18364225794SFrancois Pichet }
1844e7a2c09SFrancois Pichet 
1854e7a2c09SFrancois Pichet template <class A>
1864e7a2c09SFrancois Pichet class C1 {
1874e7a2c09SFrancois Pichet public:
1884e7a2c09SFrancois Pichet   template <int B>
1894e7a2c09SFrancois Pichet   class Iterator {
1904e7a2c09SFrancois Pichet   };
1914e7a2c09SFrancois Pichet };
1924e7a2c09SFrancois Pichet 
1934e7a2c09SFrancois Pichet template<class T>
1944e7a2c09SFrancois Pichet class C2  {
1954e7a2c09SFrancois Pichet   typename C1<T>:: /*template*/  Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
1964e7a2c09SFrancois Pichet };
1974e7a2c09SFrancois Pichet 
1984e7a2c09SFrancois Pichet template <class T>
missing_template_keyword()1992f019ed2SFrancois Pichet void missing_template_keyword(){
2004e7a2c09SFrancois Pichet   typename C1<T>:: /*template*/ Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
2014e7a2c09SFrancois Pichet }
2024e7a2c09SFrancois Pichet 
203dd876125SFrancois Pichet 
204dd876125SFrancois Pichet 
205ad01851fSDavid Majnemer class AAAA {
206ad01851fSDavid Majnemer    typedef int D;
207ad01851fSDavid Majnemer };
208dd876125SFrancois Pichet 
209b71e7324SRichard Smith template <typename T>
210b71e7324SRichard Smith class SimpleTemplate {};
211b71e7324SRichard Smith 
212dd876125SFrancois Pichet template <class T>
redundant_typename()213dd876125SFrancois Pichet void redundant_typename() {
214dd876125SFrancois Pichet    typename T t;// expected-warning {{expected a qualified name after 'typename'}}
215dd876125SFrancois Pichet    typename AAAA a;// expected-warning {{expected a qualified name after 'typename'}}
216b71e7324SRichard Smith 
217dd876125SFrancois Pichet    t = 3;
218b71e7324SRichard Smith 
219b71e7324SRichard Smith    typedef typename T* pointerT;// expected-warning {{expected a qualified name after 'typename'}}
220b71e7324SRichard Smith    typedef typename SimpleTemplate<int> templateT;// expected-warning {{expected a qualified name after 'typename'}}
221b71e7324SRichard Smith 
222b71e7324SRichard Smith    pointerT pT = &t;
223b71e7324SRichard Smith    *pT = 4;
224b71e7324SRichard Smith 
225b71e7324SRichard Smith    int var;
226b71e7324SRichard Smith    int k = typename var;// expected-error {{expected a qualified name after 'typename'}}
227dd876125SFrancois Pichet }
228dd876125SFrancois Pichet 
229ad01851fSDavid Majnemer template <typename T>
230ad01851fSDavid Majnemer struct TypenameWrongPlace {
231ad01851fSDavid Majnemer   typename typedef T::D D;// expected-warning {{expected a qualified name after 'typename'}}
232ad01851fSDavid Majnemer };
233ad01851fSDavid Majnemer 
234ad01851fSDavid Majnemer extern TypenameWrongPlace<AAAA> PR16925;
2354e7a2c09SFrancois Pichet 
23633477fdfSFrancois Pichet __interface MicrosoftInterface;
23733477fdfSFrancois Pichet __interface MicrosoftInterface {
238f920a0aaSFariborz Jahanian    void foo1() = 0; // expected-note {{overridden virtual function is here}}
23933477fdfSFrancois Pichet    virtual void foo2() = 0;
24033477fdfSFrancois Pichet };
24184133e41SFrancois Pichet 
242dc86f94fSJoao Matos __interface MicrosoftDerivedInterface : public MicrosoftInterface {
243f920a0aaSFariborz Jahanian   void foo1(); // expected-warning {{'foo1' overrides a member function but is not marked 'override'}}
244dc86f94fSJoao Matos   void foo2() override;
245dc86f94fSJoao Matos   void foo3();
246dc86f94fSJoao Matos };
247dc86f94fSJoao Matos 
248d3b986dfSFrancois Pichet void interface_test() {
249d3b986dfSFrancois Pichet   MicrosoftInterface* a;
250d3b986dfSFrancois Pichet   a->foo1();
251dc86f94fSJoao Matos   MicrosoftDerivedInterface* b;
252dc86f94fSJoao Matos   b->foo2();
253d3b986dfSFrancois Pichet }
254d3b986dfSFrancois Pichet 
25584133e41SFrancois Pichet __int64 x7 = __int64(0);
256efd1375fSReid Kleckner _int64 x8 = _int64(0);
257efd1375fSReid Kleckner static_assert(sizeof(_int64) == 8, "");
258efd1375fSReid Kleckner static_assert(sizeof(_int32) == 4, "");
259efd1375fSReid Kleckner static_assert(sizeof(_int16) == 2, "");
260efd1375fSReid Kleckner static_assert(sizeof(_int8) == 1, "");
2614a7de3ebSFrancois Pichet 
26261d818c0SFrancois Pichet int __identifier(generic) = 3;
263ae385084SRichard Smith int __identifier(int) = 4;
264ae385084SRichard Smith struct __identifier(class) { __identifier(class) *__identifier(for); };
265ae385084SRichard Smith __identifier(class) __identifier(struct) = { &__identifier(struct) };
266ae385084SRichard Smith 
267ae385084SRichard Smith int __identifier for; // expected-error {{missing '(' after '__identifier'}}
268ae385084SRichard Smith int __identifier(else} = __identifier(for); // expected-error {{missing ')' after identifier}} expected-note {{to match this '('}}
269ae385084SRichard Smith #define identifier_weird(x) __identifier(x
270ae385084SRichard Smith int k = identifier_weird(if)); // expected-error {{use of undeclared identifier 'if'}}
271ae385084SRichard Smith 
27290f981bcSOlivier Goffart extern int __identifier(and);
273ae385084SRichard Smith 
274b5b3843fSMelvin Fox int __identifier("baz") = 0;
275b5b3843fSMelvin Fox int bar = baz;
276b5b3843fSMelvin Fox 
277b5b3843fSMelvin Fox void mangled_function();
278b5b3843fSMelvin Fox extern "C" void __identifier("?mangled_function@@YAXXZ")() {}
279b5b3843fSMelvin Fox 
280ae385084SRichard Smith void f() {
281ae385084SRichard Smith   __identifier(() // expected-error {{cannot convert '(' token to an identifier}}
282ae385084SRichard Smith   __identifier(void) // expected-error {{use of undeclared identifier 'void'}}
283ae385084SRichard Smith   __identifier()) // expected-error {{cannot convert ')' token to an identifier}}
284ae385084SRichard Smith   // FIXME: We should pick a friendlier display name for this token kind.
285ae385084SRichard Smith   __identifier(1) // expected-error {{cannot convert <numeric_constant> token to an identifier}}
286ae385084SRichard Smith   __identifier(+) // expected-error {{cannot convert '+' token to an identifier}}
287ae385084SRichard Smith   __identifier(;) // expected-error {{cannot convert ';' token to an identifier}}
288b5b3843fSMelvin Fox   __identifier("1"); // expected-error {{use of undeclared identifier '1'}}
289b5b3843fSMelvin Fox   __identifier("+"); // expected-error {{use of undeclared identifier '+'}}
290b5b3843fSMelvin Fox   __identifier(";"); // expected-error {{use of undeclared identifier ';'}}
291ae385084SRichard Smith }
29261d818c0SFrancois Pichet 
2933abc9b8bSFrancois Pichet class inline_definition_pure_spec {
2943abc9b8bSFrancois Pichet    virtual int f() = 0 { return 0; }// expected-warning {{function definition with pure-specifier is a Microsoft extension}}
2953abc9b8bSFrancois Pichet    virtual int f2() = 0;
2963abc9b8bSFrancois Pichet };
2973abc9b8bSFrancois Pichet 
298be7a4466SReid Kleckner struct pure_virtual_dtor {
299be7a4466SReid Kleckner   virtual ~pure_virtual_dtor() = 0;
300be7a4466SReid Kleckner };
301be7a4466SReid Kleckner pure_virtual_dtor::~pure_virtual_dtor() { }
302be7a4466SReid Kleckner 
303be7a4466SReid Kleckner struct pure_virtual_dtor_inline {
304be7a4466SReid Kleckner   virtual ~pure_virtual_dtor_inline() = 0 { }// expected-warning {{function definition with pure-specifier is a Microsoft extension}}
305be7a4466SReid Kleckner };
306be7a4466SReid Kleckner 
307ba7ffae0SBruno Ricci template<typename T> struct pure_virtual_dtor_template {
308ba7ffae0SBruno Ricci   virtual ~pure_virtual_dtor_template() = 0;
309ba7ffae0SBruno Ricci };
310ba7ffae0SBruno Ricci template<typename T> pure_virtual_dtor_template<T>::~pure_virtual_dtor_template() {}
311ba7ffae0SBruno Ricci template struct pure_virtual_dtor_template<int>;
312ba7ffae0SBruno Ricci 
313ba7ffae0SBruno Ricci template<typename T> struct pure_virtual_dtor_template_inline {
314ba7ffae0SBruno Ricci     virtual ~pure_virtual_dtor_template_inline() = 0 {}
315ba7ffae0SBruno Ricci     // expected-warning@-1 2{{function definition with pure-specifier is a Microsoft extension}}
316ba7ffae0SBruno Ricci };
317ba7ffae0SBruno Ricci template struct pure_virtual_dtor_template_inline<int>;
318ba7ffae0SBruno Ricci // expected-note@-1 {{in instantiation of member function}}
3192f019ed2SFrancois Pichet 
3202f019ed2SFrancois Pichet int main () {
3212f019ed2SFrancois Pichet   // Necessary to force instantiation in -fdelayed-template-parsing mode.
3222f019ed2SFrancois Pichet   test_late_defined_uuid<int>();
3232f019ed2SFrancois Pichet   redundant_typename<int>();
3242f019ed2SFrancois Pichet   missing_template_keyword<int>();
3252f019ed2SFrancois Pichet }
3262f019ed2SFrancois Pichet 
327a39371c0SFrancois Pichet namespace access_protected_PTM {
328a39371c0SFrancois Pichet   class A {
329a39371c0SFrancois Pichet   protected:
330a39371c0SFrancois Pichet     void f(); // expected-note {{must name member using the type of the current context 'access_protected_PTM::B'}}
331a39371c0SFrancois Pichet   };
332a39371c0SFrancois Pichet 
333a39371c0SFrancois Pichet   class B : public A{
334a39371c0SFrancois Pichet   public:
335a39371c0SFrancois Pichet     void test_access();
336a39371c0SFrancois Pichet     static void test_access_static();
337a39371c0SFrancois Pichet   };
338a39371c0SFrancois Pichet 
339a39371c0SFrancois Pichet   void B::test_access() {
340a39371c0SFrancois Pichet     &A::f; // expected-error {{'f' is a protected member of 'access_protected_PTM::A'}}
341a39371c0SFrancois Pichet   }
342a39371c0SFrancois Pichet 
343a39371c0SFrancois Pichet   void B::test_access_static() {
344a39371c0SFrancois Pichet     &A::f;
345a39371c0SFrancois Pichet   }
346a39371c0SFrancois Pichet }
3478d32c05eSJohn McCall 
3488d32c05eSJohn McCall namespace Inheritance {
3498d32c05eSJohn McCall   class __single_inheritance A;
3508d32c05eSJohn McCall   class __multiple_inheritance B;
3518d32c05eSJohn McCall   class __virtual_inheritance C;
3528d32c05eSJohn McCall }
3535e77d76cSJohn McCall 
3545e77d76cSJohn McCall struct StructWithProperty {
3555e77d76cSJohn McCall   __declspec(property) int V0; // expected-error {{expected '(' after 'property'}}
3565e77d76cSJohn McCall   __declspec(property()) int V1; // expected-error {{property does not specify a getter or a putter}}
3575e77d76cSJohn McCall   __declspec(property(set)) int V2; // expected-error {{putter for property must be specified as 'put', not 'set'}} expected-error {{expected '=' after 'set'}}
3585e77d76cSJohn McCall   __declspec(property(ptu)) int V3; // expected-error {{missing 'get=' or 'put='}}
3595e77d76cSJohn McCall   __declspec(property(ptu=PutV)) int V4; // expected-error {{expected 'get' or 'put' in property declaration}}
3605e77d76cSJohn McCall   __declspec(property(get)) int V5; // expected-error {{expected '=' after 'get'}}
3615e77d76cSJohn McCall   __declspec(property(get&)) int V6; // expected-error {{expected '=' after 'get'}}
3625e77d76cSJohn McCall   __declspec(property(get=)) int V7; // expected-error {{expected name of accessor method}}
3635e77d76cSJohn McCall   __declspec(property(get=GetV)) int V8; // no-warning
3645e77d76cSJohn McCall   __declspec(property(get=GetV=)) int V9; // expected-error {{expected ',' or ')' at end of property accessor list}}
3655e77d76cSJohn McCall   __declspec(property(get=GetV,)) int V10; // expected-error {{expected 'get' or 'put' in property declaration}}
3665e77d76cSJohn McCall   __declspec(property(get=GetV,put=SetV)) int V11; // no-warning
3675e77d76cSJohn McCall   __declspec(property(get=GetV,put=SetV,get=GetV)) int V12; // expected-error {{property declaration specifies 'get' accessor twice}}
36815fbae8aSAaron Ballman   __declspec(property(get=GetV)) int V13 = 3; // expected-error {{property declaration cannot have a default member initializer}}
3695e77d76cSJohn McCall 
3705e77d76cSJohn McCall   int GetV() { return 123; }
3715e77d76cSJohn McCall   void SetV(int v) {}
3725e77d76cSJohn McCall };
3735e77d76cSJohn McCall void TestProperty() {
3745e77d76cSJohn McCall   StructWithProperty sp;
3755e77d76cSJohn McCall   sp.V8;
3765e77d76cSJohn McCall   sp.V8 = 0; // expected-error {{no setter defined for property 'V8'}}
3775e77d76cSJohn McCall   int i = sp.V11;
3785e77d76cSJohn McCall   sp.V11 = i++;
3795e77d76cSJohn McCall   sp.V11 += 8;
3805e77d76cSJohn McCall   sp.V11++;
3815e77d76cSJohn McCall   ++sp.V11;
3825e77d76cSJohn McCall }
383e03e9e15SAlp Toker 
384d46083ccSErich Keane //expected-warning@+1 {{C++ operator 'and' (aka '&&') used as a macro name}}
385e03e9e15SAlp Toker #define and foo
3861c8a5d75SAaron Ballman 
387129f417eSDavid Majnemer struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) __declspec(novtable) IUnknown {};
3881c8a5d75SAaron Ballman 
3891c8a5d75SAaron Ballman typedef bool (__stdcall __stdcall *blarg)(int);
3901c8a5d75SAaron Ballman 
3911c8a5d75SAaron Ballman void local_callconv() {
3921c8a5d75SAaron Ballman   bool (__stdcall *p)(int);
3931c8a5d75SAaron Ballman }
3941c8a5d75SAaron Ballman 
3951c8a5d75SAaron Ballman struct S7 {
3961c8a5d75SAaron Ballman 	int foo() { return 12; }
3971c8a5d75SAaron Ballman 	__declspec(property(get=foo) deprecated) int t; // expected-note {{'t' has been explicitly marked deprecated here}}
3981c8a5d75SAaron Ballman };
3991c8a5d75SAaron Ballman 
4001c8a5d75SAaron Ballman // Technically, this is legal (though it does nothing)
4011c8a5d75SAaron Ballman __declspec() void quux( void ) {
4021c8a5d75SAaron Ballman   struct S7 s;
4031c8a5d75SAaron Ballman   int i = s.t;	// expected-warning {{'t' is deprecated}}
4041c8a5d75SAaron Ballman }
4051c8a5d75SAaron Ballman 
4061c8a5d75SAaron Ballman void *_alloca(int);
4071c8a5d75SAaron Ballman 
4081c8a5d75SAaron Ballman void foo(void) {
4091c8a5d75SAaron Ballman   __declspec(align(16)) int *buffer = (int *)_alloca(9);
4101c8a5d75SAaron Ballman }
4115c734ad8SDavid Majnemer 
4125c734ad8SDavid Majnemer template <int *>
4135c734ad8SDavid Majnemer struct NullptrArg {};
4145c734ad8SDavid Majnemer NullptrArg<nullptr> a;
415eaaae27bSNico Rieck 
416eaaae27bSNico Rieck // Ignored type qualifiers after comma in declarator lists
417eaaae27bSNico Rieck 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}}
418eaaae27bSNico Rieck typedef void(*ignored_quals_dummy2)(), __fastcall ignored_quals2; // expected-warning {{qualifiers after comma in declarator list are ignored}}
419eaaae27bSNico Rieck typedef void(*ignored_quals_dummy3)(), __stdcall ignored_quals3; // expected-warning {{qualifiers after comma in declarator list are ignored}}
420eaaae27bSNico Rieck typedef void(*ignored_quals_dummy4)(), __thiscall ignored_quals4; // expected-warning {{qualifiers after comma in declarator list are ignored}}
421eaaae27bSNico Rieck typedef void(*ignored_quals_dummy5)(), __cdecl ignored_quals5; // expected-warning {{qualifiers after comma in declarator list are ignored}}
422eaaae27bSNico Rieck typedef void(*ignored_quals_dummy6)(), __vectorcall ignored_quals6; // expected-warning {{qualifiers after comma in declarator list are ignored}}
42351236644SDavid Majnemer 
42451236644SDavid Majnemer namespace {
42551236644SDavid Majnemer bool f(int);
42651236644SDavid Majnemer template <typename T>
42751236644SDavid Majnemer struct A {
42851236644SDavid Majnemer   constexpr A(T t) {
42951236644SDavid Majnemer     __assume(f(t)); // expected-warning{{the argument to '__assume' has side effects that will be discarded}}
43051236644SDavid Majnemer   }
43151236644SDavid Majnemer   constexpr bool g() { return false; }
43251236644SDavid Majnemer };
43351236644SDavid Majnemer constexpr A<int> h() {
43451236644SDavid Majnemer   A<int> b(0); // expected-note {{in instantiation of member function}}
43551236644SDavid Majnemer   return b;
43651236644SDavid Majnemer }
43751236644SDavid Majnemer static_assert(h().g() == false, "");
43851236644SDavid Majnemer }
439936b411bSDavid Majnemer 
440936b411bSDavid Majnemer namespace {
441936b411bSDavid Majnemer __declspec(align(16)) struct align_before_key1 {};
442936b411bSDavid Majnemer __declspec(align(16)) struct align_before_key2 {} align_before_key2_var;
443936b411bSDavid Majnemer __declspec(align(16)) struct align_before_key3 {} *align_before_key3_var;
444936b411bSDavid Majnemer static_assert(__alignof(struct align_before_key1) == 16, "");
445936b411bSDavid Majnemer static_assert(__alignof(struct align_before_key2) == 16, "");
446936b411bSDavid Majnemer static_assert(__alignof(struct align_before_key3) == 16, "");
447936b411bSDavid Majnemer }
448e4752e75SDavid Majnemer 
449e4752e75SDavid Majnemer namespace PR24027 {
450e4752e75SDavid Majnemer struct S {
451e4752e75SDavid Majnemer   template <typename T>
452e4752e75SDavid Majnemer   S(T);
453e4752e75SDavid Majnemer } f([] {});
454e4752e75SDavid Majnemer }
455c6663b7cSReid Kleckner 
456c6663b7cSReid Kleckner namespace pr36638 {
457c6663b7cSReid Kleckner // Make sure we accept __unaligned method qualifiers on member function
458c6663b7cSReid Kleckner // pointers.
459c6663b7cSReid Kleckner struct A;
460c6663b7cSReid Kleckner void (A::*mp1)(int) __unaligned;
461c6663b7cSReid Kleckner }
462d6425e2cSRichard Smith 
463d6425e2cSRichard Smith namespace enum_class {
464d6425e2cSRichard Smith   // MSVC allows opaque-enum-declaration syntax anywhere an
465d6425e2cSRichard Smith   // elaborated-type-specifier can appear.
466d6425e2cSRichard Smith   // FIXME: Most of these are missing warnings.
467d6425e2cSRichard Smith   enum E0 *p0; // expected-warning {{Microsoft extension}}
468d6425e2cSRichard Smith   enum class E1 : int *p1;
469d6425e2cSRichard Smith   enum E2 : int *p2;
470d6425e2cSRichard Smith   enum class E3 *p3;
471d6425e2cSRichard Smith   auto f4() -> enum class E4 { return {}; }
472d6425e2cSRichard Smith   auto f5() -> enum E5 : int { return {}; } // FIXME: MSVC rejects this and crashes if the body is {}.
473d6425e2cSRichard Smith   auto f6() -> enum E6 { return {}; } // expected-warning {{Microsoft extension}}
4748fc12b86SRichard Smith 
4758fc12b86SRichard Smith   // MSVC does not perform disambiguation for a colon that could introduce an
4768fc12b86SRichard Smith   // enum-base or a bit-field.
4778fc12b86SRichard Smith   enum E {};
4788fc12b86SRichard Smith   struct S {
4798fc12b86SRichard Smith     enum E : int(1); // expected-error {{anonymous bit-field}}
4808fc12b86SRichard Smith     enum E : int : 1; // OK, bit-field
4818fc12b86SRichard Smith     enum F : int a = {}; // OK, default member initializer
4828fc12b86SRichard Smith     // MSVC produces a "C4353 constant 0 as function expression" for this,
4838fc12b86SRichard Smith     // considering the final {} to be part of the bit-width. We follow P0683R1
4848fc12b86SRichard Smith     // and treat it as a default member initializer.
485538762feSAaron Ballman     enum E : int : int{}{}; // expected-error {{anonymous bit-field cannot have a default member initializer}}
4868fc12b86SRichard Smith   };
487d6425e2cSRichard Smith }
488