• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -verify -fms-extensions -fexceptions -fcxx-exceptions
2 
3 
4 // ::type_info is predeclared with forward class declartion
5 void f(const type_info &a);
6 
7 
8 // Microsoft doesn't validate exception specification.
9 namespace microsoft_exception_spec {
10 
11 void foo(); // expected-note {{previous declaration}}
12 void foo() throw(); // expected-warning {{exception specification in declaration does not match previous declaration}}
13 
14 void r6() throw(...); // expected-note {{previous declaration}}
15 void r6() throw(int); // expected-warning {{exception specification in declaration does not match previous declaration}}
16 
17 struct Base {
18   virtual void f2();
19   virtual void f3() throw(...);
20 };
21 
22 struct Derived : Base {
23   virtual void f2() throw(...);
24   virtual void f3();
25 };
26 
27 class A {
28   virtual ~A() throw();  // expected-note {{overridden virtual function is here}}
29 };
30 
31 class B : public A {
32   virtual ~B();  // expected-warning {{exception specification of overriding function is more lax than base version}}
33 };
34 
35 }
36 
37 // MSVC allows type definition in anonymous union and struct
38 struct A
39 {
40   union
41   {
42     int a;
43     struct B  // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
44     {
45       int c;
46     } d;
47 
48     union C   // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
49     {
50       int e;
51       int ee;
52     } f;
53 
54     typedef int D;  // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
55     struct F;  // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
56   };
57 
58   struct
59   {
60     int a2;
61 
62     struct B2  // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
63     {
64       int c2;
65     } d2;
66 
67 	union C2  // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
68     {
69       int e2;
70       int ee2;
71     } f2;
72 
73     typedef int D2;  // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
74     struct F2;  // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
75   };
76 };
77 
78 // __stdcall handling
79 struct M {
80     int __stdcall addP();
81     float __stdcall subtractP();
82 };
83 
h1(T (__stdcall M::* const)())84 template<typename T> void h1(T (__stdcall M::* const )()) { }
85 
m1()86 void m1() {
87   h1<int>(&M::addP);
88   h1(&M::subtractP);
89 }
90 
91 //MSVC allows forward enum declaration
92 enum ENUM; // expected-warning {{forward references to 'enum' types are a Microsoft extension}}
93 ENUM *var = 0;
94 ENUM var2 = (ENUM)3;
95 enum ENUM1* var3 = 0;// expected-warning {{forward references to 'enum' types are a Microsoft extension}}
96 
97 
98 enum ENUM2 {
99 	ENUM2_a = (enum ENUM2) 4,
100 	ENUM2_b = 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
101 	ENUM2_c = 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
102 };
103 
104 
105 void f(long long);
106 void f(int);
107 
main()108 int main()
109 {
110   // This is an ambiguous call in standard C++.
111   // This calls f(long long) in Microsoft mode because LL is always signed.
112   f(0xffffffffffffffffLL);
113   f(0xffffffffffffffffi64);
114 }
115 
116 // Enumeration types with a fixed underlying type.
117 const int seventeen = 17;
118 typedef int Int;
119 
120 struct X0 {
121   enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
122   enum E1 : seventeen;
123 };
124 
125 enum : long long {  // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
126   SomeValue = 0x100000000
127 };
128 
129 
130 class AAA {
f(void)131 __declspec(dllimport) void f(void) { }
132 void f2(void);
133 };
134 
f2(void)135 __declspec(dllimport) void AAA::f2(void) { // expected-error {{dllimport attribute can be applied only to symbol}}
136 
137 }
138 
139 
140 
141 template <class T>
142 class BB {
143 public:
144    void f(int g = 10 ); // expected-note {{previous definition is here}}
145 };
146 
147 template <class T>
f(int g=0)148 void BB<T>::f(int g = 0) { } // expected-warning {{redefinition of default argument}}
149 
150 
151 namespace MissingTypename {
152 
153 template<class T> class A {
154 public:
155 	 typedef int TYPE;
156 };
157 
158 template<class T> class B {
159 public:
160 	 typedef int TYPE;
161 };
162 
163 
164 template<class T, class U>
165 class C : private A<T>, public B<U> {
166 public:
167    typedef A<T> Base1;
168    typedef B<U> Base2;
169    typedef A<U> Base3;
170 
171    A<T>::TYPE a1; // expected-warning {{missing 'typename' prior to dependent type name}}
172    Base1::TYPE a2; // expected-warning {{missing 'typename' prior to dependent type name}}
173 
174    B<U>::TYPE a3; // expected-warning {{missing 'typename' prior to dependent type name}}
175    Base2::TYPE a4; // expected-warning {{missing 'typename' prior to dependent type name}}
176 
177    A<U>::TYPE a5; // expected-error {{missing 'typename' prior to dependent type name}}
178    Base3::TYPE a6; // expected-error {{missing 'typename' prior to dependent type name}}
179  };
180 
181 }
182 
183 
184 
185 
186 extern void static_func();
187 void static_func(); // expected-note {{previous declaration is here}}
188 
189 
static_func()190 static void static_func() // expected-warning {{static declaration of 'static_func' follows non-static declaration}}
191 {
192 
193 }
194 
195 long function_prototype(int a);
196 long (*function_ptr)(int a);
197 
function_to_voidptr_conv()198 void function_to_voidptr_conv() {
199    void *a1 = function_prototype;
200    void *a2 = &function_prototype;
201    void *a3 = function_ptr;
202 }
203 
204 
pointer_to_integral_type_conv(char * ptr)205 void pointer_to_integral_type_conv(char* ptr) {
206    char ch = (char)ptr;
207    short sh = (short)ptr;
208    ch = (char)ptr;
209    sh = (short)ptr;
210 }
211 
212 namespace ms_using_declaration_bug {
213 
214 class A {
215 public:
216   int f();
217 };
218 
219 class B : public A {
220 private:
221   using A::f;
222 };
223 
224 class C : public B {
225 private:
226   using B::f; // expected-warning {{using declaration refers to inaccessible member 'ms_using_declaration_bug::B::f', which refers to accessible member 'ms_using_declaration_bug::A::f', accepted for Microsoft compatibility}}
227 };
228 
229 }
230 
231 
232 
233 namespace friend_as_a_forward_decl {
234 
235 class A {
236   class Nested {
237     friend class B;
238     B* b;
239   };
240   B* b;
241 };
242 B* global_b;
243 
244 
f()245 void f()
246 {
247   class Local {
248     friend class Z;
249     Z* b;
250   };
251   Z* b;
252 }
253 
254  }