1 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++11 -Wmicrosoft -verify -fms-compatibility -fexceptions -fcxx-exceptions -fms-compatibility-version=19.28
2 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++11 -Wmicrosoft -verify -fms-compatibility -fexceptions -fcxx-exceptions -fms-compatibility-version=19.27
3 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++11 -Wmicrosoft -verify -fms-compatibility -fexceptions -fcxx-exceptions -fms-compatibility-version=19.00
4 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++11 -Wmicrosoft -verify -fms-compatibility -fexceptions -fcxx-exceptions -fms-compatibility-version=18.00
5 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++17 -Wmicrosoft -verify -fms-compatibility -fexceptions -fcxx-exceptions
8 #if defined(_HAS_CHAR16_T_LANGUAGE_SUPPORT) && _HAS_CHAR16_T_LANGUAGE_SUPPORT
12 typedef unsigned short char16_t
;
13 typedef unsigned int char32_t
;
23 struct atomic
: _Atomic
<T
> {
24 typedef _Atomic
<T
> TheBase
;
29 typename
decltype(3) a
; // expected-warning {{expected a qualified name after 'typename'}}
31 namespace ms_conversion_rules
{
36 // expected-note@-3 2 {{candidate function}}
37 // expected-note@-3 2 {{candidate function}}
46 // expected-error@-3 {{call to 'f' is ambiguous}}
47 // expected-error@-3 {{call to 'f' is ambiguous}}
54 namespace ms_predefined_types
{
55 // ::type_info is a built-in forward class declaration.
56 void f(const type_info
&a
);
61 namespace ms_protected_scope
{
64 int jump_over_variable_init(bool b
) {
66 goto foo
; // expected-warning {{jump from this goto statement to its label is a Microsoft extension}}
67 C c
; // expected-note {{jump bypasses variable initialization}}
76 void jump_over_var_with_dtor() {
77 goto end
; // expected-warning{{jump from this goto statement to its label is a Microsoft extension}}
78 Y y
; // expected-note {{jump bypasses variable with a non-trivial destructor}}
83 void jump_over_variable_case(int c
) {
86 int x
= 56; // expected-note {{jump bypasses variable initialization}}
87 case 1: // expected-error {{cannot jump}}
93 void exception_jump() {
94 goto l2
; // expected-error {{cannot jump}}
95 try { // expected-note {{jump bypasses initialization of try block}}
101 int jump_over_indirect_goto() {
102 static void *ps
[] = { &&a0
};
103 goto *&&a0
; // expected-warning {{jump from this goto statement to its label is a Microsoft extension}}
104 int a
= 3; // expected-note {{jump bypasses variable initialization}}
115 void operator=(pair
&& rhs
) { } // expected-note {{copy constructor is implicitly deleted because 'pair' has a user-declared move assignment operator}}
117 void operator=(pair
&& rhs
) { }
123 pair p
= p0
; // expected-error {{call to implicitly-deleted copy constructor of 'pair'}}
130 namespace PR11826_for_symmetry
{
134 pair(pair
&& rhs
) { } // expected-note {{copy assignment operator is implicitly deleted because 'pair' has a user-declared move constructor}}
143 p
= p0
; // expected-error {{object of type 'pair' cannot be assigned because its copy assignment operator is implicitly deleted}}
150 namespace ms_using_declaration_bug
{
161 f(); // no diagnostic
167 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}}
172 namespace using_tag_redeclaration
176 using ::using_tag_redeclaration::S
;
177 struct S
{}; // expected-note {{previous definition is here}}
184 struct S
; // expected-note {{forward declaration of 'S'}}
185 S s3
; // expected-error {{variable has incomplete type 'S'}}
188 using ::using_tag_redeclaration::S
;
189 struct S
{}; // expected-error {{redefinition of 'S'}}
194 namespace MissingTypename
{
196 template<class T
> class A
{
201 template<class T
> class B
{
207 template<class T
, class U
>
208 class C
: private A
<T
>, public B
<U
> {
214 A
<T
>::TYPE a1
; // expected-warning {{missing 'typename' prior to dependent type name}}
215 Base1::TYPE a2
; // expected-warning {{missing 'typename' prior to dependent type name}}
217 B
<U
>::TYPE a3
; // expected-warning {{missing 'typename' prior to dependent type name}}
218 Base2::TYPE a4
; // expected-warning {{missing 'typename' prior to dependent type name}}
220 A
<U
>::TYPE a5
; // expected-error {{missing 'typename' prior to dependent type name}}
221 Base3::TYPE a6
; // expected-error {{missing 'typename' prior to dependent type name}}
230 void function_missing_typename(const T::Type param
)// expected-warning {{missing 'typename' prior to dependent type name}}
232 const T::Type var
= 2; // expected-warning {{missing 'typename' prior to dependent type name}}
235 template void function_missing_typename
<D
>(const D::Type param
);
239 //MSVC allows forward enum declaration
240 enum ENUM
; // expected-warning {{forward references to 'enum' types are a Microsoft extension}}
243 enum ENUM1
* var3
= 0;// expected-warning {{forward references to 'enum' types are a Microsoft extension}}
246 enum ENUM1
; // This way round is fine.
249 ENUM2_a
= (enum ENUM2
) 0,
250 ENUM2_b
= 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
251 ENUM2_c
= 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
254 namespace NsEnumForwardDecl
{
255 enum E
*p
; // expected-warning {{forward references to 'enum' types are a Microsoft extension}}
258 // Clang used to complain that NsEnumForwardDecl::E was undeclared below.
259 NsEnumForwardDecl::E NsEnumForwardDecl_e
;
260 namespace NsEnumForwardDecl
{
266 void del(_Ty
*_Ptr
) {
267 _Ptr
->~_Ty(); // expected-warning {{pseudo-destructors on type void are a Microsoft extension}}
272 del((void*)a
); // expected-note {{in instantiation of function template specialization}}
276 namespace IntToNullPtrConv
{
278 static const int ZERO
= 0;
279 typedef void (Foo::*MemberFcnPtr
)();
283 const Foo::MemberFcnPtr pB
;
286 Bar g_bar
= { (Foo::MemberFcnPtr
)Foo::ZERO
};
288 template<int N
> int *get_n() { return N
; } // expected-warning {{expression which evaluates to zero treated as a null pointer constant}}
289 int *g_nullptr
= get_n
<0>(); // expected-note {{in instantiation of function template specialization}}
291 // FIXME: MSVC accepts this.
292 constexpr float k
= 0;
293 int *p1
= (int)k
; // expected-error {{cannot initialize}}
297 int *p2
= (int)r
; // expected-error {{cannot initialize}}
299 constexpr int f() { return 0; }
300 int *p
= f(); // expected-error {{cannot initialize}}
303 namespace signed_hex_i64
{
307 // This is an ambiguous call in standard C++.
308 // This calls f(long long) in Microsoft mode because LL is always signed.
309 f(0xffffffffffffffffLL
);
310 f(0xffffffffffffffffi
64);
314 typedef void (*FnPtrTy
)();
315 void (*PR23733_1
)() = static_cast<FnPtrTy
>((void *)0); // expected-warning {{static_cast between pointer-to-function and pointer-to-object is a Microsoft extension}}
316 void (*PR23733_2
)() = FnPtrTy((void *)0);
317 void (*PR23733_3
)() = (FnPtrTy
)((void *)0);
318 void (*PR23733_4
)() = reinterpret_cast<FnPtrTy
>((void *)0);
320 long function_prototype(int a
);
321 long (*function_ptr
)(int a
);
323 void function_to_voidptr_conv() {
324 void *a1
= function_prototype
; // expected-warning {{implicit conversion between pointer-to-function and pointer-to-object is a Microsoft extension}}
325 void *a2
= &function_prototype
; // expected-warning {{implicit conversion between pointer-to-function and pointer-to-object is a Microsoft extension}}
326 void *a3
= function_ptr
; // expected-warning {{implicit conversion between pointer-to-function and pointer-to-object is a Microsoft extension}}
329 namespace member_lookup
{
332 struct ConfuseLookup
{
335 static size_t ms_test
;
339 // Microsoft mode allows explicit constructor calls
340 // This could confuse name lookup in cases such as this
342 size_t ConfuseLookup
<T
>::m_val::ms_test
343 = size_t(&(char&)(reinterpret_cast<ConfuseLookup
<T
>*>(0)->m_val
));
345 void instantiate() { ConfuseLookup
<int>::m_val::ms_test
= 1; }
349 // Microsoft doesn't validate exception specification.
350 namespace microsoft_exception_spec
{
352 void foo(); // expected-note {{previous declaration}}
353 void foo() throw(); // expected-warning {{exception specification in declaration does not match previous declaration}}
355 #if __cplusplus < 201703L
356 void r6() throw(...); // expected-note {{previous declaration}}
357 void r6() throw(int); // expected-warning {{exception specification in declaration does not match previous declaration}}
361 virtual void f3() throw(...);
364 struct Derived
: Base
{
365 virtual void f2() throw(...);
371 virtual ~A() throw();
372 #if __cplusplus <= 199711L
373 // expected-note@-2 {{overridden virtual function is here}}
379 #if __cplusplus <= 199711L
380 // expected-warning@-2 {{exception specification of overriding function is more lax than base version}}
384 void f4() throw(); // expected-note {{previous declaration is here}}
385 void f4() {} // expected-warning {{'f4' is missing exception specification 'throw()'}}
387 __declspec(nothrow
) void f5();
390 void f6() noexcept
; // expected-note {{previous declaration is here}}
391 void f6() {} // expected-error {{'f6' is missing exception specification 'noexcept'}}
395 template <int N
> // expected-note {{template parameter is declared here}}
397 static const int N
= 42; // expected-warning {{declaration of 'N' shadows template parameter}}
401 namespace Inner_Outer_same_template_param_name
{
402 template <typename T
> // expected-note {{template parameter is declared here}}
404 template <typename T
> // expected-warning {{declaration of 'T' shadows template parameter}}