xref: /llvm-project/clang/test/SemaCXX/MicrosoftCompatibility.cpp (revision 1de36917d304f40af314fa0c6048eb0fd7c2740e)
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 namespace ms_predefined_types {
25   // ::type_info is a built-in forward class declaration.
26   void f(const type_info &a);
27   void f(size_t);
28 }
29 
30 
31 namespace ms_protected_scope {
32   struct C { C(); };
33 
34   int jump_over_variable_init(bool b) {
35     if (b)
36       goto foo; // expected-warning {{goto into protected scope}}
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}}
48   Y y; // expected-note {{jump bypasses variable with a non-trivial destructor}}
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() {
64   goto l2; // expected-error {{goto into protected scope}}
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 
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 }
91 
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 }
103 
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 
123 
124 namespace MissingTypename {
125 
126 template<class T> class A {
127 public:
128 	 typedef int TYPE;
129 };
130 
131 template<class T> class B {
132 public:
133 	 typedef int TYPE;
134 };
135 
136 
137 template<class T, class U>
138 class C : private A<T>, public B<U> {
139 public:
140    typedef A<T> Base1;
141    typedef B<U> Base2;
142    typedef A<U> Base3;
143 
144    A<T>::TYPE a1; // expected-warning {{missing 'typename' prior to dependent type name}}
145    Base1::TYPE a2; // expected-warning {{missing 'typename' prior to dependent type name}}
146 
147    B<U>::TYPE a3; // expected-warning {{missing 'typename' prior to dependent type name}}
148    Base2::TYPE a4; // expected-warning {{missing 'typename' prior to dependent type name}}
149 
150    A<U>::TYPE a5; // expected-error {{missing 'typename' prior to dependent type name}}
151    Base3::TYPE a6; // expected-error {{missing 'typename' prior to dependent type name}}
152  };
153 
154 class D {
155 public:
156     typedef int Type;
157 };
158 
159 template <class T>
160 void function_missing_typename(const T::Type param)// expected-warning {{missing 'typename' prior to dependent type name}}
161 {
162     const T::Type var = 2; // expected-warning {{missing 'typename' prior to dependent type name}}
163 }
164 
165 template void function_missing_typename<D>(const D::Type param);
166 
167 }
168 
169 enum ENUM2 {
170 	ENUM2_a = (enum ENUM2) 4,
171 	ENUM2_b = 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
172 	ENUM2_c = 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
173 };
174 
175 
176 namespace PR11791 {
177   template<class _Ty>
178   void del(_Ty *_Ptr) {
179     _Ptr->~_Ty();  // expected-warning {{pseudo-destructors on type void are a Microsoft extension}}
180   }
181 
182   void f() {
183     int* a = 0;
184     del((void*)a);  // expected-note {{in instantiation of function template specialization}}
185   }
186 }
187 
188 namespace IntToNullPtrConv {
189   struct Foo {
190     static const int ZERO = 0;
191     typedef void (Foo::*MemberFcnPtr)();
192   };
193 
194   struct Bar {
195     const Foo::MemberFcnPtr pB;
196   };
197 
198   Bar g_bar = { (Foo::MemberFcnPtr)Foo::ZERO };
199 
200   template<int N> int *get_n() { return N; }   // expected-warning {{expression which evaluates to zero treated as a null pointer constant}}
201   int *g_nullptr = get_n<0>();  // expected-note {{in instantiation of function template specialization}}
202 }
203