Bob Wilson | 7c73083 | 2015-07-20 22:57:31 +0000 | [diff] [blame] | 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-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}} |
Nico Weber | 05e1dad | 2016-09-03 03:25:22 +0000 | [diff] [blame] | 52 | [uuid("000000000000-0000-1234-000000000047")] struct uuid_attr_bad6 { };// expected-error {{uuid attribute contains a malformed GUID}} |
Francois Pichet | 9dddd40 | 2010-12-20 03:51:03 +0000 | [diff] [blame] | 53 | |
Aaron Ballman | 60e705e | 2013-11-24 20:58:02 +0000 | [diff] [blame] | 54 | __declspec(uuid("000000A0-0000-0000-C000-000000000046")) int i; // expected-warning {{'uuid' attribute only applies to classes}} |
Francois Pichet | 9dddd40 | 2010-12-20 03:51:03 +0000 | [diff] [blame] | 55 | |
| 56 | struct __declspec(uuid("000000A0-0000-0000-C000-000000000046")) |
| 57 | struct_with_uuid { }; |
| 58 | struct struct_without_uuid { }; |
| 59 | |
Francois Pichet | b757765 | 2010-12-27 01:32:00 +0000 | [diff] [blame] | 60 | struct __declspec(uuid("000000A0-0000-0000-C000-000000000049")) |
| 61 | struct_with_uuid2; |
| 62 | |
Nico Weber | 05e1dad | 2016-09-03 03:25:22 +0000 | [diff] [blame] | 63 | [uuid("000000A0-0000-0000-C000-000000000049")] struct struct_with_uuid3; |
| 64 | |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 65 | struct |
Francois Pichet | b757765 | 2010-12-27 01:32:00 +0000 | [diff] [blame] | 66 | struct_with_uuid2 {} ; |
Francois Pichet | 9dddd40 | 2010-12-20 03:51:03 +0000 | [diff] [blame] | 67 | |
Reid Kleckner | e516eab | 2016-12-13 18:58:09 +0000 | [diff] [blame] | 68 | enum __declspec(uuid("000000A0-0000-0000-C000-000000000046")) |
| 69 | enum_with_uuid { }; |
| 70 | enum enum_without_uuid { }; |
| 71 | |
| 72 | int __declspec(uuid("000000A0-0000-0000-C000-000000000046")) inappropriate_uuid; // expected-warning {{'uuid' attribute only applies to classes and enumerations}} |
| 73 | |
Francois Pichet | 9dddd40 | 2010-12-20 03:51:03 +0000 | [diff] [blame] | 74 | int uuid_sema_test() |
| 75 | { |
| 76 | struct_with_uuid var_with_uuid[1]; |
| 77 | struct_without_uuid var_without_uuid[1]; |
| 78 | |
| 79 | __uuidof(struct_with_uuid); |
Francois Pichet | b757765 | 2010-12-27 01:32:00 +0000 | [diff] [blame] | 80 | __uuidof(struct_with_uuid2); |
Nico Weber | 05e1dad | 2016-09-03 03:25:22 +0000 | [diff] [blame] | 81 | __uuidof(struct_with_uuid3); |
Francois Pichet | 9dddd40 | 2010-12-20 03:51:03 +0000 | [diff] [blame] | 82 | __uuidof(struct_without_uuid); // expected-error {{cannot call operator __uuidof on a type with no GUID}} |
| 83 | __uuidof(struct_with_uuid*); |
| 84 | __uuidof(struct_without_uuid*); // expected-error {{cannot call operator __uuidof on a type with no GUID}} |
David Majnemer | 68c880b | 2013-09-27 07:57:34 +0000 | [diff] [blame] | 85 | __uuidof(struct_with_uuid[1]); |
| 86 | __uuidof(struct_with_uuid*[1]); // expected-error {{cannot call operator __uuidof on a type with no GUID}} |
| 87 | __uuidof(const struct_with_uuid[1][1]); |
| 88 | __uuidof(const struct_with_uuid*[1][1]); // expected-error {{cannot call operator __uuidof on a type with no GUID}} |
Francois Pichet | 9dddd40 | 2010-12-20 03:51:03 +0000 | [diff] [blame] | 89 | |
Reid Kleckner | e516eab | 2016-12-13 18:58:09 +0000 | [diff] [blame] | 90 | __uuidof(enum_with_uuid); |
| 91 | __uuidof(enum_without_uuid); // expected-error {{cannot call operator __uuidof on a type with no GUID}} |
| 92 | __uuidof(enum_with_uuid*); |
| 93 | __uuidof(enum_without_uuid*); // expected-error {{cannot call operator __uuidof on a type with no GUID}} |
| 94 | __uuidof(enum_with_uuid[1]); |
| 95 | __uuidof(enum_with_uuid*[1]); // expected-error {{cannot call operator __uuidof on a type with no GUID}} |
| 96 | __uuidof(const enum_with_uuid[1][1]); |
| 97 | __uuidof(const enum_with_uuid*[1][1]); // expected-error {{cannot call operator __uuidof on a type with no GUID}} |
| 98 | |
Francois Pichet | 9dddd40 | 2010-12-20 03:51:03 +0000 | [diff] [blame] | 99 | __uuidof(var_with_uuid); |
| 100 | __uuidof(var_without_uuid);// expected-error {{cannot call operator __uuidof on a type with no GUID}} |
| 101 | __uuidof(var_with_uuid[1]); |
| 102 | __uuidof(var_without_uuid[1]);// expected-error {{cannot call operator __uuidof on a type with no GUID}} |
| 103 | __uuidof(&var_with_uuid[1]); |
| 104 | __uuidof(&var_without_uuid[1]);// expected-error {{cannot call operator __uuidof on a type with no GUID}} |
| 105 | |
| 106 | __uuidof(0); |
| 107 | __uuidof(1);// expected-error {{cannot call operator __uuidof on a type with no GUID}} |
| 108 | } |
Francois Pichet | b757765 | 2010-12-27 01:32:00 +0000 | [diff] [blame] | 109 | |
| 110 | |
| 111 | template <class T> |
| 112 | void template_uuid() |
| 113 | { |
| 114 | T expr; |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 115 | |
Francois Pichet | b757765 | 2010-12-27 01:32:00 +0000 | [diff] [blame] | 116 | __uuidof(T); |
| 117 | __uuidof(expr); |
| 118 | } |
Francois Pichet | 6422579 | 2011-01-18 05:04:39 +0000 | [diff] [blame] | 119 | |
| 120 | |
David Majnemer | 61c39a1 | 2013-08-23 05:39:39 +0000 | [diff] [blame] | 121 | 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] | 122 | class COM_CLASS_TEMPLATE { }; |
| 123 | |
David Majnemer | 61c39a1 | 2013-08-23 05:39:39 +0000 | [diff] [blame] | 124 | 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] | 125 | typedef COM_CLASS_TEMPLATE<struct_with_uuid> COM_TYPE_2; |
| 126 | |
Francois Pichet | c867975 | 2011-04-29 09:08:14 +0000 | [diff] [blame] | 127 | template <class T, const GUID& g> |
| 128 | class COM_CLASS_TEMPLATE_REF { }; |
Francois Pichet | 0066db9 | 2012-04-16 04:08:35 +0000 | [diff] [blame] | 129 | 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] | 130 | |
Francois Pichet | 2f019ed | 2011-05-10 00:08:32 +0000 | [diff] [blame] | 131 | struct late_defined_uuid; |
| 132 | template<typename T> |
| 133 | void test_late_defined_uuid() { |
| 134 | __uuidof(late_defined_uuid); |
| 135 | } |
| 136 | struct __declspec(uuid("000000A0-0000-0000-C000-000000000049")) late_defined_uuid; |
| 137 | |
David Majnemer | 61c39a1 | 2013-08-23 05:39:39 +0000 | [diff] [blame] | 138 | COM_CLASS_TEMPLATE_REF<int, __uuidof(struct_with_uuid)> good_template_arg; |
| 139 | |
David Majnemer | 5c734ad | 2014-08-14 00:49:23 +0000 | [diff] [blame] | 140 | 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] | 141 | |
David Majnemer | 59c0ec2 | 2013-09-07 06:59:46 +0000 | [diff] [blame] | 142 | namespace PR16911 { |
| 143 | struct __declspec(uuid("{12345678-1234-1234-1234-1234567890aB}")) uuid; |
| 144 | struct __declspec(uuid("{12345678-1234-1234-1234-1234567890aB}")) uuid2; |
| 145 | |
| 146 | template <typename T, typename T2> |
| 147 | struct thing { |
| 148 | }; |
| 149 | |
| 150 | struct empty {}; |
| 151 | struct inher : public thing<empty, uuid2> {}; |
| 152 | |
| 153 | struct __declspec(uuid("{12345678-1234-1234-1234-1234567890aB}")) uuid; |
| 154 | const struct _GUID *w = &__uuidof(inher); // expected-error{{cannot call operator __uuidof on a type with no GUID}} |
| 155 | const struct _GUID *x = &__uuidof(thing<uuid, inher>); |
| 156 | const struct _GUID *y = &__uuidof(thing<uuid2, uuid>); // expected-error{{cannot call operator __uuidof on a type with multiple GUIDs}} |
| 157 | thing<uuid2, uuid> thing_obj = thing<uuid2, uuid>(); |
| 158 | const struct _GUID *z = &__uuidof(thing_obj); // expected-error{{cannot call operator __uuidof on a type with multiple GUIDs}} |
| 159 | } |
| 160 | |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 161 | class CtorCall { |
Francois Pichet | 6422579 | 2011-01-18 05:04:39 +0000 | [diff] [blame] | 162 | public: |
| 163 | CtorCall& operator=(const CtorCall& that); |
| 164 | |
| 165 | int a; |
| 166 | }; |
| 167 | |
| 168 | CtorCall& CtorCall::operator=(const CtorCall& that) |
| 169 | { |
| 170 | if (this != &that) { |
| 171 | this->CtorCall::~CtorCall(); |
| 172 | this->CtorCall::CtorCall(that); // expected-warning {{explicit constructor calls are a Microsoft extension}} |
| 173 | } |
| 174 | return *this; |
| 175 | } |
Francois Pichet | 4e7a2c0 | 2011-03-27 19:41:34 +0000 | [diff] [blame] | 176 | |
| 177 | template <class A> |
| 178 | class C1 { |
| 179 | public: |
| 180 | template <int B> |
| 181 | class Iterator { |
| 182 | }; |
| 183 | }; |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 184 | |
Francois Pichet | 4e7a2c0 | 2011-03-27 19:41:34 +0000 | [diff] [blame] | 185 | template<class T> |
| 186 | class C2 { |
| 187 | typename C1<T>:: /*template*/ Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}} |
| 188 | }; |
| 189 | |
| 190 | template <class T> |
Francois Pichet | 2f019ed | 2011-05-10 00:08:32 +0000 | [diff] [blame] | 191 | void missing_template_keyword(){ |
Francois Pichet | 4e7a2c0 | 2011-03-27 19:41:34 +0000 | [diff] [blame] | 192 | typename C1<T>:: /*template*/ Iterator<0> Mypos; // expected-warning {{use 'template' keyword to treat 'Iterator' as a dependent template name}} |
| 193 | } |
| 194 | |
Francois Pichet | dd87612 | 2011-04-24 11:24:13 +0000 | [diff] [blame] | 195 | |
| 196 | |
David Majnemer | ad01851 | 2013-09-03 22:36:22 +0000 | [diff] [blame] | 197 | class AAAA { |
| 198 | typedef int D; |
| 199 | }; |
Francois Pichet | dd87612 | 2011-04-24 11:24:13 +0000 | [diff] [blame] | 200 | |
Richard Smith | b71e732 | 2012-05-14 22:43:34 +0000 | [diff] [blame] | 201 | template <typename T> |
| 202 | class SimpleTemplate {}; |
| 203 | |
Francois Pichet | dd87612 | 2011-04-24 11:24:13 +0000 | [diff] [blame] | 204 | template <class T> |
| 205 | void redundant_typename() { |
| 206 | typename T t;// expected-warning {{expected a qualified name after 'typename'}} |
| 207 | typename AAAA a;// expected-warning {{expected a qualified name after 'typename'}} |
Richard Smith | b71e732 | 2012-05-14 22:43:34 +0000 | [diff] [blame] | 208 | |
Francois Pichet | dd87612 | 2011-04-24 11:24:13 +0000 | [diff] [blame] | 209 | t = 3; |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 210 | |
Richard Smith | b71e732 | 2012-05-14 22:43:34 +0000 | [diff] [blame] | 211 | typedef typename T* pointerT;// expected-warning {{expected a qualified name after 'typename'}} |
| 212 | typedef typename SimpleTemplate<int> templateT;// expected-warning {{expected a qualified name after 'typename'}} |
| 213 | |
| 214 | pointerT pT = &t; |
| 215 | *pT = 4; |
| 216 | |
| 217 | int var; |
| 218 | int k = typename var;// expected-error {{expected a qualified name after 'typename'}} |
Francois Pichet | dd87612 | 2011-04-24 11:24:13 +0000 | [diff] [blame] | 219 | } |
| 220 | |
David Majnemer | ad01851 | 2013-09-03 22:36:22 +0000 | [diff] [blame] | 221 | template <typename T> |
| 222 | struct TypenameWrongPlace { |
| 223 | typename typedef T::D D;// expected-warning {{expected a qualified name after 'typename'}} |
| 224 | }; |
| 225 | |
| 226 | extern TypenameWrongPlace<AAAA> PR16925; |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 227 | |
| 228 | __interface MicrosoftInterface; |
| 229 | __interface MicrosoftInterface { |
Fariborz Jahanian | f920a0a | 2014-10-27 19:11:51 +0000 | [diff] [blame] | 230 | void foo1() = 0; // expected-note {{overridden virtual function is here}} |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 231 | virtual void foo2() = 0; |
| 232 | }; |
| 233 | |
| 234 | __interface MicrosoftDerivedInterface : public MicrosoftInterface { |
Fariborz Jahanian | f920a0a | 2014-10-27 19:11:51 +0000 | [diff] [blame] | 235 | void foo1(); // expected-warning {{'foo1' overrides a member function but is not marked 'override'}} |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 236 | void foo2() override; |
| 237 | void foo3(); |
| 238 | }; |
| 239 | |
| 240 | void interface_test() { |
| 241 | MicrosoftInterface* a; |
| 242 | a->foo1(); |
| 243 | MicrosoftDerivedInterface* b; |
| 244 | b->foo2(); |
| 245 | } |
| 246 | |
| 247 | __int64 x7 = __int64(0); |
Reid Kleckner | efd1375 | 2014-08-22 16:52:57 +0000 | [diff] [blame] | 248 | _int64 x8 = _int64(0); |
| 249 | static_assert(sizeof(_int64) == 8, ""); |
| 250 | static_assert(sizeof(_int32) == 4, ""); |
| 251 | static_assert(sizeof(_int16) == 2, ""); |
| 252 | static_assert(sizeof(_int8) == 1, ""); |
Francois Pichet | 4a7de3e | 2011-05-06 20:48:22 +0000 | [diff] [blame] | 253 | |
Francois Pichet | 61d818c | 2011-05-07 17:47:38 +0000 | [diff] [blame] | 254 | int __identifier(generic) = 3; |
Richard Smith | ae38508 | 2014-03-15 00:06:08 +0000 | [diff] [blame] | 255 | int __identifier(int) = 4; |
| 256 | struct __identifier(class) { __identifier(class) *__identifier(for); }; |
| 257 | __identifier(class) __identifier(struct) = { &__identifier(struct) }; |
| 258 | |
| 259 | int __identifier for; // expected-error {{missing '(' after '__identifier'}} |
| 260 | int __identifier(else} = __identifier(for); // expected-error {{missing ')' after identifier}} expected-note {{to match this '('}} |
| 261 | #define identifier_weird(x) __identifier(x |
| 262 | int k = identifier_weird(if)); // expected-error {{use of undeclared identifier 'if'}} |
| 263 | |
| 264 | // This is a bit weird, but the alternative tokens aren't keywords, and this |
| 265 | // behavior matches MSVC. FIXME: Consider supporting this anyway. |
| 266 | extern int __identifier(and) r; // expected-error {{cannot convert '&&' token to an identifier}} |
| 267 | |
| 268 | void f() { |
| 269 | __identifier(() // expected-error {{cannot convert '(' token to an identifier}} |
| 270 | __identifier(void) // expected-error {{use of undeclared identifier 'void'}} |
| 271 | __identifier()) // expected-error {{cannot convert ')' token to an identifier}} |
| 272 | // FIXME: We should pick a friendlier display name for this token kind. |
| 273 | __identifier(1) // expected-error {{cannot convert <numeric_constant> token to an identifier}} |
| 274 | __identifier(+) // expected-error {{cannot convert '+' token to an identifier}} |
| 275 | __identifier("foo") // expected-error {{cannot convert <string_literal> token to an identifier}} |
| 276 | __identifier(;) // expected-error {{cannot convert ';' token to an identifier}} |
| 277 | } |
Francois Pichet | 61d818c | 2011-05-07 17:47:38 +0000 | [diff] [blame] | 278 | |
Francois Pichet | 3abc9b8 | 2011-05-11 02:14:46 +0000 | [diff] [blame] | 279 | class inline_definition_pure_spec { |
| 280 | virtual int f() = 0 { return 0; }// expected-warning {{function definition with pure-specifier is a Microsoft extension}} |
| 281 | virtual int f2() = 0; |
| 282 | }; |
| 283 | |
Reid Kleckner | be7a446 | 2013-10-08 22:45:29 +0000 | [diff] [blame] | 284 | struct pure_virtual_dtor { |
| 285 | virtual ~pure_virtual_dtor() = 0; |
| 286 | }; |
| 287 | pure_virtual_dtor::~pure_virtual_dtor() { } |
| 288 | |
| 289 | struct pure_virtual_dtor_inline { |
| 290 | virtual ~pure_virtual_dtor_inline() = 0 { }// expected-warning {{function definition with pure-specifier is a Microsoft extension}} |
| 291 | }; |
| 292 | |
Francois Pichet | 2f019ed | 2011-05-10 00:08:32 +0000 | [diff] [blame] | 293 | |
| 294 | int main () { |
| 295 | // Necessary to force instantiation in -fdelayed-template-parsing mode. |
Aaron Ballman | 3bf758c | 2013-07-30 01:31:03 +0000 | [diff] [blame] | 296 | test_late_defined_uuid<int>(); |
Francois Pichet | 2f019ed | 2011-05-10 00:08:32 +0000 | [diff] [blame] | 297 | redundant_typename<int>(); |
| 298 | missing_template_keyword<int>(); |
| 299 | } |
| 300 | |
John McCall | fa6cf4c | 2012-05-22 21:28:07 +0000 | [diff] [blame] | 301 | namespace access_protected_PTM { |
| 302 | class A { |
| 303 | protected: |
| 304 | void f(); // expected-note {{must name member using the type of the current context 'access_protected_PTM::B'}} |
| 305 | }; |
Francois Pichet | a39371c | 2012-04-17 12:35:05 +0000 | [diff] [blame] | 306 | |
John McCall | fa6cf4c | 2012-05-22 21:28:07 +0000 | [diff] [blame] | 307 | class B : public A{ |
| 308 | public: |
| 309 | void test_access(); |
| 310 | static void test_access_static(); |
| 311 | }; |
Francois Pichet | a39371c | 2012-04-17 12:35:05 +0000 | [diff] [blame] | 312 | |
John McCall | fa6cf4c | 2012-05-22 21:28:07 +0000 | [diff] [blame] | 313 | void B::test_access() { |
| 314 | &A::f; // expected-error {{'f' is a protected member of 'access_protected_PTM::A'}} |
| 315 | } |
| 316 | |
| 317 | void B::test_access_static() { |
| 318 | &A::f; |
| 319 | } |
| 320 | } |
John McCall | 8d32c05 | 2012-05-22 21:28:12 +0000 | [diff] [blame] | 321 | |
| 322 | namespace Inheritance { |
| 323 | class __single_inheritance A; |
| 324 | class __multiple_inheritance B; |
| 325 | class __virtual_inheritance C; |
| 326 | } |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 327 | |
| 328 | struct StructWithProperty { |
| 329 | __declspec(property) int V0; // expected-error {{expected '(' after 'property'}} |
| 330 | __declspec(property()) int V1; // expected-error {{property does not specify a getter or a putter}} |
| 331 | __declspec(property(set)) int V2; // expected-error {{putter for property must be specified as 'put', not 'set'}} expected-error {{expected '=' after 'set'}} |
| 332 | __declspec(property(ptu)) int V3; // expected-error {{missing 'get=' or 'put='}} |
| 333 | __declspec(property(ptu=PutV)) int V4; // expected-error {{expected 'get' or 'put' in property declaration}} |
| 334 | __declspec(property(get)) int V5; // expected-error {{expected '=' after 'get'}} |
| 335 | __declspec(property(get&)) int V6; // expected-error {{expected '=' after 'get'}} |
| 336 | __declspec(property(get=)) int V7; // expected-error {{expected name of accessor method}} |
| 337 | __declspec(property(get=GetV)) int V8; // no-warning |
| 338 | __declspec(property(get=GetV=)) int V9; // expected-error {{expected ',' or ')' at end of property accessor list}} |
| 339 | __declspec(property(get=GetV,)) int V10; // expected-error {{expected 'get' or 'put' in property declaration}} |
| 340 | __declspec(property(get=GetV,put=SetV)) int V11; // no-warning |
| 341 | __declspec(property(get=GetV,put=SetV,get=GetV)) int V12; // expected-error {{property declaration specifies 'get' accessor twice}} |
David Majnemer | 87ff66c | 2014-12-13 11:34:16 +0000 | [diff] [blame] | 342 | __declspec(property(get=GetV)) int V13 = 3; // expected-error {{property declaration cannot have an in-class initializer}} |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 343 | |
| 344 | int GetV() { return 123; } |
| 345 | void SetV(int v) {} |
| 346 | }; |
| 347 | void TestProperty() { |
| 348 | StructWithProperty sp; |
| 349 | sp.V8; |
| 350 | sp.V8 = 0; // expected-error {{no setter defined for property 'V8'}} |
| 351 | int i = sp.V11; |
| 352 | sp.V11 = i++; |
| 353 | sp.V11 += 8; |
| 354 | sp.V11++; |
| 355 | ++sp.V11; |
| 356 | } |
Alp Toker | e03e9e1 | 2014-05-31 16:32:22 +0000 | [diff] [blame] | 357 | |
| 358 | //expected-warning@+1 {{C++ operator 'and' (aka '&&') used as a macro name}} |
| 359 | #define and foo |
Aaron Ballman | 1c8a5d7 | 2014-07-06 20:04:10 +0000 | [diff] [blame] | 360 | |
David Majnemer | 129f417 | 2015-02-02 10:22:20 +0000 | [diff] [blame] | 361 | struct __declspec(uuid("00000000-0000-0000-C000-000000000046")) __declspec(novtable) IUnknown {}; |
Aaron Ballman | 1c8a5d7 | 2014-07-06 20:04:10 +0000 | [diff] [blame] | 362 | |
| 363 | typedef bool (__stdcall __stdcall *blarg)(int); |
| 364 | |
| 365 | void local_callconv() { |
| 366 | bool (__stdcall *p)(int); |
| 367 | } |
| 368 | |
| 369 | struct S7 { |
| 370 | int foo() { return 12; } |
| 371 | __declspec(property(get=foo) deprecated) int t; // expected-note {{'t' has been explicitly marked deprecated here}} |
| 372 | }; |
| 373 | |
| 374 | // Technically, this is legal (though it does nothing) |
| 375 | __declspec() void quux( void ) { |
| 376 | struct S7 s; |
| 377 | int i = s.t; // expected-warning {{'t' is deprecated}} |
| 378 | } |
| 379 | |
| 380 | void *_alloca(int); |
| 381 | |
| 382 | void foo(void) { |
| 383 | __declspec(align(16)) int *buffer = (int *)_alloca(9); |
| 384 | } |
David Majnemer | 5c734ad | 2014-08-14 00:49:23 +0000 | [diff] [blame] | 385 | |
| 386 | template <int *> |
| 387 | struct NullptrArg {}; |
| 388 | NullptrArg<nullptr> a; |
Nico Rieck | eaaae27 | 2014-12-04 23:31:08 +0000 | [diff] [blame] | 389 | |
| 390 | // Ignored type qualifiers after comma in declarator lists |
| 391 | typedef int ignored_quals_dummy1, const volatile __ptr32 __ptr64 __w64 __unaligned __sptr __uptr ignored_quals1; // expected-warning {{qualifiers after comma in declarator list are ignored}} |
| 392 | typedef void(*ignored_quals_dummy2)(), __fastcall ignored_quals2; // expected-warning {{qualifiers after comma in declarator list are ignored}} |
| 393 | typedef void(*ignored_quals_dummy3)(), __stdcall ignored_quals3; // expected-warning {{qualifiers after comma in declarator list are ignored}} |
| 394 | typedef void(*ignored_quals_dummy4)(), __thiscall ignored_quals4; // expected-warning {{qualifiers after comma in declarator list are ignored}} |
| 395 | typedef void(*ignored_quals_dummy5)(), __cdecl ignored_quals5; // expected-warning {{qualifiers after comma in declarator list are ignored}} |
| 396 | typedef void(*ignored_quals_dummy6)(), __vectorcall ignored_quals6; // expected-warning {{qualifiers after comma in declarator list are ignored}} |
David Majnemer | 5123664 | 2015-02-26 00:57:33 +0000 | [diff] [blame] | 397 | |
| 398 | namespace { |
| 399 | bool f(int); |
| 400 | template <typename T> |
| 401 | struct A { |
| 402 | constexpr A(T t) { |
| 403 | __assume(f(t)); // expected-warning{{the argument to '__assume' has side effects that will be discarded}} |
| 404 | } |
| 405 | constexpr bool g() { return false; } |
| 406 | }; |
| 407 | constexpr A<int> h() { |
| 408 | A<int> b(0); // expected-note {{in instantiation of member function}} |
| 409 | return b; |
| 410 | } |
| 411 | static_assert(h().g() == false, ""); |
| 412 | } |
David Majnemer | 936b411 | 2015-04-19 07:53:29 +0000 | [diff] [blame] | 413 | |
| 414 | namespace { |
| 415 | __declspec(align(16)) struct align_before_key1 {}; |
| 416 | __declspec(align(16)) struct align_before_key2 {} align_before_key2_var; |
| 417 | __declspec(align(16)) struct align_before_key3 {} *align_before_key3_var; |
| 418 | static_assert(__alignof(struct align_before_key1) == 16, ""); |
| 419 | static_assert(__alignof(struct align_before_key2) == 16, ""); |
| 420 | static_assert(__alignof(struct align_before_key3) == 16, ""); |
| 421 | } |
David Majnemer | e4752e75 | 2015-07-08 05:55:00 +0000 | [diff] [blame] | 422 | |
| 423 | namespace PR24027 { |
| 424 | struct S { |
| 425 | template <typename T> |
| 426 | S(T); |
| 427 | } f([] {}); |
| 428 | } |