David Majnemer | 28aae9c | 2015-03-18 04:15:23 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++11 -Wmicrosoft -verify -fms-compatibility -fexceptions -fcxx-exceptions -fms-compatibility-version=19.00 |
| 2 | // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++11 -Wmicrosoft -verify -fms-compatibility -fexceptions -fcxx-exceptions -fms-compatibility-version=18.00 |
Francois Pichet | 08d2fa0 | 2011-09-18 21:37:37 +0000 | [diff] [blame] | 3 | |
David Majnemer | aaf2b84 | 2015-03-18 07:53:18 +0000 | [diff] [blame] | 4 | #if defined(_HAS_CHAR16_T_LANGUAGE_SUPPORT) && _HAS_CHAR16_T_LANGUAGE_SUPPORT |
David Majnemer | 28aae9c | 2015-03-18 04:15:23 +0000 | [diff] [blame] | 5 | char16_t x; |
| 6 | char32_t y; |
David Majnemer | 28aae9c | 2015-03-18 04:15:23 +0000 | [diff] [blame] | 7 | #else |
Francois Pichet | 0e2b843 | 2012-07-22 11:32:41 +0000 | [diff] [blame] | 8 | typedef unsigned short char16_t; |
| 9 | typedef unsigned int char32_t; |
David Majnemer | aaf2b84 | 2015-03-18 07:53:18 +0000 | [diff] [blame] | 10 | #endif |
| 11 | |
David Majnemer | aaf2b84 | 2015-03-18 07:53:18 +0000 | [diff] [blame] | 12 | _Atomic(int) z; |
David Majnemer | 51fd8a0 | 2015-07-22 23:46:18 +0000 | [diff] [blame] | 13 | template <typename T> |
| 14 | struct _Atomic { |
| 15 | _Atomic() {} |
| 16 | ~_Atomic() {} |
| 17 | }; |
| 18 | template <typename T> |
| 19 | struct atomic : _Atomic<T> { |
| 20 | typedef _Atomic<T> TheBase; |
| 21 | TheBase field; |
| 22 | }; |
| 23 | _Atomic(int) alpha; |
Francois Pichet | 08d2fa0 | 2011-09-18 21:37:37 +0000 | [diff] [blame] | 24 | |
Francois Pichet | f5b24e0 | 2012-07-22 15:10:57 +0000 | [diff] [blame] | 25 | typename decltype(3) a; // expected-warning {{expected a qualified name after 'typename'}} |
| 26 | |
Francois Pichet | 08d2fa0 | 2011-09-18 21:37:37 +0000 | [diff] [blame] | 27 | namespace ms_conversion_rules { |
| 28 | |
| 29 | void f(float a); |
| 30 | void f(int a); |
| 31 | |
| 32 | void test() |
| 33 | { |
| 34 | long a = 0; |
| 35 | f((long)0); |
| 36 | f(a); |
| 37 | } |
| 38 | |
| 39 | } |
| 40 | |
Francois Pichet | 39cba53 | 2011-09-18 21:48:27 +0000 | [diff] [blame] | 41 | |
Alp Toker | ab1b1dc | 2014-01-05 06:38:18 +0000 | [diff] [blame] | 42 | namespace ms_predefined_types { |
Alp Toker | 8db6e7a | 2014-01-05 06:38:57 +0000 | [diff] [blame] | 43 | // ::type_info is a built-in forward class declaration. |
Alp Toker | ab1b1dc | 2014-01-05 06:38:18 +0000 | [diff] [blame] | 44 | void f(const type_info &a); |
David Majnemer | 1de3691 | 2014-01-14 06:19:35 +0000 | [diff] [blame] | 45 | void f(size_t); |
Alp Toker | ab1b1dc | 2014-01-05 06:38:18 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Francois Pichet | 39cba53 | 2011-09-18 21:48:27 +0000 | [diff] [blame] | 48 | |
| 49 | namespace ms_protected_scope { |
| 50 | struct C { C(); }; |
| 51 | |
| 52 | int jump_over_variable_init(bool b) { |
| 53 | if (b) |
Richard Smith | 091405d | 2014-09-06 00:24:58 +0000 | [diff] [blame] | 54 | goto foo; // expected-warning {{jump from this goto statement to its label is a Microsoft extension}} |
Francois Pichet | 39cba53 | 2011-09-18 21:48:27 +0000 | [diff] [blame] | 55 | C c; // expected-note {{jump bypasses variable initialization}} |
| 56 | foo: |
| 57 | return 1; |
| 58 | } |
| 59 | |
| 60 | struct Y { |
| 61 | ~Y(); |
| 62 | }; |
| 63 | |
| 64 | void jump_over_var_with_dtor() { |
Richard Smith | 091405d | 2014-09-06 00:24:58 +0000 | [diff] [blame] | 65 | goto end; // expected-warning{{jump from this goto statement to its label is a Microsoft extension}} |
Richard Smith | fe2750d | 2011-10-20 21:42:12 +0000 | [diff] [blame] | 66 | Y y; // expected-note {{jump bypasses variable with a non-trivial destructor}} |
Francois Pichet | 39cba53 | 2011-09-18 21:48:27 +0000 | [diff] [blame] | 67 | end: |
| 68 | ; |
| 69 | } |
| 70 | |
| 71 | void jump_over_variable_case(int c) { |
| 72 | switch (c) { |
| 73 | case 0: |
| 74 | int x = 56; // expected-note {{jump bypasses variable initialization}} |
Richard Smith | 091405d | 2014-09-06 00:24:58 +0000 | [diff] [blame] | 75 | case 1: // expected-error {{cannot jump}} |
Francois Pichet | 39cba53 | 2011-09-18 21:48:27 +0000 | [diff] [blame] | 76 | x = 10; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | |
| 81 | void exception_jump() { |
Richard Smith | 091405d | 2014-09-06 00:24:58 +0000 | [diff] [blame] | 82 | goto l2; // expected-error {{cannot jump}} |
Francois Pichet | 39cba53 | 2011-09-18 21:48:27 +0000 | [diff] [blame] | 83 | try { // expected-note {{jump bypasses initialization of try block}} |
| 84 | l2: ; |
| 85 | } catch(int) { |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | int jump_over_indirect_goto() { |
| 90 | static void *ps[] = { &&a0 }; |
Richard Smith | 091405d | 2014-09-06 00:24:58 +0000 | [diff] [blame] | 91 | goto *&&a0; // expected-warning {{jump from this goto statement to its label is a Microsoft extension}} |
Francois Pichet | 39cba53 | 2011-09-18 21:48:27 +0000 | [diff] [blame] | 92 | int a = 3; // expected-note {{jump bypasses variable initialization}} |
| 93 | a0: |
| 94 | return 0; |
| 95 | } |
| 96 | |
| 97 | } |
| 98 | |
Nico Weber | 323076f | 2012-01-23 04:01:33 +0000 | [diff] [blame] | 99 | namespace PR11826 { |
| 100 | struct pair { |
| 101 | pair(int v) { } |
| 102 | void operator=(pair&& rhs) { } |
| 103 | }; |
| 104 | void f() { |
| 105 | pair p0(3); |
| 106 | pair p = p0; |
| 107 | } |
| 108 | } |
Francois Pichet | 39cba53 | 2011-09-18 21:48:27 +0000 | [diff] [blame] | 109 | |
Nico Weber | 323076f | 2012-01-23 04:01:33 +0000 | [diff] [blame] | 110 | namespace PR11826_for_symmetry { |
| 111 | struct pair { |
| 112 | pair(int v) { } |
| 113 | pair(pair&& rhs) { } |
| 114 | }; |
| 115 | void f() { |
| 116 | pair p0(3); |
| 117 | pair p(4); |
| 118 | p = p0; |
| 119 | } |
| 120 | } |
Francois Pichet | 39cba53 | 2011-09-18 21:48:27 +0000 | [diff] [blame] | 121 | |
Nico Weber | 33a362e | 2012-01-23 04:08:13 +0000 | [diff] [blame] | 122 | namespace ms_using_declaration_bug { |
| 123 | |
| 124 | class A { |
| 125 | public: |
| 126 | int f(); |
| 127 | }; |
| 128 | |
| 129 | class B : public A { |
| 130 | private: |
| 131 | using A::f; |
Reid Kleckner | 42063b0 | 2014-02-08 02:40:20 +0000 | [diff] [blame] | 132 | void g() { |
| 133 | f(); // no diagnostic |
| 134 | } |
Nico Weber | 33a362e | 2012-01-23 04:08:13 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
| 137 | class C : public B { |
| 138 | private: |
| 139 | using B::f; // expected-warning {{using declaration referring to inaccessible member 'ms_using_declaration_bug::B::f' (which refers to accessible member 'ms_using_declaration_bug::A::f') is a Microsoft compatibility extension}} |
| 140 | }; |
| 141 | |
| 142 | } |
| 143 | |
Alp Toker | 0abb057 | 2014-01-18 00:59:32 +0000 | [diff] [blame] | 144 | namespace using_tag_redeclaration |
| 145 | { |
| 146 | struct S; |
| 147 | namespace N { |
| 148 | using ::using_tag_redeclaration::S; |
| 149 | struct S {}; // expected-note {{previous definition is here}} |
| 150 | } |
| 151 | void f() { |
| 152 | N::S s1; |
| 153 | S s2; |
| 154 | } |
| 155 | void g() { |
| 156 | struct S; // expected-note {{forward declaration of 'S'}} |
| 157 | S s3; // expected-error {{variable has incomplete type 'S'}} |
| 158 | } |
| 159 | void h() { |
| 160 | using ::using_tag_redeclaration::S; |
| 161 | struct S {}; // expected-error {{redefinition of 'S'}} |
| 162 | } |
| 163 | } |
| 164 | |
Nico Weber | 33a362e | 2012-01-23 04:08:13 +0000 | [diff] [blame] | 165 | |
| 166 | namespace MissingTypename { |
| 167 | |
| 168 | template<class T> class A { |
| 169 | public: |
| 170 | typedef int TYPE; |
| 171 | }; |
| 172 | |
| 173 | template<class T> class B { |
| 174 | public: |
| 175 | typedef int TYPE; |
| 176 | }; |
| 177 | |
| 178 | |
| 179 | template<class T, class U> |
| 180 | class C : private A<T>, public B<U> { |
| 181 | public: |
| 182 | typedef A<T> Base1; |
| 183 | typedef B<U> Base2; |
| 184 | typedef A<U> Base3; |
| 185 | |
| 186 | A<T>::TYPE a1; // expected-warning {{missing 'typename' prior to dependent type name}} |
| 187 | Base1::TYPE a2; // expected-warning {{missing 'typename' prior to dependent type name}} |
| 188 | |
| 189 | B<U>::TYPE a3; // expected-warning {{missing 'typename' prior to dependent type name}} |
| 190 | Base2::TYPE a4; // expected-warning {{missing 'typename' prior to dependent type name}} |
| 191 | |
| 192 | A<U>::TYPE a5; // expected-error {{missing 'typename' prior to dependent type name}} |
| 193 | Base3::TYPE a6; // expected-error {{missing 'typename' prior to dependent type name}} |
| 194 | }; |
| 195 | |
| 196 | class D { |
| 197 | public: |
| 198 | typedef int Type; |
| 199 | }; |
| 200 | |
| 201 | template <class T> |
| 202 | void function_missing_typename(const T::Type param)// expected-warning {{missing 'typename' prior to dependent type name}} |
| 203 | { |
| 204 | const T::Type var = 2; // expected-warning {{missing 'typename' prior to dependent type name}} |
| 205 | } |
| 206 | |
| 207 | template void function_missing_typename<D>(const D::Type param); |
| 208 | |
| 209 | } |
| 210 | |
Francois Pichet | 2056a69 | 2012-01-21 23:26:50 +0000 | [diff] [blame] | 211 | enum ENUM2 { |
| 212 | ENUM2_a = (enum ENUM2) 4, |
| 213 | ENUM2_b = 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}} |
| 214 | ENUM2_c = 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}} |
| 215 | }; |
Nico Weber | 33a362e | 2012-01-23 04:08:13 +0000 | [diff] [blame] | 216 | |
| 217 | |
Nico Weber | 5882927 | 2012-01-23 05:50:57 +0000 | [diff] [blame] | 218 | namespace PR11791 { |
| 219 | template<class _Ty> |
| 220 | void del(_Ty *_Ptr) { |
| 221 | _Ptr->~_Ty(); // expected-warning {{pseudo-destructors on type void are a Microsoft extension}} |
| 222 | } |
| 223 | |
| 224 | void f() { |
| 225 | int* a = 0; |
| 226 | del((void*)a); // expected-note {{in instantiation of function template specialization}} |
| 227 | } |
| 228 | } |
Reid Kleckner | a5eef14 | 2013-11-12 02:22:34 +0000 | [diff] [blame] | 229 | |
| 230 | namespace IntToNullPtrConv { |
| 231 | struct Foo { |
| 232 | static const int ZERO = 0; |
| 233 | typedef void (Foo::*MemberFcnPtr)(); |
| 234 | }; |
| 235 | |
| 236 | struct Bar { |
| 237 | const Foo::MemberFcnPtr pB; |
| 238 | }; |
| 239 | |
| 240 | Bar g_bar = { (Foo::MemberFcnPtr)Foo::ZERO }; |
| 241 | |
| 242 | template<int N> int *get_n() { return N; } // expected-warning {{expression which evaluates to zero treated as a null pointer constant}} |
| 243 | int *g_nullptr = get_n<0>(); // expected-note {{in instantiation of function template specialization}} |
| 244 | } |