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