Home | History | Annotate | Download | only in Parser
      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 parameter 1 to be a string}}
     48 struct __declspec(uuid(3)) uuid_attr_bad2 { };// expected-error {{'uuid' attribute requires parameter 1 to be 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)>
     99 class COM_CLASS_TEMPLATE  { };
    100 
    101 typedef COM_CLASS_TEMPLATE<struct_with_uuid, &__uuidof(struct_with_uuid)> COM_TYPE_1;
    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 
    116 class CtorCall {
    117 public:
    118   CtorCall& operator=(const CtorCall& that);
    119 
    120   int a;
    121 };
    122 
    123 CtorCall& 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 
    132 template <class A>
    133 class C1 {
    134 public:
    135   template <int B>
    136   class Iterator {
    137   };
    138 };
    139 
    140 template<class T>
    141 class C2  {
    142   typename C1<T>:: /*template*/  Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}}
    143 };
    144 
    145 template <class T>
    146 void 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 
    152 class AAAA { };
    153 
    154 template <class T>
    155 void 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 void interface_test() {
    169   MicrosoftInterface* a;
    170   a->foo1();
    171 }
    172 
    173 __int64 x7 = __int64(0);
    174 
    175 
    176 namespace If_exists_test {
    177 
    178 class IF_EXISTS {
    179 private:
    180     typedef int Type;
    181 };
    182 
    183 int __if_exists_test() {
    184   int b=0;
    185   __if_exists(IF_EXISTS::Type) {
    186      b++;
    187      b++;
    188   }
    189   __if_exists(IF_EXISTS::Type_not) {
    190      this wont compile.
    191   }
    192   __if_not_exists(IF_EXISTS::Type) {
    193      this wont compile.
    194   }
    195   __if_not_exists(IF_EXISTS::Type_not) {
    196      b++;
    197      b++;
    198   }
    199 }
    200 
    201 
    202 __if_exists(IF_EXISTS::Type) {
    203   int var23;
    204 }
    205 
    206 __if_exists(IF_EXISTS::Type_not) {
    207  this wont compile.
    208 }
    209 
    210 __if_not_exists(IF_EXISTS::Type) {
    211  this wont compile.
    212 }
    213 
    214 __if_not_exists(IF_EXISTS::Type_not) {
    215   int var244;
    216 }
    217 
    218 int __if_exists_init_list() {
    219 
    220   int array1[] = {
    221     0,
    222     __if_exists(IF_EXISTS::Type) {2, }
    223     3
    224   };
    225 
    226   int array2[] = {
    227     0,
    228     __if_exists(IF_EXISTS::Type_not) { this wont compile }
    229     3
    230   };
    231 
    232   int array3[] = {
    233     0,
    234     __if_not_exists(IF_EXISTS::Type_not) {2, }
    235     3
    236   };
    237 
    238   int array4[] = {
    239     0,
    240     __if_not_exists(IF_EXISTS::Type) { this wont compile }
    241     3
    242   };
    243 
    244 }
    245 
    246 
    247 class IF_EXISTS_CLASS_TEST {
    248   __if_exists(IF_EXISTS::Type) {
    249     // __if_exists, __if_not_exists can nest
    250     __if_not_exists(IF_EXISTS::Type_not) {
    251       int var123;
    252     }
    253     int var23;
    254   }
    255 
    256   __if_exists(IF_EXISTS::Type_not) {
    257    this wont compile.
    258   }
    259 
    260   __if_not_exists(IF_EXISTS::Type) {
    261    this wont compile.
    262   }
    263 
    264   __if_not_exists(IF_EXISTS::Type_not) {
    265     int var244;
    266   }
    267 };
    268 
    269 }
    270 
    271 
    272 int __identifier(generic) = 3;
    273 
    274 class inline_definition_pure_spec {
    275    virtual int f() = 0 { return 0; }// expected-warning {{function definition with pure-specifier is a Microsoft extension}}
    276    virtual int f2() = 0;
    277 };
    278 
    279 
    280 int main () {
    281   // Necessary to force instantiation in -fdelayed-template-parsing mode.
    282   test_late_defined_uuid<int>();
    283   redundant_typename<int>();
    284   missing_template_keyword<int>();
    285 }
    286 
    287 
    288 
    289 
    290 namespace access_protected_PTM {
    291 
    292 class A {
    293 protected:
    294   void f(); // expected-note {{must name member using the type of the current context 'access_protected_PTM::B'}}
    295 };
    296 
    297 class B : public A{
    298 public:
    299   void test_access();
    300   static void test_access_static();
    301 };
    302 
    303 void B::test_access() {
    304   &A::f; // expected-error {{'f' is a protected member of 'access_protected_PTM::A'}}
    305 }
    306 
    307 void B::test_access_static() {
    308   &A::f;
    309 }
    310 
    311 }