1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef SUPPORT_MSVC_STDLIB_FORCE_INCLUDE_H
10 #define SUPPORT_MSVC_STDLIB_FORCE_INCLUDE_H
11 
12 // This header is force-included when running the libc++ tests against the
13 // MSVC standard library.
14 
15 #ifndef _LIBCXX_IN_DEVCRT
16     // Silence warnings about CRT machinery.
17     #define _CRT_SECURE_NO_WARNINGS 1
18 
19     // Avoid assertion dialogs.
20     #define _CRT_SECURE_INVALID_PARAMETER(EXPR) ::abort()
21 #endif // _LIBCXX_IN_DEVCRT
22 
23 #include <crtdbg.h>
24 #include <stdlib.h>
25 
26 #if defined(_LIBCPP_VERSION)
27     #error This header may not be used when targeting libc++
28 #endif
29 
30 #ifndef _LIBCXX_IN_DEVCRT
31 struct AssertionDialogAvoider {
AssertionDialogAvoiderAssertionDialogAvoider32     AssertionDialogAvoider() {
33         _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
34         _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
35 
36         _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
37         _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
38     }
39 };
40 
41 const AssertionDialogAvoider assertion_dialog_avoider{};
42 #endif // _LIBCXX_IN_DEVCRT
43 
44 // MSVC frontend only configurations
45 #if !defined(__clang__)
46     // Simulate feature-test macros.
47     #define __has_feature(X) _MSVC_HAS_FEATURE_ ## X
48     #define _MSVC_HAS_FEATURE_cxx_exceptions    1
49     #define _MSVC_HAS_FEATURE_cxx_rtti          1
50     #define _MSVC_HAS_FEATURE_address_sanitizer 0
51     #define _MSVC_HAS_FEATURE_memory_sanitizer  0
52     #define _MSVC_HAS_FEATURE_thread_sanitizer  0
53 
54     #define __has_attribute(X) _MSVC_HAS_ATTRIBUTE_ ## X
55     #define _MSVC_HAS_ATTRIBUTE_vector_size     0
56 
57     // Silence compiler warnings.
58     #pragma warning(disable: 4180) // qualifier applied to function type has no meaning; ignored
59     #pragma warning(disable: 4324) // structure was padded due to alignment specifier
60     #pragma warning(disable: 4521) // multiple copy constructors specified
61     #pragma warning(disable: 4702) // unreachable code
62     #pragma warning(disable: 28251) // Inconsistent annotation for 'new': this instance has no annotations.
63 #endif // !defined(__clang__)
64 
65 #ifndef _LIBCXX_IN_DEVCRT
66     // atomic_is_lock_free.pass.cpp needs this VS 2015 Update 2 fix.
67     #define _ENABLE_ATOMIC_ALIGNMENT_FIX
68 
69     // Restore features that are removed in C++20.
70     #define _HAS_FEATURES_REMOVED_IN_CXX20 1
71 
72     // Silence warnings about the unspecified complex<non-floating-point>
73     #define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING
74 
75     // Silence warnings about features that are deprecated in non-default language modes.
76     #define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
77     #define _SILENCE_ALL_CXX20_DEPRECATION_WARNINGS
78     #define _SILENCE_ALL_CXX23_DEPRECATION_WARNINGS
79 #endif // _LIBCXX_IN_DEVCRT
80 
81 #include <version>
82 
83 #if _HAS_CXX23
84     #define TEST_STD_VER 99
85 #elif _HAS_CXX20
86     #define TEST_STD_VER 20
87 #elif _HAS_CXX17
88     #define TEST_STD_VER 17
89 #else
90     #define TEST_STD_VER 14
91 #endif
92 
93 #define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
94 
95 #ifdef __clang__
96 #define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
97     _Pragma("GCC diagnostic push") \
98     _Pragma("GCC diagnostic ignored \"-Wdeprecated\"")
99 #define _LIBCPP_SUPPRESS_DEPRECATED_POP \
100     _Pragma("GCC diagnostic pop")
101 #else // ^^^ clang / MSVC vvv
102 #define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
103     __pragma(warning(push)) \
104     __pragma(warning(disable : 4996)) \
105     __pragma(warning(disable : 5215))
106 #define _LIBCPP_SUPPRESS_DEPRECATED_POP \
107     __pragma(warning(pop))
108 #endif // __clang__
109 
110 #endif // SUPPORT_MSVC_STDLIB_FORCE_INCLUDE_H
111