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