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