Francois Pichet | a39371c | 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 | 8d3a178 | 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 | |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 7 | [returnvalue:SA_Post( attr=1)] |
Nick Lewycky | 8d3a178 | 2010-10-12 16:46:35 +0000 | [diff] [blame] | 8 | int foo1([SA_Post(attr=1)] void *param); |
| 9 | |
| 10 | namespace { |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 11 | [returnvalue:SA_Post(attr=1)] |
Nick Lewycky | 8d3a178 | 2010-10-12 16:46:35 +0000 | [diff] [blame] | 12 | int foo2([SA_Post(attr=1)] void *param); |
| 13 | } |
| 14 | |
| 15 | class T { |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 16 | [returnvalue:SA_Post(attr=1)] |
Nick Lewycky | 8d3a178 | 2010-10-12 16:46:35 +0000 | [diff] [blame] | 17 | int foo3([SA_Post(attr=1)] void *param); |
| 18 | }; |
| 19 | |
| 20 | extern "C" { |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 21 | [returnvalue:SA_Post(attr=1)] |
Nick Lewycky | 8d3a178 | 2010-10-12 16:46:35 +0000 | [diff] [blame] | 22 | int foo5([SA_Post(attr=1)] void *param); |
| 23 | } |
| 24 | |
Francois Pichet | 79f3a87 | 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 | 8d3a178 | 2010-10-12 16:46:35 +0000 | [diff] [blame] | 33 | |
Francois Pichet | 9dddd40 | 2010-12-20 03:51:03 +0000 | [diff] [blame] | 34 | void uuidof_test1() |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 35 | { |
Francois Pichet | 9dddd40 | 2010-12-20 03:51:03 +0000 | [diff] [blame] | 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 | |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 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}} |
Francois Pichet | 9dddd40 | 2010-12-20 03:51:03 +0000 | [diff] [blame] | 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 | b757765 | 2010-12-27 01:32:00 +0000 | [diff] [blame] | 59 | struct __declspec(uuid("000000A0-0000-0000-C000-000000000049")) |
| 60 | struct_with_uuid2; |
| 61 | |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 62 | struct |
Francois Pichet | b757765 | 2010-12-27 01:32:00 +0000 | [diff] [blame] | 63 | struct_with_uuid2 {} ; |
Francois Pichet | 9dddd40 | 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 | b757765 | 2010-12-27 01:32:00 +0000 | [diff] [blame] | 71 | __uuidof(struct_with_uuid2); |
Francois Pichet | 9dddd40 | 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 | b757765 | 2010-12-27 01:32:00 +0000 | [diff] [blame] | 86 | |
| 87 | |
| 88 | template <class T> |
| 89 | void template_uuid() |
| 90 | { |
| 91 | T expr; |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 92 | |
Francois Pichet | b757765 | 2010-12-27 01:32:00 +0000 | [diff] [blame] | 93 | __uuidof(T); |
| 94 | __uuidof(expr); |
| 95 | } |
Francois Pichet | 6422579 | 2011-01-18 05:04:39 +0000 | [diff] [blame] | 96 | |
| 97 | |
David Majnemer | 61c39a1 | 2013-08-23 05:39:39 +0000 | [diff] [blame] | 98 | template <class T, const GUID* g = &__uuidof(T)> // expected-note {{template parameter is declared here}} |
Francois Pichet | a1c1352 | 2011-04-28 04:39:50 +0000 | [diff] [blame] | 99 | class COM_CLASS_TEMPLATE { }; |
| 100 | |
David Majnemer | 61c39a1 | 2013-08-23 05:39:39 +0000 | [diff] [blame] | 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}} |
Francois Pichet | a1c1352 | 2011-04-28 04:39:50 +0000 | [diff] [blame] | 102 | typedef COM_CLASS_TEMPLATE<struct_with_uuid> COM_TYPE_2; |
| 103 | |
Francois Pichet | c867975 | 2011-04-29 09:08:14 +0000 | [diff] [blame] | 104 | template <class T, const GUID& g> |
| 105 | class COM_CLASS_TEMPLATE_REF { }; |
Francois Pichet | 0066db9 | 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 | a1c1352 | 2011-04-28 04:39:50 +0000 | [diff] [blame] | 107 | |
Francois Pichet | 2f019ed | 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 | |
David Majnemer | 61c39a1 | 2013-08-23 05:39:39 +0000 | [diff] [blame] | 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}} |
Francois Pichet | 6422579 | 2011-01-18 05:04:39 +0000 | [diff] [blame] | 118 | |
David Majnemer | 59c0ec2 | 2013-09-07 06:59:46 +0000 | [diff] [blame^] | 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 | |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 138 | class CtorCall { |
Francois Pichet | 6422579 | 2011-01-18 05:04:39 +0000 | [diff] [blame] | 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 | } |
Francois Pichet | 4e7a2c0 | 2011-03-27 19:41:34 +0000 | [diff] [blame] | 153 | |
| 154 | template <class A> |
| 155 | class C1 { |
| 156 | public: |
| 157 | template <int B> |
| 158 | class Iterator { |
| 159 | }; |
| 160 | }; |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 161 | |
Francois Pichet | 4e7a2c0 | 2011-03-27 19:41:34 +0000 | [diff] [blame] | 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> |
Francois Pichet | 2f019ed | 2011-05-10 00:08:32 +0000 | [diff] [blame] | 168 | void missing_template_keyword(){ |
Francois Pichet | 4e7a2c0 | 2011-03-27 19:41:34 +0000 | [diff] [blame] | 169 | typename C1<T>:: /*template*/ Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}} |
| 170 | } |
| 171 | |
Francois Pichet | dd87612 | 2011-04-24 11:24:13 +0000 | [diff] [blame] | 172 | |
| 173 | |
David Majnemer | ad01851 | 2013-09-03 22:36:22 +0000 | [diff] [blame] | 174 | class AAAA { |
| 175 | typedef int D; |
| 176 | }; |
Francois Pichet | dd87612 | 2011-04-24 11:24:13 +0000 | [diff] [blame] | 177 | |
Richard Smith | b71e732 | 2012-05-14 22:43:34 +0000 | [diff] [blame] | 178 | template <typename T> |
| 179 | class SimpleTemplate {}; |
| 180 | |
Francois Pichet | dd87612 | 2011-04-24 11:24:13 +0000 | [diff] [blame] | 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'}} |
Richard Smith | b71e732 | 2012-05-14 22:43:34 +0000 | [diff] [blame] | 185 | |
Francois Pichet | dd87612 | 2011-04-24 11:24:13 +0000 | [diff] [blame] | 186 | t = 3; |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 187 | |
Richard Smith | b71e732 | 2012-05-14 22:43:34 +0000 | [diff] [blame] | 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'}} |
Francois Pichet | dd87612 | 2011-04-24 11:24:13 +0000 | [diff] [blame] | 196 | } |
| 197 | |
David Majnemer | ad01851 | 2013-09-03 22:36:22 +0000 | [diff] [blame] | 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; |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 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); |
Francois Pichet | 4a7de3e | 2011-05-06 20:48:22 +0000 | [diff] [blame] | 225 | |
| 226 | |
Francois Pichet | 8f981d5 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 227 | namespace If_exists_test { |
Francois Pichet | 4a7de3e | 2011-05-06 20:48:22 +0000 | [diff] [blame] | 228 | |
| 229 | class IF_EXISTS { |
| 230 | private: |
| 231 | typedef int Type; |
| 232 | }; |
| 233 | |
| 234 | int __if_exists_test() { |
Francois Pichet | 4a7de3e | 2011-05-06 20:48:22 +0000 | [diff] [blame] | 235 | int b=0; |
Francois Pichet | 4a7de3e | 2011-05-06 20:48:22 +0000 | [diff] [blame] | 236 | __if_exists(IF_EXISTS::Type) { |
| 237 | b++; |
| 238 | b++; |
| 239 | } |
Francois Pichet | 4a7de3e | 2011-05-06 20:48:22 +0000 | [diff] [blame] | 240 | __if_exists(IF_EXISTS::Type_not) { |
| 241 | this wont compile. |
| 242 | } |
Francois Pichet | 4a7de3e | 2011-05-06 20:48:22 +0000 | [diff] [blame] | 243 | __if_not_exists(IF_EXISTS::Type) { |
| 244 | this wont compile. |
| 245 | } |
Francois Pichet | 4a7de3e | 2011-05-06 20:48:22 +0000 | [diff] [blame] | 246 | __if_not_exists(IF_EXISTS::Type_not) { |
| 247 | b++; |
| 248 | b++; |
| 249 | } |
Francois Pichet | a5b3fcb | 2011-05-07 17:30:27 +0000 | [diff] [blame] | 250 | } |
Francois Pichet | 4a7de3e | 2011-05-06 20:48:22 +0000 | [diff] [blame] | 251 | |
Francois Pichet | a5b3fcb | 2011-05-07 17:30:27 +0000 | [diff] [blame] | 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; |
Francois Pichet | 4a7de3e | 2011-05-06 20:48:22 +0000 | [diff] [blame] | 267 | } |
Francois Pichet | 61d818c | 2011-05-07 17:47:38 +0000 | [diff] [blame] | 268 | |
Francois Pichet | 0251316 | 2011-12-12 23:24:39 +0000 | [diff] [blame] | 269 | int __if_exists_init_list() { |
| 270 | |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 271 | int array1[] = { |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 272 | 0, |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 273 | __if_exists(IF_EXISTS::Type) {2, } |
| 274 | 3 |
| 275 | }; |
Francois Pichet | 0251316 | 2011-12-12 23:24:39 +0000 | [diff] [blame] | 276 | |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 277 | int array2[] = { |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 278 | 0, |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 279 | __if_exists(IF_EXISTS::Type_not) { this wont compile } |
| 280 | 3 |
| 281 | }; |
Francois Pichet | 0251316 | 2011-12-12 23:24:39 +0000 | [diff] [blame] | 282 | |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 283 | int array3[] = { |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 284 | 0, |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 285 | __if_not_exists(IF_EXISTS::Type_not) {2, } |
| 286 | 3 |
| 287 | }; |
| 288 | |
| 289 | int array4[] = { |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 290 | 0, |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 291 | __if_not_exists(IF_EXISTS::Type) { this wont compile } |
| 292 | 3 |
| 293 | }; |
Francois Pichet | 0251316 | 2011-12-12 23:24:39 +0000 | [diff] [blame] | 294 | |
| 295 | } |
| 296 | |
| 297 | |
Francois Pichet | 8f981d5 | 2011-05-25 10:19:49 +0000 | [diff] [blame] | 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 | |
Francois Pichet | 61d818c | 2011-05-07 17:47:38 +0000 | [diff] [blame] | 323 | int __identifier(generic) = 3; |
| 324 | |
Francois Pichet | 3abc9b8 | 2011-05-11 02:14:46 +0000 | [diff] [blame] | 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 | |
Francois Pichet | 2f019ed | 2011-05-10 00:08:32 +0000 | [diff] [blame] | 330 | |
| 331 | int main () { |
| 332 | // Necessary to force instantiation in -fdelayed-template-parsing mode. |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 333 | test_late_defined_uuid<int>(); |
Francois Pichet | 2f019ed | 2011-05-10 00:08:32 +0000 | [diff] [blame] | 334 | redundant_typename<int>(); |
| 335 | missing_template_keyword<int>(); |
| 336 | } |
| 337 | |
John McCall | fa6cf4c | 2012-05-22 21:28:07 +0000 | [diff] [blame] | 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 | }; |
Francois Pichet | a39371c | 2012-04-17 12:35:05 +0000 | [diff] [blame] | 343 | |
John McCall | fa6cf4c | 2012-05-22 21:28:07 +0000 | [diff] [blame] | 344 | class B : public A{ |
| 345 | public: |
| 346 | void test_access(); |
| 347 | static void test_access_static(); |
| 348 | }; |
Francois Pichet | a39371c | 2012-04-17 12:35:05 +0000 | [diff] [blame] | 349 | |
John McCall | fa6cf4c | 2012-05-22 21:28:07 +0000 | [diff] [blame] | 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 | } |
John McCall | 8d32c05 | 2012-05-22 21:28:12 +0000 | [diff] [blame] | 358 | |
| 359 | namespace Inheritance { |
| 360 | class __single_inheritance A; |
| 361 | class __multiple_inheritance B; |
| 362 | class __virtual_inheritance C; |
| 363 | } |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 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 | } |