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