Francois Pichet | b2d899e | 2012-04-17 12:35:05 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -Wno-unused-value -Wmicrosoft -verify -fms-extensions -fms-compatibility -fdelayed-template-parsing |
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 | |
Francois Pichet | a97d24f | 2011-04-28 04:39:50 +0000 | [diff] [blame] | 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 | |
Francois Pichet | a343a41 | 2011-04-29 09:08:14 +0000 | [diff] [blame] | 104 | template <class T, const GUID& g> |
| 105 | class COM_CLASS_TEMPLATE_REF { }; |
Francois Pichet | e275a18 | 2012-04-16 04:08:35 +0000 | [diff] [blame] | 106 | typedef COM_CLASS_TEMPLATE_REF<struct_with_uuid, __uuidof(struct_with_uuid)> COM_TYPE_REF; |
Francois Pichet | a97d24f | 2011-04-28 04:39:50 +0000 | [diff] [blame] | 107 | |
Francois Pichet | 20e3c9e | 2011-05-10 00:08:32 +0000 | [diff] [blame] | 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 | |
Francois Pichet | dbee341 | 2011-01-18 05:04:39 +0000 | [diff] [blame] | 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 | } |
Francois Pichet | 4147d30 | 2011-03-27 19:41:34 +0000 | [diff] [blame] | 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> |
Francois Pichet | 20e3c9e | 2011-05-10 00:08:32 +0000 | [diff] [blame] | 146 | void missing_template_keyword(){ |
Francois Pichet | 4147d30 | 2011-03-27 19:41:34 +0000 | [diff] [blame] | 147 | typename C1<T>:: /*template*/ Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}} |
| 148 | } |
| 149 | |
Francois Pichet | a5d318a | 2011-04-24 11:24:13 +0000 | [diff] [blame] | 150 | |
| 151 | |
| 152 | class AAAA { }; |
| 153 | |
Richard Smith | 2375677 | 2012-05-14 22:43:34 +0000 | [diff] [blame] | 154 | template <typename T> |
| 155 | class SimpleTemplate {}; |
| 156 | |
Francois Pichet | a5d318a | 2011-04-24 11:24:13 +0000 | [diff] [blame] | 157 | template <class T> |
| 158 | void redundant_typename() { |
| 159 | typename T t;// expected-warning {{expected a qualified name after 'typename'}} |
| 160 | typename AAAA a;// expected-warning {{expected a qualified name after 'typename'}} |
Richard Smith | 2375677 | 2012-05-14 22:43:34 +0000 | [diff] [blame] | 161 | |
Francois Pichet | a5d318a | 2011-04-24 11:24:13 +0000 | [diff] [blame] | 162 | t = 3; |
Richard Smith | 2375677 | 2012-05-14 22:43:34 +0000 | [diff] [blame] | 163 | |
| 164 | typedef typename T* pointerT;// expected-warning {{expected a qualified name after 'typename'}} |
| 165 | typedef typename SimpleTemplate<int> templateT;// expected-warning {{expected a qualified name after 'typename'}} |
| 166 | |
| 167 | pointerT pT = &t; |
| 168 | *pT = 4; |
| 169 | |
| 170 | int var; |
| 171 | int k = typename var;// expected-error {{expected a qualified name after 'typename'}} |
Francois Pichet | a5d318a | 2011-04-24 11:24:13 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Francois Pichet | 4147d30 | 2011-03-27 19:41:34 +0000 | [diff] [blame] | 174 | |
Francois Pichet | 0047012 | 2011-04-27 05:07:51 +0000 | [diff] [blame] | 175 | __interface MicrosoftInterface; |
| 176 | __interface MicrosoftInterface { |
| 177 | virtual void foo1() = 0; |
| 178 | virtual void foo2() = 0; |
Francois Pichet | 338d7f7 | 2011-04-28 01:59:37 +0000 | [diff] [blame] | 179 | }; |
| 180 | |
Francois Pichet | 2aba711 | 2011-12-01 08:30:47 +0000 | [diff] [blame] | 181 | void interface_test() { |
| 182 | MicrosoftInterface* a; |
| 183 | a->foo1(); |
| 184 | } |
| 185 | |
Francois Pichet | 338d7f7 | 2011-04-28 01:59:37 +0000 | [diff] [blame] | 186 | __int64 x7 = __int64(0); |
Francois Pichet | 1e86269 | 2011-05-06 20:48:22 +0000 | [diff] [blame] | 187 | |
| 188 | |
Francois Pichet | 563a645 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 189 | namespace If_exists_test { |
Francois Pichet | 1e86269 | 2011-05-06 20:48:22 +0000 | [diff] [blame] | 190 | |
| 191 | class IF_EXISTS { |
| 192 | private: |
| 193 | typedef int Type; |
| 194 | }; |
| 195 | |
| 196 | int __if_exists_test() { |
Francois Pichet | 1e86269 | 2011-05-06 20:48:22 +0000 | [diff] [blame] | 197 | int b=0; |
Francois Pichet | 1e86269 | 2011-05-06 20:48:22 +0000 | [diff] [blame] | 198 | __if_exists(IF_EXISTS::Type) { |
| 199 | b++; |
| 200 | b++; |
| 201 | } |
Francois Pichet | 1e86269 | 2011-05-06 20:48:22 +0000 | [diff] [blame] | 202 | __if_exists(IF_EXISTS::Type_not) { |
| 203 | this wont compile. |
| 204 | } |
Francois Pichet | 1e86269 | 2011-05-06 20:48:22 +0000 | [diff] [blame] | 205 | __if_not_exists(IF_EXISTS::Type) { |
| 206 | this wont compile. |
| 207 | } |
Francois Pichet | 1e86269 | 2011-05-06 20:48:22 +0000 | [diff] [blame] | 208 | __if_not_exists(IF_EXISTS::Type_not) { |
| 209 | b++; |
| 210 | b++; |
| 211 | } |
Francois Pichet | f986038 | 2011-05-07 17:30:27 +0000 | [diff] [blame] | 212 | } |
Francois Pichet | 1e86269 | 2011-05-06 20:48:22 +0000 | [diff] [blame] | 213 | |
Francois Pichet | f986038 | 2011-05-07 17:30:27 +0000 | [diff] [blame] | 214 | |
| 215 | __if_exists(IF_EXISTS::Type) { |
| 216 | int var23; |
| 217 | } |
| 218 | |
| 219 | __if_exists(IF_EXISTS::Type_not) { |
| 220 | this wont compile. |
| 221 | } |
| 222 | |
| 223 | __if_not_exists(IF_EXISTS::Type) { |
| 224 | this wont compile. |
| 225 | } |
| 226 | |
| 227 | __if_not_exists(IF_EXISTS::Type_not) { |
| 228 | int var244; |
Francois Pichet | 1e86269 | 2011-05-06 20:48:22 +0000 | [diff] [blame] | 229 | } |
Francois Pichet | a23ae3f | 2011-05-07 17:47:38 +0000 | [diff] [blame] | 230 | |
Francois Pichet | 9d24a8b | 2011-12-12 23:24:39 +0000 | [diff] [blame] | 231 | int __if_exists_init_list() { |
| 232 | |
| 233 | int array1[] = {
|
| 234 | 0,
|
| 235 | __if_exists(IF_EXISTS::Type) {2, }
|
| 236 | 3
|
| 237 | };
|
| 238 | |
| 239 | int array2[] = {
|
| 240 | 0,
|
| 241 | __if_exists(IF_EXISTS::Type_not) { this wont compile }
|
| 242 | 3
|
| 243 | };
|
| 244 |
|
| 245 | int array3[] = {
|
| 246 | 0,
|
| 247 | __if_not_exists(IF_EXISTS::Type_not) {2, }
|
| 248 | 3
|
| 249 | };
|
| 250 | |
| 251 | int array4[] = {
|
| 252 | 0,
|
| 253 | __if_not_exists(IF_EXISTS::Type) { this wont compile }
|
| 254 | 3
|
| 255 | };
|
| 256 | |
| 257 | } |
| 258 | |
| 259 | |
Francois Pichet | 563a645 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 260 | class IF_EXISTS_CLASS_TEST { |
| 261 | __if_exists(IF_EXISTS::Type) { |
| 262 | // __if_exists, __if_not_exists can nest |
| 263 | __if_not_exists(IF_EXISTS::Type_not) { |
| 264 | int var123; |
| 265 | } |
| 266 | int var23; |
| 267 | } |
| 268 | |
| 269 | __if_exists(IF_EXISTS::Type_not) { |
| 270 | this wont compile. |
| 271 | } |
| 272 | |
| 273 | __if_not_exists(IF_EXISTS::Type) { |
| 274 | this wont compile. |
| 275 | } |
| 276 | |
| 277 | __if_not_exists(IF_EXISTS::Type_not) { |
| 278 | int var244; |
| 279 | } |
| 280 | }; |
| 281 | |
| 282 | } |
| 283 | |
| 284 | |
Francois Pichet | a23ae3f | 2011-05-07 17:47:38 +0000 | [diff] [blame] | 285 | int __identifier(generic) = 3; |
| 286 | |
Francois Pichet | 6a24747 | 2011-05-11 02:14:46 +0000 | [diff] [blame] | 287 | class inline_definition_pure_spec { |
| 288 | virtual int f() = 0 { return 0; }// expected-warning {{function definition with pure-specifier is a Microsoft extension}} |
| 289 | virtual int f2() = 0; |
| 290 | }; |
| 291 | |
Francois Pichet | 20e3c9e | 2011-05-10 00:08:32 +0000 | [diff] [blame] | 292 | |
| 293 | int main () { |
| 294 | // Necessary to force instantiation in -fdelayed-template-parsing mode. |
| 295 | test_late_defined_uuid<int>(); |
| 296 | redundant_typename<int>(); |
| 297 | missing_template_keyword<int>(); |
| 298 | } |
| 299 | |
John McCall | 6c20222 | 2012-05-22 21:28:07 +0000 | [diff] [blame] | 300 | namespace access_protected_PTM { |
| 301 | class A { |
| 302 | protected: |
| 303 | void f(); // expected-note {{must name member using the type of the current context 'access_protected_PTM::B'}} |
| 304 | }; |
Francois Pichet | b2d899e | 2012-04-17 12:35:05 +0000 | [diff] [blame] | 305 | |
John McCall | 6c20222 | 2012-05-22 21:28:07 +0000 | [diff] [blame] | 306 | class B : public A{ |
| 307 | public: |
| 308 | void test_access(); |
| 309 | static void test_access_static(); |
| 310 | }; |
Francois Pichet | b2d899e | 2012-04-17 12:35:05 +0000 | [diff] [blame] | 311 | |
John McCall | 6c20222 | 2012-05-22 21:28:07 +0000 | [diff] [blame] | 312 | void B::test_access() { |
| 313 | &A::f; // expected-error {{'f' is a protected member of 'access_protected_PTM::A'}} |
| 314 | } |
| 315 | |
| 316 | void B::test_access_static() { |
| 317 | &A::f; |
| 318 | } |
| 319 | } |
John McCall | c052dbb | 2012-05-22 21:28:12 +0000 | [diff] [blame] | 320 | |
| 321 | namespace Inheritance { |
| 322 | class __single_inheritance A; |
| 323 | class __multiple_inheritance B; |
| 324 | class __virtual_inheritance C; |
| 325 | } |