Francois Pichet | dde385d | 2011-03-29 11:38:04 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -verify -fms-extensions -fexceptions -fcxx-exceptions |
Douglas Gregor | 5c0ca52 | 2010-08-30 14:44:26 +0000 | [diff] [blame] | 2 | |
| 3 | |
| 4 | // ::type_info is predeclared with forward class declartion |
| 5 | void f(const type_info &a); |
| 6 | |
Francois Pichet | eedd467 | 2011-03-19 23:05:18 +0000 | [diff] [blame] | 7 | |
| 8 | // Microsoft doesn't validate exception specification. |
Francois Pichet | 0f16159 | 2011-05-24 02:11:43 +0000 | [diff] [blame] | 9 | namespace microsoft_exception_spec { |
| 10 | |
Douglas Gregor | 5b6f769 | 2010-08-30 15:04:51 +0000 | [diff] [blame] | 11 | void foo(); // expected-note {{previous declaration}} |
Francois Pichet | eedd467 | 2011-03-19 23:05:18 +0000 | [diff] [blame] | 12 | void foo() throw(); // expected-warning {{exception specification in declaration does not match previous declaration}} |
Douglas Gregor | 5c0ca52 | 2010-08-30 14:44:26 +0000 | [diff] [blame] | 13 | |
Francois Pichet | eedd467 | 2011-03-19 23:05:18 +0000 | [diff] [blame] | 14 | void r6() throw(...); // expected-note {{previous declaration}} |
| 15 | void r6() throw(int); // expected-warning {{exception specification in declaration does not match previous declaration}} |
Douglas Gregor | 5b6f769 | 2010-08-30 15:04:51 +0000 | [diff] [blame] | 16 | |
| 17 | struct Base { |
| 18 | virtual void f2(); |
| 19 | virtual void f3() throw(...); |
| 20 | }; |
| 21 | |
| 22 | struct Derived : Base { |
| 23 | virtual void f2() throw(...); |
| 24 | virtual void f3(); |
| 25 | }; |
Douglas Gregor | afac01d | 2010-09-01 16:29:03 +0000 | [diff] [blame] | 26 | |
Francois Pichet | 0f16159 | 2011-05-24 02:11:43 +0000 | [diff] [blame] | 27 | class A { |
| 28 | virtual ~A() throw(); // expected-note {{overridden virtual function is here}} |
| 29 | }; |
| 30 | |
| 31 | class B : public A { |
| 32 | virtual ~B(); // expected-warning {{exception specification of overriding function is more lax than base version}} |
| 33 | }; |
| 34 | |
| 35 | } |
Francois Pichet | 538e0d0 | 2010-09-08 11:32:25 +0000 | [diff] [blame] | 36 | |
| 37 | // MSVC allows type definition in anonymous union and struct |
| 38 | struct A |
| 39 | { |
| 40 | union |
| 41 | { |
| 42 | int a; |
| 43 | struct B // expected-warning {{types declared in an anonymous union are a Microsoft extension}} |
| 44 | { |
| 45 | int c; |
| 46 | } d; |
| 47 | |
| 48 | union C // expected-warning {{types declared in an anonymous union are a Microsoft extension}} |
| 49 | { |
| 50 | int e; |
| 51 | int ee; |
| 52 | } f; |
| 53 | |
| 54 | typedef int D; // expected-warning {{types declared in an anonymous union are a Microsoft extension}} |
| 55 | struct F; // expected-warning {{types declared in an anonymous union are a Microsoft extension}} |
| 56 | }; |
| 57 | |
| 58 | struct |
| 59 | { |
| 60 | int a2; |
| 61 | |
| 62 | struct B2 // expected-warning {{types declared in an anonymous struct are a Microsoft extension}} |
| 63 | { |
| 64 | int c2; |
| 65 | } d2; |
| 66 | |
| 67 | union C2 // expected-warning {{types declared in an anonymous struct are a Microsoft extension}} |
| 68 | { |
| 69 | int e2; |
| 70 | int ee2; |
| 71 | } f2; |
| 72 | |
| 73 | typedef int D2; // expected-warning {{types declared in an anonymous struct are a Microsoft extension}} |
| 74 | struct F2; // expected-warning {{types declared in an anonymous struct are a Microsoft extension}} |
| 75 | }; |
| 76 | }; |
| 77 | |
Douglas Gregor | afac01d | 2010-09-01 16:29:03 +0000 | [diff] [blame] | 78 | // __stdcall handling |
| 79 | struct M { |
| 80 | int __stdcall addP(); |
| 81 | float __stdcall subtractP(); |
| 82 | }; |
| 83 | |
Francois Pichet | 3bd9aa4 | 2011-08-18 09:59:55 +0000 | [diff] [blame] | 84 | // __unaligned handling |
| 85 | typedef char __unaligned *aligned_type; |
| 86 | |
| 87 | |
Douglas Gregor | afac01d | 2010-09-01 16:29:03 +0000 | [diff] [blame] | 88 | template<typename T> void h1(T (__stdcall M::* const )()) { } |
| 89 | |
| 90 | void m1() { |
| 91 | h1<int>(&M::addP); |
| 92 | h1(&M::subtractP); |
| 93 | } |
Francois Pichet | 8dc3abc | 2010-09-12 05:06:55 +0000 | [diff] [blame] | 94 | |
| 95 | //MSVC allows forward enum declaration |
| 96 | enum ENUM; // expected-warning {{forward references to 'enum' types are a Microsoft extension}} |
Francois Pichet | 842e7a2 | 2010-10-18 15:01:13 +0000 | [diff] [blame] | 97 | ENUM *var = 0; |
| 98 | ENUM var2 = (ENUM)3; |
| 99 | enum ENUM1* var3 = 0;// expected-warning {{forward references to 'enum' types are a Microsoft extension}} |
| 100 | |
| 101 | |
| 102 | enum ENUM2 { |
| 103 | ENUM2_a = (enum ENUM2) 4, |
| 104 | ENUM2_b = 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}} |
| 105 | ENUM2_c = 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}} |
| 106 | }; |
Francois Pichet | 5be38be | 2011-01-17 01:08:01 +0000 | [diff] [blame] | 107 | |
| 108 | |
| 109 | void f(long long); |
| 110 | void f(int); |
| 111 | |
| 112 | int main() |
| 113 | { |
| 114 | // This is an ambiguous call in standard C++. |
| 115 | // This calls f(long long) in Microsoft mode because LL is always signed. |
| 116 | f(0xffffffffffffffffLL); |
| 117 | f(0xffffffffffffffffi64); |
| 118 | } |
Douglas Gregor | 86f208c | 2011-02-22 20:32:04 +0000 | [diff] [blame] | 119 | |
| 120 | // Enumeration types with a fixed underlying type. |
| 121 | const int seventeen = 17; |
| 122 | typedef int Int; |
| 123 | |
| 124 | struct X0 { |
| 125 | enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}} |
| 126 | enum E1 : seventeen; |
| 127 | }; |
| 128 | |
Douglas Gregor | 1756ce4 | 2011-02-22 21:42:31 +0000 | [diff] [blame] | 129 | enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}} |
Douglas Gregor | 86f208c | 2011-02-22 20:32:04 +0000 | [diff] [blame] | 130 | SomeValue = 0x100000000 |
| 131 | }; |
Francois Pichet | b613cd6 | 2011-03-29 10:39:17 +0000 | [diff] [blame] | 132 | |
| 133 | |
| 134 | class AAA { |
| 135 | __declspec(dllimport) void f(void) { } |
| 136 | void f2(void); |
| 137 | }; |
| 138 | |
| 139 | __declspec(dllimport) void AAA::f2(void) { // expected-error {{dllimport attribute can be applied only to symbol}} |
| 140 | |
| 141 | } |
| 142 | |
| 143 | |
| 144 | |
Francois Pichet | 8d051e0 | 2011-04-10 03:03:52 +0000 | [diff] [blame] | 145 | template <class T> |
| 146 | class BB { |
| 147 | public: |
| 148 | void f(int g = 10 ); // expected-note {{previous definition is here}} |
| 149 | }; |
| 150 | |
| 151 | template <class T> |
| 152 | void BB<T>::f(int g = 0) { } // expected-warning {{redefinition of default argument}} |
| 153 | |
Francois Pichet | 6943e9b | 2011-04-13 02:38:49 +0000 | [diff] [blame] | 154 | |
| 155 | namespace MissingTypename { |
| 156 | |
| 157 | template<class T> class A { |
| 158 | public: |
| 159 | typedef int TYPE; |
| 160 | }; |
| 161 | |
| 162 | template<class T> class B { |
| 163 | public: |
| 164 | typedef int TYPE; |
| 165 | }; |
| 166 | |
| 167 | |
| 168 | template<class T, class U> |
| 169 | class C : private A<T>, public B<U> { |
| 170 | public: |
| 171 | typedef A<T> Base1; |
| 172 | typedef B<U> Base2; |
| 173 | typedef A<U> Base3; |
| 174 | |
| 175 | A<T>::TYPE a1; // expected-warning {{missing 'typename' prior to dependent type name}} |
| 176 | Base1::TYPE a2; // expected-warning {{missing 'typename' prior to dependent type name}} |
| 177 | |
| 178 | B<U>::TYPE a3; // expected-warning {{missing 'typename' prior to dependent type name}} |
| 179 | Base2::TYPE a4; // expected-warning {{missing 'typename' prior to dependent type name}} |
| 180 | |
| 181 | A<U>::TYPE a5; // expected-error {{missing 'typename' prior to dependent type name}} |
| 182 | Base3::TYPE a6; // expected-error {{missing 'typename' prior to dependent type name}} |
| 183 | }; |
| 184 | |
Francois Pichet | 2e510a0 | 2011-04-22 08:14:00 +0000 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | extern void static_func(); |
| 191 | void static_func(); // expected-note {{previous declaration is here}} |
| 192 | |
| 193 | |
| 194 | static void static_func() // expected-warning {{static declaration of 'static_func' follows non-static declaration}} |
| 195 | { |
| 196 | |
Francois Pichet | a8ef3ac | 2011-05-08 22:52:41 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | long function_prototype(int a); |
| 200 | long (*function_ptr)(int a); |
| 201 | |
| 202 | void function_to_voidptr_conv() { |
| 203 | void *a1 = function_prototype; |
| 204 | void *a2 = &function_prototype; |
Francois Pichet | b594fac | 2011-05-08 23:15:10 +0000 | [diff] [blame] | 205 | void *a3 = function_ptr; |
Francois Pichet | a8ef3ac | 2011-05-08 22:52:41 +0000 | [diff] [blame] | 206 | } |
Francois Pichet | 30aff5b | 2011-05-11 22:13:54 +0000 | [diff] [blame] | 207 | |
| 208 | |
| 209 | void pointer_to_integral_type_conv(char* ptr) { |
| 210 | char ch = (char)ptr; |
| 211 | short sh = (short)ptr; |
| 212 | ch = (char)ptr; |
| 213 | sh = (short)ptr; |
| 214 | } |
Francois Pichet | b2ee830 | 2011-05-23 03:43:44 +0000 | [diff] [blame] | 215 | |
| 216 | namespace ms_using_declaration_bug { |
| 217 | |
| 218 | class A { |
| 219 | public: |
| 220 | int f(); |
| 221 | }; |
| 222 | |
| 223 | class B : public A { |
| 224 | private: |
| 225 | using A::f; |
| 226 | }; |
| 227 | |
| 228 | class C : public B { |
| 229 | private: |
| 230 | using B::f; // expected-warning {{using declaration refers to inaccessible member 'ms_using_declaration_bug::B::f', which refers to accessible member 'ms_using_declaration_bug::A::f', accepted for Microsoft compatibility}} |
| 231 | }; |
| 232 | |
Francois Pichet | b474603 | 2011-06-01 04:14:20 +0000 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | |
| 236 | |
| 237 | namespace friend_as_a_forward_decl { |
| 238 | |
| 239 | class A { |
| 240 | class Nested { |
| 241 | friend class B; |
| 242 | B* b; |
| 243 | }; |
| 244 | B* b; |
| 245 | }; |
| 246 | B* global_b; |
| 247 | |
| 248 | |
| 249 | void f() |
| 250 | { |
| 251 | class Local { |
| 252 | friend class Z; |
| 253 | Z* b; |
| 254 | }; |
| 255 | Z* b; |
| 256 | } |
| 257 | |
Francois Pichet | c985b88 | 2011-09-13 10:26:51 +0000 | [diff] [blame^] | 258 | } |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | namespace ms_protected_scope { |
| 270 | struct C { C(); }; |
| 271 | |
| 272 | int jump_over_variable_init(bool b) { |
| 273 | if (b) |
| 274 | goto foo; // expected-warning {{illegal goto into protected scope}} |
| 275 | C c; // expected-note {{jump bypasses variable initialization}} |
| 276 | foo: |
| 277 | return 1; |
| 278 | } |
| 279 | |
| 280 | struct Y { |
| 281 | ~Y(); |
| 282 | }; |
| 283 | |
| 284 | void jump_over_var_with_dtor() { |
| 285 | goto end; // expected-warning{{goto into protected scope}} |
| 286 | Y y; // expected-note {{jump bypasses variable initialization}} |
| 287 | end: |
| 288 | ; |
| 289 | } |
| 290 | |
| 291 | void jump_over_variable_case(int c) { |
| 292 | switch (c) { |
| 293 | case 0: |
| 294 | int x = 56; // expected-note {{jump bypasses variable initialization}} |
| 295 | case 1: // expected-error {{switch case is in protected scope}} |
| 296 | x = 10; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | |
| 301 | void exception_jump() { |
| 302 | goto l2; // expected-error {{illegal goto into protected scope}} |
| 303 | try { // expected-note {{jump bypasses initialization of try block}} |
| 304 | l2: ; |
| 305 | } catch(int) { |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | } |
| 310 | |
| 311 | |
| 312 | |