MicrosoftExtensions.cpp revision 20e3c9ed21b47c3b6d1d82df84db357600bacc06
1// RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-extensions -fdelayed-template-parsing
2
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
25class class_attr {
26public:
27  class_attr([SA_Pre(Null=SA_No,NullTerminated=SA_Yes)]  int a)
28  {
29  }
30};
31
32
33
34void 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
59struct __declspec(uuid("000000A0-0000-0000-C000-000000000049"))
60struct_with_uuid2;
61
62struct
63struct_with_uuid2 {} ;
64
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);
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
88template <class T>
89void template_uuid()
90{
91   T expr;
92
93   __uuidof(T);
94   __uuidof(expr);
95}
96
97
98template <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
104template <class T, const GUID& g>
105class COM_CLASS_TEMPLATE_REF  { };
106typedef COM_CLASS_TEMPLATE<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
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}
131
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>
146void missing_template_keyword(){
147  typename C1<T>:: /*template*/ Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
148}
149
150
151
152class AAAA { };
153
154template <class T>
155void redundant_typename() {
156   typename T t;// expected-warning {{expected a qualified name after 'typename'}}
157   typename AAAA a;// expected-warning {{expected a qualified name after 'typename'}}
158   t = 3;
159}
160
161
162__interface MicrosoftInterface;
163__interface MicrosoftInterface {
164   virtual void foo1() = 0;
165   virtual void foo2() = 0;
166};
167
168__int64 x7 = __int64(0);
169
170
171
172
173class IF_EXISTS {
174private:
175    typedef int Type;
176};
177
178int __if_exists_test() {
179  int b=0;
180  __if_exists(IF_EXISTS::Type) {
181     b++;
182     b++;
183  }
184  __if_exists(IF_EXISTS::Type_not) {
185     this wont compile.
186  }
187  __if_not_exists(IF_EXISTS::Type) {
188     this wont compile.
189  }
190  __if_not_exists(IF_EXISTS::Type_not) {
191     b++;
192     b++;
193  }
194}
195
196
197__if_exists(IF_EXISTS::Type) {
198  int var23;
199}
200
201__if_exists(IF_EXISTS::Type_not) {
202 this wont compile.
203}
204
205__if_not_exists(IF_EXISTS::Type) {
206 this wont compile.
207}
208
209__if_not_exists(IF_EXISTS::Type_not) {
210  int var244;
211}
212
213int __identifier(generic) = 3;
214
215
216int main () {
217  // Necessary to force instantiation in -fdelayed-template-parsing mode.
218  test_late_defined_uuid<int>();
219  redundant_typename<int>();
220  missing_template_keyword<int>();
221}
222
223