brintos

brintos / llvm-project-archived public Read only

0
0
Text · 17.7 KiB · e32d7fa Raw
488 lines · cpp
1// 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-parsing2 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);37}38 39typedef struct _GUID40{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-warning {{encoding prefix 'L' on an unevaluated string literal has no effect and is incompatible with c++2c}}48struct __declspec(uuid(3)) uuid_attr_bad2 { };// expected-error {{expected string literal as argument of 'uuid' attribute}}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[uuid("000000000000-0000-1234-000000000047")] struct uuid_attr_bad6 { };// expected-error {{uuid attribute contains a malformed GUID}}53 54__declspec(uuid("000000A0-0000-0000-C000-000000000046")) int i; // expected-warning {{'uuid' attribute only applies to structs, unions, classes, and enums}}55 56struct __declspec(uuid("000000A0-0000-0000-C000-000000000046"))57struct_with_uuid { };58struct struct_without_uuid { };59 60struct base {61  int a;62};63struct derived : base {64  // Can't apply a UUID to a using declaration.65  [uuid("000000A0-0000-0000-C000-00000000004A")] using base::a; // expected-error {{expected member name}}66};67 68struct __declspec(uuid("000000A0-0000-0000-C000-000000000049"))69struct_with_uuid2;70 71[uuid("000000A0-0000-0000-C000-000000000049")] struct struct_with_uuid3; // expected-warning{{specifying 'uuid' as an ATL attribute is deprecated; use __declspec instead}}72 73struct74struct_with_uuid2 {} ;75 76enum __declspec(uuid("000000A0-0000-0000-C000-000000000046"))77enum_with_uuid { };78enum enum_without_uuid { };79 80int __declspec(uuid("000000A0-0000-0000-C000-000000000046")) inappropriate_uuid; // expected-warning {{'uuid' attribute only applies to}}81 82int uuid_sema_test()83{84   struct_with_uuid var_with_uuid[1];85   struct_without_uuid var_without_uuid[1];86 87   __uuidof(struct_with_uuid);88   __uuidof(struct_with_uuid2);89   __uuidof(struct_with_uuid3);90   __uuidof(struct_without_uuid); // expected-error {{cannot call operator __uuidof on a type with no GUID}}91   __uuidof(struct_with_uuid*);92   __uuidof(struct_without_uuid*); // expected-error {{cannot call operator __uuidof on a type with no GUID}}93   __uuidof(struct_with_uuid[1]);94   __uuidof(struct_with_uuid*[1]); // expected-error {{cannot call operator __uuidof on a type with no GUID}}95   __uuidof(const struct_with_uuid[1][1]);96   __uuidof(const struct_with_uuid*[1][1]); // expected-error {{cannot call operator __uuidof on a type with no GUID}}97 98   __uuidof(enum_with_uuid);99   __uuidof(enum_without_uuid); // expected-error {{cannot call operator __uuidof on a type with no GUID}}100   __uuidof(enum_with_uuid*);101   __uuidof(enum_without_uuid*); // expected-error {{cannot call operator __uuidof on a type with no GUID}}102   __uuidof(enum_with_uuid[1]);103   __uuidof(enum_with_uuid*[1]); // expected-error {{cannot call operator __uuidof on a type with no GUID}}104   __uuidof(const enum_with_uuid[1][1]);105   __uuidof(const enum_with_uuid*[1][1]); // expected-error {{cannot call operator __uuidof on a type with no GUID}}106 107   __uuidof(var_with_uuid);108   __uuidof(var_without_uuid);// expected-error {{cannot call operator __uuidof on a type with no GUID}}109   __uuidof(var_with_uuid[1]);110   __uuidof(var_without_uuid[1]);// expected-error {{cannot call operator __uuidof on a type with no GUID}}111   __uuidof(&var_with_uuid[1]);112   __uuidof(&var_without_uuid[1]);// expected-error {{cannot call operator __uuidof on a type with no GUID}}113 114   __uuidof(0);115   __uuidof(1);// expected-error {{cannot call operator __uuidof on a type with no GUID}}116}117 118 119template <class T>120void template_uuid()121{122   T expr;123 124   __uuidof(T);125   __uuidof(expr);126}127 128 129template <class T, const GUID* g = &__uuidof(T)> // expected-note {{template parameter is declared here}}130class COM_CLASS_TEMPLATE  { };131 132typedef 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}}133typedef COM_CLASS_TEMPLATE<struct_with_uuid> COM_TYPE_2;134 135template <class T, const GUID& g>136class COM_CLASS_TEMPLATE_REF  { };137typedef COM_CLASS_TEMPLATE_REF<struct_with_uuid, __uuidof(struct_with_uuid)> COM_TYPE_REF;138 139  struct late_defined_uuid;140  template<typename T>141  void test_late_defined_uuid() {142    __uuidof(late_defined_uuid);143  }144  struct __declspec(uuid("000000A0-0000-0000-C000-000000000049")) late_defined_uuid;145 146COM_CLASS_TEMPLATE_REF<int, __uuidof(struct_with_uuid)> good_template_arg;147 148COM_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 struct _GUID *') must have its address taken}}149 150namespace PR16911 {151struct __declspec(uuid("{12345678-1234-1234-1234-1234567890aB}")) uuid;152struct __declspec(uuid("{12345678-1234-1234-1234-1234567890aB}")) uuid2;153 154template <typename T, typename T2>155struct thing {156};157 158struct empty {};159struct inher : public thing<empty, uuid2> {};160 161struct __declspec(uuid("{12345678-1234-1234-1234-1234567890aB}")) uuid;162const struct _GUID *w = &__uuidof(inher); // expected-error{{cannot call operator __uuidof on a type with no GUID}}163const struct _GUID *x = &__uuidof(thing<uuid, inher>);164const struct _GUID *y = &__uuidof(thing<uuid2, uuid>); // expected-error{{cannot call operator __uuidof on a type with multiple GUIDs}}165thing<uuid2, uuid> thing_obj = thing<uuid2, uuid>();166const struct _GUID *z = &__uuidof(thing_obj); // expected-error{{cannot call operator __uuidof on a type with multiple GUIDs}}167}168 169class CtorCall {170public:171  CtorCall& operator=(const CtorCall& that);172 173  int a;174};175 176CtorCall& CtorCall::operator=(const CtorCall& that)177{178    if (this != &that) {179        this->CtorCall::~CtorCall();180        this->CtorCall::CtorCall(that); // expected-warning {{explicit constructor calls are a Microsoft extension}}181    }182    return *this;183}184 185template <class A>186class C1 {187public:188  template <int B>189  class Iterator {190  };191};192 193template<class T>194class C2  {195  typename C1<T>:: /*template*/  Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}}196};197 198template <class T>199void missing_template_keyword(){200  typename C1<T>:: /*template*/ Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}}201}202 203 204 205class AAAA {206   typedef int D;207};208 209template <typename T>210class SimpleTemplate {};211 212template <class T>213void redundant_typename() {214   typename T t;// expected-warning {{expected a qualified name after 'typename'}}215   typename AAAA a;// expected-warning {{expected a qualified name after 'typename'}}216 217   t = 3;218 219   typedef typename T* pointerT;// expected-warning {{expected a qualified name after 'typename'}}220   typedef typename SimpleTemplate<int> templateT;// expected-warning {{expected a qualified name after 'typename'}}221 222   pointerT pT = &t;223   *pT = 4;224 225   int var;226   int k = typename var;// expected-error {{expected a qualified name after 'typename'}}227}228 229template <typename T>230struct TypenameWrongPlace {231  typename typedef T::D D;// expected-warning {{expected a qualified name after 'typename'}}232};233 234extern TypenameWrongPlace<AAAA> PR16925;235 236__interface MicrosoftInterface;237__interface MicrosoftInterface {238   void foo1() = 0; // expected-note {{overridden virtual function is here}}239   virtual void foo2() = 0;240};241 242__interface MicrosoftDerivedInterface : public MicrosoftInterface {243  void foo1(); // expected-warning {{'foo1' overrides a member function but is not marked 'override'}}244  void foo2() override;245  void foo3();246};247 248void interface_test() {249  MicrosoftInterface* a;250  a->foo1();251  MicrosoftDerivedInterface* b;252  b->foo2();253}254 255__int64 x7 = __int64(0);256_int64 x8 = _int64(0);257static_assert(sizeof(_int64) == 8, "");258static_assert(sizeof(_int32) == 4, "");259static_assert(sizeof(_int16) == 2, "");260static_assert(sizeof(_int8) == 1, "");261 262int __identifier(generic) = 3;263int __identifier(int) = 4;264struct __identifier(class) { __identifier(class) *__identifier(for); };265__identifier(class) __identifier(struct) = { &__identifier(struct) };266 267int __identifier for; // expected-error {{missing '(' after '__identifier'}}268int __identifier(else} = __identifier(for); // expected-error {{missing ')' after identifier}} expected-note {{to match this '('}}269#define identifier_weird(x) __identifier(x270int k = identifier_weird(if)); // expected-error {{use of undeclared identifier 'if'}}271 272extern int __identifier(and);273 274int __identifier("baz") = 0;275int bar = baz;276 277void mangled_function();278extern "C" void __identifier("?mangled_function@@YAXXZ")() {}279 280void f() {281  __identifier(() // expected-error {{cannot convert '(' token to an identifier}}282  __identifier(void) // expected-error {{use of undeclared identifier 'void'}}283  __identifier()) // expected-error {{cannot convert ')' token to an identifier}}284  // FIXME: We should pick a friendlier display name for this token kind.285  __identifier(1) // expected-error {{cannot convert <numeric_constant> token to an identifier}}286  __identifier(+) // expected-error {{cannot convert '+' token to an identifier}}287  __identifier(;) // expected-error {{cannot convert ';' token to an identifier}}288  __identifier("1"); // expected-error {{use of undeclared identifier '1'}}289  __identifier("+"); // expected-error {{use of undeclared identifier '+'}}290  __identifier(";"); // expected-error {{use of undeclared identifier ';'}}291}292 293class inline_definition_pure_spec {294   virtual int f() = 0 { return 0; }// expected-warning {{function definition with pure-specifier is a Microsoft extension}}295   virtual int f2() = 0;296};297 298struct pure_virtual_dtor {299  virtual ~pure_virtual_dtor() = 0;300};301pure_virtual_dtor::~pure_virtual_dtor() { }302 303struct pure_virtual_dtor_inline {304  virtual ~pure_virtual_dtor_inline() = 0 { }// expected-warning {{function definition with pure-specifier is a Microsoft extension}}305};306 307template<typename T> struct pure_virtual_dtor_template {308  virtual ~pure_virtual_dtor_template() = 0;309};310template<typename T> pure_virtual_dtor_template<T>::~pure_virtual_dtor_template() {}311template struct pure_virtual_dtor_template<int>;312 313template<typename T> struct pure_virtual_dtor_template_inline {314    virtual ~pure_virtual_dtor_template_inline() = 0 {}315    // expected-warning@-1 2{{function definition with pure-specifier is a Microsoft extension}}316};317template struct pure_virtual_dtor_template_inline<int>;318// expected-note@-1 {{in instantiation of member function}}319 320int main () {321  // Necessary to force instantiation in -fdelayed-template-parsing mode.322  test_late_defined_uuid<int>();323  redundant_typename<int>();324  missing_template_keyword<int>();325}326 327namespace access_protected_PTM {328  class A {329  protected:330    void f(); // expected-note {{must name member using the type of the current context 'access_protected_PTM::B'}}331  };332 333  class B : public A{334  public:335    void test_access();336    static void test_access_static();337  };338 339  void B::test_access() {340    &A::f; // expected-error {{'f' is a protected member of 'access_protected_PTM::A'}}341  }342 343  void B::test_access_static() {344    &A::f;345  }346}347 348namespace Inheritance {349  class __single_inheritance A;350  class __multiple_inheritance B;351  class __virtual_inheritance C;352}353 354struct StructWithProperty {355  __declspec(property) int V0; // expected-error {{expected '(' after 'property'}}356  __declspec(property()) int V1; // expected-error {{property does not specify a getter or a putter}}357  __declspec(property(set)) int V2; // expected-error {{putter for property must be specified as 'put', not 'set'}} expected-error {{expected '=' after 'set'}}358  __declspec(property(ptu)) int V3; // expected-error {{missing 'get=' or 'put='}}359  __declspec(property(ptu=PutV)) int V4; // expected-error {{expected 'get' or 'put' in property declaration}}360  __declspec(property(get)) int V5; // expected-error {{expected '=' after 'get'}}361  __declspec(property(get&)) int V6; // expected-error {{expected '=' after 'get'}}362  __declspec(property(get=)) int V7; // expected-error {{expected name of accessor method}}363  __declspec(property(get=GetV)) int V8; // no-warning364  __declspec(property(get=GetV=)) int V9; // expected-error {{expected ',' or ')' at end of property accessor list}}365  __declspec(property(get=GetV,)) int V10; // expected-error {{expected 'get' or 'put' in property declaration}}366  __declspec(property(get=GetV,put=SetV)) int V11; // no-warning367  __declspec(property(get=GetV,put=SetV,get=GetV)) int V12; // expected-error {{property declaration specifies 'get' accessor twice}}368  __declspec(property(get=GetV)) int V13 = 3; // expected-error {{property declaration cannot have a default member initializer}}369 370  int GetV() { return 123; }371  void SetV(int v) {}372};373void TestProperty() {374  StructWithProperty sp;375  sp.V8;376  sp.V8 = 0; // expected-error {{no setter defined for property 'V8'}}377  int i = sp.V11;378  sp.V11 = i++;379  sp.V11 += 8;380  sp.V11++;381  ++sp.V11;382}383 384//expected-warning@+1 {{C++ operator 'and' (aka '&&') used as a macro name}}385#define and foo386 387struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) __declspec(novtable) IUnknown {};388 389typedef bool (__stdcall __stdcall *blarg)(int);390 391void local_callconv() {392  bool (__stdcall *p)(int);393}394 395struct S7 {396	int foo() { return 12; }397	__declspec(property(get=foo) deprecated) int t; // expected-note {{'t' has been explicitly marked deprecated here}}398};399 400// Technically, this is legal (though it does nothing)401__declspec() void quux( void ) {402  struct S7 s;403  int i = s.t;	// expected-warning {{'t' is deprecated}}404}405 406void *_alloca(int);407 408void foo(void) {409  __declspec(align(16)) int *buffer = (int *)_alloca(9);410}411 412template <int *>413struct NullptrArg {};414NullptrArg<nullptr> a;415 416// Ignored type qualifiers after comma in declarator lists417typedef int ignored_quals_dummy1, const volatile __ptr32 __ptr64 __w64 __unaligned __sptr __uptr ignored_quals1; // expected-warning {{qualifiers after comma in declarator list are ignored}}418typedef void(*ignored_quals_dummy2)(), __fastcall ignored_quals2; // expected-warning {{qualifiers after comma in declarator list are ignored}}419typedef void(*ignored_quals_dummy3)(), __stdcall ignored_quals3; // expected-warning {{qualifiers after comma in declarator list are ignored}}420typedef void(*ignored_quals_dummy4)(), __thiscall ignored_quals4; // expected-warning {{qualifiers after comma in declarator list are ignored}}421typedef void(*ignored_quals_dummy5)(), __cdecl ignored_quals5; // expected-warning {{qualifiers after comma in declarator list are ignored}}422typedef void(*ignored_quals_dummy6)(), __vectorcall ignored_quals6; // expected-warning {{qualifiers after comma in declarator list are ignored}}423 424namespace {425bool f(int);426template <typename T>427struct A {428  constexpr A(T t) {429    __assume(f(t)); // expected-warning{{assumption is ignored because it contains (potential) side-effects}}430  }431  constexpr bool g() { return false; }432};433constexpr A<int> h() {434  A<int> b(0); // expected-note {{in instantiation of member function}}435  return b;436}437static_assert(h().g() == false, "");438}439 440namespace {441__declspec(align(16)) struct align_before_key1 {};442__declspec(align(16)) struct align_before_key2 {} align_before_key2_var;443__declspec(align(16)) struct align_before_key3 {} *align_before_key3_var;444static_assert(__alignof(struct align_before_key1) == 16, "");445static_assert(__alignof(struct align_before_key2) == 16, "");446static_assert(__alignof(struct align_before_key3) == 16, "");447}448 449namespace PR24027 {450struct S {451  template <typename T>452  S(T);453} f([] {});454}455 456namespace pr36638 {457// Make sure we accept __unaligned method qualifiers on member function458// pointers.459struct A;460void (A::*mp1)(int) __unaligned;461}462 463namespace enum_class {464  // MSVC allows opaque-enum-declaration syntax anywhere an465  // elaborated-type-specifier can appear.466  // FIXME: Most of these are missing warnings.467  enum E0 *p0; // expected-warning {{Microsoft extension}}468  enum class E1 : int *p1;469  enum E2 : int *p2;470  enum class E3 *p3;471  auto f4() -> enum class E4 { return {}; }472  auto f5() -> enum E5 : int { return {}; } // FIXME: MSVC rejects this and crashes if the body is {}.473  auto f6() -> enum E6 { return {}; } // expected-warning {{Microsoft extension}}474 475  // MSVC does not perform disambiguation for a colon that could introduce an476  // enum-base or a bit-field.477  enum E {};478  struct S {479    enum E : int(1); // expected-error {{anonymous bit-field}}480    enum E : int : 1; // OK, bit-field481    enum F : int a = {}; // OK, default member initializer482    // MSVC produces a "C4353 constant 0 as function expression" for this,483    // considering the final {} to be part of the bit-width. We follow P0683R1484    // and treat it as a default member initializer.485    enum E : int : int{}{}; // expected-error {{anonymous bit-field cannot have a default member initializer}}486  };487}488