msvc_stdlib_force_include.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #ifndef SUPPORT_MSVC_STDLIB_FORCE_INCLUDE_H
  9. #define SUPPORT_MSVC_STDLIB_FORCE_INCLUDE_H
  10. // This header is force-included when running the libc++ tests against the
  11. // MSVC standard library.
  12. #ifndef _LIBCXX_IN_DEVCRT
  13. // Silence warnings about CRT machinery.
  14. #define _CRT_SECURE_NO_WARNINGS
  15. // Avoid assertion dialogs.
  16. #define _CRT_SECURE_INVALID_PARAMETER(EXPR) ::abort()
  17. #endif // _LIBCXX_IN_DEVCRT
  18. #include <crtdbg.h>
  19. #include <stdlib.h>
  20. #if defined(_LIBCPP_VERSION)
  21. #error This header may not be used when targeting libc++
  22. #endif
  23. #ifndef _LIBCXX_IN_DEVCRT
  24. struct AssertionDialogAvoider {
  25. AssertionDialogAvoider() {
  26. _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
  27. _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
  28. _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
  29. _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
  30. }
  31. };
  32. const AssertionDialogAvoider assertion_dialog_avoider{};
  33. #endif // _LIBCXX_IN_DEVCRT
  34. // MSVC frontend only configurations
  35. #if !defined(__clang__)
  36. // Simulate feature-test macros.
  37. #define __has_feature(X) _MSVC_HAS_FEATURE_ ## X
  38. #define _MSVC_HAS_FEATURE_cxx_exceptions 1
  39. #define _MSVC_HAS_FEATURE_cxx_rtti 1
  40. #define _MSVC_HAS_FEATURE_address_sanitizer 0
  41. #define _MSVC_HAS_FEATURE_memory_sanitizer 0
  42. #define _MSVC_HAS_FEATURE_thread_sanitizer 0
  43. #define __has_attribute(X) _MSVC_HAS_ATTRIBUTE_ ## X
  44. #define _MSVC_HAS_ATTRIBUTE_vector_size 0
  45. // Silence compiler warnings.
  46. #pragma warning(disable: 4180) // qualifier applied to function type has no meaning; ignored
  47. #pragma warning(disable: 4324) // structure was padded due to alignment specifier
  48. #pragma warning(disable: 4521) // multiple copy constructors specified
  49. #pragma warning(disable: 4702) // unreachable code
  50. #pragma warning(disable: 28251) // Inconsistent annotation for 'new': this instance has no annotations.
  51. #endif // !defined(__clang__)
  52. // MSVC doesn't have __int128_t.
  53. #define _LIBCPP_HAS_NO_INT128
  54. // MSVC has quick_exit() and at_quick_exit().
  55. #define _LIBCPP_HAS_QUICK_EXIT
  56. #ifndef _LIBCXX_IN_DEVCRT
  57. // atomic_is_lock_free.pass.cpp needs this VS 2015 Update 2 fix.
  58. #define _ENABLE_ATOMIC_ALIGNMENT_FIX
  59. // Silence warnings about features that are deprecated in C++17 and C++20.
  60. #define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
  61. #define _SILENCE_ALL_CXX20_DEPRECATION_WARNINGS
  62. #endif // _LIBCXX_IN_DEVCRT
  63. #include <version>
  64. #if _HAS_CXX20
  65. #define TEST_STD_VER 99
  66. #elif _HAS_CXX17
  67. #define TEST_STD_VER 17
  68. #else // !(_HAS_CXX20 || _HAS_CXX17)
  69. #define TEST_STD_VER 14
  70. #endif
  71. #define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
  72. #endif // SUPPORT_MSVC_STDLIB_FORCE_INCLUDE_H