Francois Pichet | 913b7bf | 2010-12-20 03:51:03 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-extensions |
Nick Lewycky | 141ecfe | 2010-10-12 16:46:35 +0000 | [diff] [blame] | 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 | |
Francois Pichet | dfaa5fb | 2011-01-31 04:54:32 +0000 | [diff] [blame] | 25 | class class_attr { |
| 26 | public: |
| 27 | class_attr([SA_Pre(Null=SA_No,NullTerminated=SA_Yes)] int a) |
| 28 | { |
| 29 | } |
| 30 | }; |
| 31 | |
| 32 | |
Nick Lewycky | 141ecfe | 2010-10-12 16:46:35 +0000 | [diff] [blame] | 33 | |
Francois Pichet | 913b7bf | 2010-12-20 03:51:03 +0000 | [diff] [blame] | 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 | |
Francois Pichet | 6915c52 | 2010-12-27 01:32:00 +0000 | [diff] [blame] | 59 | struct __declspec(uuid("000000A0-0000-0000-C000-000000000049")) |
| 60 | struct_with_uuid2; |
| 61 | |
| 62 | struct |
| 63 | struct_with_uuid2 {} ; |
Francois Pichet | 913b7bf | 2010-12-20 03:51:03 +0000 | [diff] [blame] | 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); |
Francois Pichet | 6915c52 | 2010-12-27 01:32:00 +0000 | [diff] [blame] | 71 | __uuidof(struct_with_uuid2); |
Francois Pichet | 913b7bf | 2010-12-20 03:51:03 +0000 | [diff] [blame] | 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 | } |
Francois Pichet | 6915c52 | 2010-12-27 01:32:00 +0000 | [diff] [blame] | 86 | |
| 87 | |
| 88 | template <class T> |
| 89 | void template_uuid() |
| 90 | { |
| 91 | T expr; |
| 92 | |
| 93 | __uuidof(T); |
| 94 | __uuidof(expr); |
| 95 | } |
Francois Pichet | dbee341 | 2011-01-18 05:04:39 +0000 | [diff] [blame] | 96 | |
| 97 | |
| 98 | |
| 99 | class CtorCall { |
| 100 | public: |
| 101 | CtorCall& operator=(const CtorCall& that); |
| 102 | |
| 103 | int a; |
| 104 | }; |
| 105 | |
| 106 | CtorCall& CtorCall::operator=(const CtorCall& that) |
| 107 | { |
| 108 | if (this != &that) { |
| 109 | this->CtorCall::~CtorCall(); |
| 110 | this->CtorCall::CtorCall(that); // expected-warning {{explicit constructor calls are a Microsoft extension}} |
| 111 | } |
| 112 | return *this; |
| 113 | } |
Francois Pichet | 4147d30 | 2011-03-27 19:41:34 +0000 | [diff] [blame] | 114 | |
| 115 | template <class A> |
| 116 | class C1 { |
| 117 | public: |
| 118 | template <int B> |
| 119 | class Iterator { |
| 120 | }; |
| 121 | }; |
| 122 | |
| 123 | template<class T> |
| 124 | class C2 { |
| 125 | typename C1<T>:: /*template*/ Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}} |
| 126 | }; |
| 127 | |
| 128 | template <class T> |
| 129 | void f(){ |
| 130 | typename C1<T>:: /*template*/ Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}} |
| 131 | } |
| 132 | |
Francois Pichet | a5d318a | 2011-04-24 11:24:13 +0000 | [diff] [blame] | 133 | |
| 134 | |
| 135 | class AAAA { }; |
| 136 | |
| 137 | template <class T> |
| 138 | void redundant_typename() { |
| 139 | typename T t;// expected-warning {{expected a qualified name after 'typename'}} |
| 140 | typename AAAA a;// expected-warning {{expected a qualified name after 'typename'}} |
| 141 | t = 3; |
| 142 | } |
| 143 | |
Francois Pichet | 4147d30 | 2011-03-27 19:41:34 +0000 | [diff] [blame] | 144 | int main() { |
Francois Pichet | a5d318a | 2011-04-24 11:24:13 +0000 | [diff] [blame] | 145 | redundant_typename<int>(); |
Francois Pichet | 4147d30 | 2011-03-27 19:41:34 +0000 | [diff] [blame] | 146 | f<int>(); |
| 147 | } |
| 148 | |
| 149 | |
Francois Pichet | 0047012 | 2011-04-27 05:07:51 +0000 | [diff] [blame] | 150 | __interface MicrosoftInterface; |
| 151 | __interface MicrosoftInterface { |
| 152 | virtual void foo1() = 0; |
| 153 | virtual void foo2() = 0; |
Francois Pichet | 338d7f7 | 2011-04-28 01:59:37 +0000 | [diff] [blame^] | 154 | }; |
| 155 | |
| 156 | __int64 x7 = __int64(0); |