1 // RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-extensions -fms-compatibility -fdelayed-template-parsing
2 
3 /* Microsoft attribute tests */
4 [repeatable][source_annotation_attribute( Parameter|ReturnValue )]
5 struct SA_Post{ SA_Post(); int attr; };
6 
7 [returnvalue:SA_Post( attr=1)]
8 int foo1([SA_Post(attr=1)] void *param);
9 
10 namespace {
11   [returnvalue:SA_Post(attr=1)]
12   int foo2([SA_Post(attr=1)] void *param);
13 }
14 
15 class T {
16   [returnvalue:SA_Post(attr=1)]
17   int foo3([SA_Post(attr=1)] void *param);
18 };
19 
20 extern "C" {
21   [returnvalue:SA_Post(attr=1)]
22   int foo5([SA_Post(attr=1)] void *param);
23 }
24 
25 class class_attr {
26 public:
27   class_attr([SA_Pre(Null=SA_No,NullTerminated=SA_Yes)]  int a)
28   {
29   }
30 };
31 
32 
33 
34 void uuidof_test1()
35 {
36   __uuidof(0);  // expected-error {{you need to include <guiddef.h> before using the '__uuidof' operator}}
37 }
38 
39 typedef struct _GUID
40 {
41     unsigned long  Data1;
42     unsigned short Data2;
43     unsigned short Data3;
44     unsigned char  Data4[8];
45 } GUID;
46 
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}}
52 
53 
54 
55 struct __declspec(uuid("000000A0-0000-0000-C000-000000000046"))
56 struct_with_uuid { };
57 struct struct_without_uuid { };
58 
59 struct __declspec(uuid("000000A0-0000-0000-C000-000000000049"))
60 struct_with_uuid2;
61 
62 struct
63 struct_with_uuid2 {} ;
64 
65 int 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);
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 
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 }
86 
87 
88 template <class T>
89 void template_uuid()
90 {
91    T expr;
92 
93    __uuidof(T);
94    __uuidof(expr);
95 }
96 
97 
98 template <class T, const GUID* g = &__uuidof(T)> // expected-note {{template parameter is declared here}}
99 class COM_CLASS_TEMPLATE  { };
100 
101 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}}
102 typedef COM_CLASS_TEMPLATE<struct_with_uuid> COM_TYPE_2;
103 
104 template <class T, const GUID& g>
105 class COM_CLASS_TEMPLATE_REF  { };
106 typedef COM_CLASS_TEMPLATE_REF<struct_with_uuid, __uuidof(struct_with_uuid)> COM_TYPE_REF;
107 
108   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 
115 COM_CLASS_TEMPLATE_REF<int, __uuidof(struct_with_uuid)> good_template_arg;
116 
117 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}}
118 
119 class CtorCall {
120 public:
121   CtorCall& operator=(const CtorCall& that);
122 
123   int a;
124 };
125 
126 CtorCall& 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 }
134 
135 template <class A>
136 class C1 {
137 public:
138   template <int B>
139   class Iterator {
140   };
141 };
142 
143 template<class T>
144 class C2  {
145   typename C1<T>:: /*template*/  Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
146 };
147 
148 template <class T>
149 void missing_template_keyword(){
150   typename C1<T>:: /*template*/ Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
151 }
152 
153 
154 
155 class AAAA {
156    typedef int D;
157 };
158 
159 template <typename T>
160 class SimpleTemplate {};
161 
162 template <class T>
163 void 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'}}
166 
167    t = 3;
168 
169    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'}}
177 }
178 
179 template <typename T>
180 struct TypenameWrongPlace {
181   typename typedef T::D D;// expected-warning {{expected a qualified name after 'typename'}}
182 };
183 
184 extern TypenameWrongPlace<AAAA> PR16925;
185 
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 
198 void interface_test() {
199   MicrosoftInterface* a;
200   a->foo1();
201   MicrosoftDerivedInterface* b;
202   b->foo2();
203 }
204 
205 __int64 x7 = __int64(0);
206 
207 
208 namespace If_exists_test {
209 
210 class IF_EXISTS {
211 private:
212     typedef int Type;
213 };
214 
215 int __if_exists_test() {
216   int b=0;
217   __if_exists(IF_EXISTS::Type) {
218      b++;
219      b++;
220   }
221   __if_exists(IF_EXISTS::Type_not) {
222      this wont compile.
223   }
224   __if_not_exists(IF_EXISTS::Type) {
225      this wont compile.
226   }
227   __if_not_exists(IF_EXISTS::Type_not) {
228      b++;
229      b++;
230   }
231 }
232 
233 
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;
248 }
249 
250 int __if_exists_init_list() {
251 
252   int array1[] = {
253     0,
254     __if_exists(IF_EXISTS::Type) {2, }
255     3
256   };
257 
258   int array2[] = {
259     0,
260     __if_exists(IF_EXISTS::Type_not) { this wont compile }
261     3
262   };
263 
264   int array3[] = {
265     0,
266     __if_not_exists(IF_EXISTS::Type_not) {2, }
267     3
268   };
269 
270   int array4[] = {
271     0,
272     __if_not_exists(IF_EXISTS::Type) { this wont compile }
273     3
274   };
275 
276 }
277 
278 
279 class 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 
304 int __identifier(generic) = 3;
305 
306 class 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 
311 
312 int main () {
313   // Necessary to force instantiation in -fdelayed-template-parsing mode.
314   test_late_defined_uuid<int>();
315   redundant_typename<int>();
316   missing_template_keyword<int>();
317 }
318 
319 namespace 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   };
324 
325   class B : public A{
326   public:
327     void test_access();
328     static void test_access_static();
329   };
330 
331   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 }
339 
340 namespace Inheritance {
341   class __single_inheritance A;
342   class __multiple_inheritance B;
343   class __virtual_inheritance C;
344 }
345 
346 struct 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 };
364 void 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 }
374