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