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