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 namespace PR16911 { 120 struct __declspec(uuid("{12345678-1234-1234-1234-1234567890aB}")) uuid; 121 struct __declspec(uuid("{12345678-1234-1234-1234-1234567890aB}")) uuid2; 122 123 template <typename T, typename T2> 124 struct thing { 125 }; 126 127 struct empty {}; 128 struct inher : public thing<empty, uuid2> {}; 129 130 struct __declspec(uuid("{12345678-1234-1234-1234-1234567890aB}")) uuid; 131 const struct _GUID *w = &__uuidof(inher); // expected-error{{cannot call operator __uuidof on a type with no GUID}} 132 const struct _GUID *x = &__uuidof(thing<uuid, inher>); 133 const struct _GUID *y = &__uuidof(thing<uuid2, uuid>); // expected-error{{cannot call operator __uuidof on a type with multiple GUIDs}} 134 thing<uuid2, uuid> thing_obj = thing<uuid2, uuid>(); 135 const struct _GUID *z = &__uuidof(thing_obj); // expected-error{{cannot call operator __uuidof on a type with multiple GUIDs}} 136 } 137 138 class CtorCall { 139 public: 140 CtorCall& operator=(const CtorCall& that); 141 142 int a; 143 }; 144 145 CtorCall& CtorCall::operator=(const CtorCall& that) 146 { 147 if (this != &that) { 148 this->CtorCall::~CtorCall(); 149 this->CtorCall::CtorCall(that); // expected-warning {{explicit constructor calls are a Microsoft extension}} 150 } 151 return *this; 152 } 153 154 template <class A> 155 class C1 { 156 public: 157 template <int B> 158 class Iterator { 159 }; 160 }; 161 162 template<class T> 163 class C2 { 164 typename C1<T>:: /*template*/ Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}} 165 }; 166 167 template <class T> 168 void missing_template_keyword(){ 169 typename C1<T>:: /*template*/ Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}} 170 } 171 172 173 174 class AAAA { 175 typedef int D; 176 }; 177 178 template <typename T> 179 class SimpleTemplate {}; 180 181 template <class T> 182 void redundant_typename() { 183 typename T t;// expected-warning {{expected a qualified name after 'typename'}} 184 typename AAAA a;// expected-warning {{expected a qualified name after 'typename'}} 185 186 t = 3; 187 188 typedef typename T* pointerT;// expected-warning {{expected a qualified name after 'typename'}} 189 typedef typename SimpleTemplate<int> templateT;// expected-warning {{expected a qualified name after 'typename'}} 190 191 pointerT pT = &t; 192 *pT = 4; 193 194 int var; 195 int k = typename var;// expected-error {{expected a qualified name after 'typename'}} 196 } 197 198 template <typename T> 199 struct TypenameWrongPlace { 200 typename typedef T::D D;// expected-warning {{expected a qualified name after 'typename'}} 201 }; 202 203 extern TypenameWrongPlace<AAAA> PR16925; 204 205 __interface MicrosoftInterface; 206 __interface MicrosoftInterface { 207 void foo1() = 0; 208 virtual void foo2() = 0; 209 }; 210 211 __interface MicrosoftDerivedInterface : public MicrosoftInterface { 212 void foo1(); 213 void foo2() override; 214 void foo3(); 215 }; 216 217 void interface_test() { 218 MicrosoftInterface* a; 219 a->foo1(); 220 MicrosoftDerivedInterface* b; 221 b->foo2(); 222 } 223 224 __int64 x7 = __int64(0); 225 226 227 namespace If_exists_test { 228 229 class IF_EXISTS { 230 private: 231 typedef int Type; 232 }; 233 234 int __if_exists_test() { 235 int b=0; 236 __if_exists(IF_EXISTS::Type) { 237 b++; 238 b++; 239 } 240 __if_exists(IF_EXISTS::Type_not) { 241 this wont compile. 242 } 243 __if_not_exists(IF_EXISTS::Type) { 244 this wont compile. 245 } 246 __if_not_exists(IF_EXISTS::Type_not) { 247 b++; 248 b++; 249 } 250 } 251 252 253 __if_exists(IF_EXISTS::Type) { 254 int var23; 255 } 256 257 __if_exists(IF_EXISTS::Type_not) { 258 this wont compile. 259 } 260 261 __if_not_exists(IF_EXISTS::Type) { 262 this wont compile. 263 } 264 265 __if_not_exists(IF_EXISTS::Type_not) { 266 int var244; 267 } 268 269 int __if_exists_init_list() { 270 271 int array1[] = { 272 0, 273 __if_exists(IF_EXISTS::Type) {2, } 274 3 275 }; 276 277 int array2[] = { 278 0, 279 __if_exists(IF_EXISTS::Type_not) { this wont compile } 280 3 281 }; 282 283 int array3[] = { 284 0, 285 __if_not_exists(IF_EXISTS::Type_not) {2, } 286 3 287 }; 288 289 int array4[] = { 290 0, 291 __if_not_exists(IF_EXISTS::Type) { this wont compile } 292 3 293 }; 294 295 } 296 297 298 class IF_EXISTS_CLASS_TEST { 299 __if_exists(IF_EXISTS::Type) { 300 // __if_exists, __if_not_exists can nest 301 __if_not_exists(IF_EXISTS::Type_not) { 302 int var123; 303 } 304 int var23; 305 } 306 307 __if_exists(IF_EXISTS::Type_not) { 308 this wont compile. 309 } 310 311 __if_not_exists(IF_EXISTS::Type) { 312 this wont compile. 313 } 314 315 __if_not_exists(IF_EXISTS::Type_not) { 316 int var244; 317 } 318 }; 319 320 } 321 322 323 int __identifier(generic) = 3; 324 325 class inline_definition_pure_spec { 326 virtual int f() = 0 { return 0; }// expected-warning {{function definition with pure-specifier is a Microsoft extension}} 327 virtual int f2() = 0; 328 }; 329 330 331 int main () { 332 // Necessary to force instantiation in -fdelayed-template-parsing mode. 333 test_late_defined_uuid<int>(); 334 redundant_typename<int>(); 335 missing_template_keyword<int>(); 336 } 337 338 namespace access_protected_PTM { 339 class A { 340 protected: 341 void f(); // expected-note {{must name member using the type of the current context 'access_protected_PTM::B'}} 342 }; 343 344 class B : public A{ 345 public: 346 void test_access(); 347 static void test_access_static(); 348 }; 349 350 void B::test_access() { 351 &A::f; // expected-error {{'f' is a protected member of 'access_protected_PTM::A'}} 352 } 353 354 void B::test_access_static() { 355 &A::f; 356 } 357 } 358 359 namespace Inheritance { 360 class __single_inheritance A; 361 class __multiple_inheritance B; 362 class __virtual_inheritance C; 363 } 364 365 struct StructWithProperty { 366 __declspec(property) int V0; // expected-error {{expected '(' after 'property'}} 367 __declspec(property()) int V1; // expected-error {{property does not specify a getter or a putter}} 368 __declspec(property(set)) int V2; // expected-error {{putter for property must be specified as 'put', not 'set'}} expected-error {{expected '=' after 'set'}} 369 __declspec(property(ptu)) int V3; // expected-error {{missing 'get=' or 'put='}} 370 __declspec(property(ptu=PutV)) int V4; // expected-error {{expected 'get' or 'put' in property declaration}} 371 __declspec(property(get)) int V5; // expected-error {{expected '=' after 'get'}} 372 __declspec(property(get&)) int V6; // expected-error {{expected '=' after 'get'}} 373 __declspec(property(get=)) int V7; // expected-error {{expected name of accessor method}} 374 __declspec(property(get=GetV)) int V8; // no-warning 375 __declspec(property(get=GetV=)) int V9; // expected-error {{expected ',' or ')' at end of property accessor list}} 376 __declspec(property(get=GetV,)) int V10; // expected-error {{expected 'get' or 'put' in property declaration}} 377 __declspec(property(get=GetV,put=SetV)) int V11; // no-warning 378 __declspec(property(get=GetV,put=SetV,get=GetV)) int V12; // expected-error {{property declaration specifies 'get' accessor twice}} 379 380 int GetV() { return 123; } 381 void SetV(int v) {} 382 }; 383 void TestProperty() { 384 StructWithProperty sp; 385 sp.V8; 386 sp.V8 = 0; // expected-error {{no setter defined for property 'V8'}} 387 int i = sp.V11; 388 sp.V11 = i++; 389 sp.V11 += 8; 390 sp.V11++; 391 ++sp.V11; 392 } 393