xref: /llvm-project/libcxx/test/support/msvc_stdlib_force_include.h (revision 2ba08386156ef25913b1bee170d8fe95aaceb234)
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 
22 // Declare POSIX function names. (By default, Clang -fno-ms-compatibility causes them to be omitted.)
23 #  define _CRT_DECLARE_NONSTDC_NAMES 1
24 
25 // Silence warnings about POSIX function names.
26 #  define _CRT_NONSTDC_NO_WARNINGS 1
27 
28 // Avoid Windows.h macroizing min() and max().
29 #  define NOMINMAX 1
30 #endif // _LIBCXX_IN_DEVCRT
31 
32 #include <crtdbg.h>
33 #include <stdlib.h>
34 
35 #if defined(_LIBCPP_VERSION)
36 #  error This header may not be used when targeting libc++
37 #endif
38 
39 #ifndef _LIBCXX_IN_DEVCRT
40 struct AssertionDialogAvoider {
AssertionDialogAvoiderAssertionDialogAvoider41   AssertionDialogAvoider() {
42     _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
43     _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
44 
45     _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
46     _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
47   }
48 };
49 
50 const AssertionDialogAvoider assertion_dialog_avoider{};
51 #endif // _LIBCXX_IN_DEVCRT
52 
53 // MSVC frontend only configurations
54 #if !defined(__clang__)
55 // Simulate feature-test macros.
56 #  define __has_feature(X) _MSVC_HAS_FEATURE_##X
57 #  define _MSVC_HAS_FEATURE_cxx_exceptions 1
58 #  define _MSVC_HAS_FEATURE_cxx_rtti 1
59 #  define _MSVC_HAS_FEATURE_address_sanitizer 0
60 #  define _MSVC_HAS_FEATURE_hwaddress_sanitizer 0
61 #  define _MSVC_HAS_FEATURE_memory_sanitizer 0
62 #  define _MSVC_HAS_FEATURE_thread_sanitizer 0
63 
64 #  define __has_attribute(X) _MSVC_HAS_ATTRIBUTE_##X
65 #  define _MSVC_HAS_ATTRIBUTE_vector_size 0
66 
67 // Silence compiler warnings.
68 #  pragma warning(disable : 4180)  // qualifier applied to function type has no meaning; ignored
69 #  pragma warning(disable : 4324)  // structure was padded due to alignment specifier
70 #  pragma warning(disable : 4702)  // unreachable code
71 #  pragma warning(disable : 28251) // Inconsistent annotation for 'new': this instance has no annotations.
72 #endif                             // !defined(__clang__)
73 
74 #ifndef _LIBCXX_IN_DEVCRT
75 // atomic_is_lock_free.pass.cpp needs this VS 2015 Update 2 fix.
76 #  define _ENABLE_ATOMIC_ALIGNMENT_FIX
77 
78 // Restore features that are removed in C++20.
79 #  define _HAS_FEATURES_REMOVED_IN_CXX20 1
80 
81 // Silence warnings about the unspecified complex<non-floating-point>
82 #  define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING
83 
84 // Silence warnings about features that are deprecated in non-default language modes.
85 #  define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
86 #  define _SILENCE_ALL_CXX20_DEPRECATION_WARNINGS
87 #  define _SILENCE_ALL_CXX23_DEPRECATION_WARNINGS
88 #endif // _LIBCXX_IN_DEVCRT
89 
90 #include <version>
91 
92 #if _HAS_CXX23
93 #  define TEST_STD_VER 23
94 #elif _HAS_CXX20
95 #  define TEST_STD_VER 20
96 #elif _HAS_CXX17
97 #  define TEST_STD_VER 17
98 #else
99 #  define TEST_STD_VER 14
100 #endif
101 
102 #define TEST_SHORT_WCHAR
103 #define TEST_ABI_MICROSOFT
104 
105 #define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
106 
107 #endif // SUPPORT_MSVC_STDLIB_FORCE_INCLUDE_H
108