[libcxx-commits] [libcxx] 3aee4a9 - [libc++] Update <source_location> and msvc_stdlib_force_include.h (#74266)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Dec 6 06:04:11 PST 2023
Author: Stephan T. Lavavej
Date: 2023-12-06T09:04:06-05:00
New Revision: 3aee4a96289b32386d1a6ccda9bc6bf4fff40e13
URL: https://github.com/llvm/llvm-project/commit/3aee4a96289b32386d1a6ccda9bc6bf4fff40e13
DIFF: https://github.com/llvm/llvm-project/commit/3aee4a96289b32386d1a6ccda9bc6bf4fff40e13.diff
LOG: [libc++] Update <source_location> and msvc_stdlib_force_include.h (#74266)
This makes libc++'s <filesystem> tests compatible with MSVC's STL.
In msvc_stdlib_force_include.h, we need to define 3 more macros:
- _CRT_DECLARE_NONSTDC_NAMES activates the POSIX names of
`getcwd` etc. As the comment explains, we need this because
we test with Clang `-fno-ms-compatibility`, which defines
`__STDC__` to `1`, which causes the UCRT headers to disable
the POSIX names by default.
- Then we need _CRT_NONSTDC_NO_WARNINGS to avoid emitting
deprecation warnings about the POSIX names.
- Finally, we need `NOMINMAX` to seal away the ancient evil.
These macros are documented in https://learn.microsoft.com/en-us/cpp/c-runtime-library/compatibility?view=msvc-170.
As a drive-by change, the patch adds a "simulated" macro for
__has_feature(hwaddress_sanitizer). It also clang-formats all
of msvc_stdlib_force_include.h and removes guards for
__has_builtin(__builtin_source_location) in <source_location>,
since those are not needed anymore.
Added:
Modified:
libcxx/include/source_location
libcxx/include/version
libcxx/test/std/language.support/support.limits/support.limits.general/source_location.version.compile.pass.cpp
libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
libcxx/test/support/msvc_stdlib_force_include.h
libcxx/utils/generate_feature_test_macro_components.py
Removed:
################################################################################
diff --git a/libcxx/include/source_location b/libcxx/include/source_location
index e9e852a6e4613..d16e3c46fce55 100644
--- a/libcxx/include/source_location
+++ b/libcxx/include/source_location
@@ -35,8 +35,7 @@ namespace std {
_LIBCPP_BEGIN_NAMESPACE_STD
-#if _LIBCPP_STD_VER >= 20 && __has_builtin(__builtin_source_location) && \
- !(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER <= 1403)
+#if _LIBCPP_STD_VER >= 20
class source_location {
// The names source_location::__impl, _M_file_name, _M_function_name, _M_line, and _M_column
@@ -79,8 +78,7 @@ public:
}
};
-#endif // _LIBCPP_STD_VER >= 20 && __has_builtin(__builtin_source_location) && !(defined(_LIBCPP_APPLE_CLANG_VER) &&
- // _LIBCPP_APPLE_CLANG_VER <= 1403)
+#endif // _LIBCPP_STD_VER >= 20
_LIBCPP_END_NAMESPACE_STD
diff --git a/libcxx/include/version b/libcxx/include/version
index e84790b888d33..a91c344c43609 100644
--- a/libcxx/include/version
+++ b/libcxx/include/version
@@ -414,9 +414,7 @@ __cpp_lib_within_lifetime 202306L <type_traits>
# define __cpp_lib_shared_ptr_arrays 201707L
# define __cpp_lib_shift 201806L
// # define __cpp_lib_smart_ptr_for_overwrite 202002L
-# if __has_builtin(__builtin_source_location) && !(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER <= 1403)
-# define __cpp_lib_source_location 201907L
-# endif
+# define __cpp_lib_source_location 201907L
# define __cpp_lib_span 202002L
# define __cpp_lib_ssize 201902L
# define __cpp_lib_starts_ends_with 201711L
diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/source_location.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/source_location.version.compile.pass.cpp
index b0ccf795bb724..7c5d882a37e61 100644
--- a/libcxx/test/std/language.support/support.limits/support.limits.general/source_location.version.compile.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/source_location.version.compile.pass.cpp
@@ -42,47 +42,29 @@
#elif TEST_STD_VER == 20
-# if __has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)
-# ifndef __cpp_lib_source_location
-# error "__cpp_lib_source_location should be defined in c++20"
-# endif
-# if __cpp_lib_source_location != 201907L
-# error "__cpp_lib_source_location should have the value 201907L in c++20"
-# endif
-# else
-# ifdef __cpp_lib_source_location
-# error "__cpp_lib_source_location should not be defined when the requirement '__has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)' is not met!"
-# endif
+# ifndef __cpp_lib_source_location
+# error "__cpp_lib_source_location should be defined in c++20"
+# endif
+# if __cpp_lib_source_location != 201907L
+# error "__cpp_lib_source_location should have the value 201907L in c++20"
# endif
#elif TEST_STD_VER == 23
-# if __has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)
-# ifndef __cpp_lib_source_location
-# error "__cpp_lib_source_location should be defined in c++23"
-# endif
-# if __cpp_lib_source_location != 201907L
-# error "__cpp_lib_source_location should have the value 201907L in c++23"
-# endif
-# else
-# ifdef __cpp_lib_source_location
-# error "__cpp_lib_source_location should not be defined when the requirement '__has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)' is not met!"
-# endif
+# ifndef __cpp_lib_source_location
+# error "__cpp_lib_source_location should be defined in c++23"
+# endif
+# if __cpp_lib_source_location != 201907L
+# error "__cpp_lib_source_location should have the value 201907L in c++23"
# endif
#elif TEST_STD_VER > 23
-# if __has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)
-# ifndef __cpp_lib_source_location
-# error "__cpp_lib_source_location should be defined in c++26"
-# endif
-# if __cpp_lib_source_location != 201907L
-# error "__cpp_lib_source_location should have the value 201907L in c++26"
-# endif
-# else
-# ifdef __cpp_lib_source_location
-# error "__cpp_lib_source_location should not be defined when the requirement '__has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)' is not met!"
-# endif
+# ifndef __cpp_lib_source_location
+# error "__cpp_lib_source_location should be defined in c++26"
+# endif
+# if __cpp_lib_source_location != 201907L
+# error "__cpp_lib_source_location should have the value 201907L in c++26"
# endif
#endif // TEST_STD_VER > 23
diff --git a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
index 0b00469892f60..c0d3d554dcf05 100644
--- a/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
+++ b/libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp
@@ -4015,17 +4015,11 @@
# error "__cpp_lib_smart_ptr_owner_equality should not be defined before c++26"
# endif
-# if __has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)
-# ifndef __cpp_lib_source_location
-# error "__cpp_lib_source_location should be defined in c++20"
-# endif
-# if __cpp_lib_source_location != 201907L
-# error "__cpp_lib_source_location should have the value 201907L in c++20"
-# endif
-# else
-# ifdef __cpp_lib_source_location
-# error "__cpp_lib_source_location should not be defined when the requirement '__has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)' is not met!"
-# endif
+# ifndef __cpp_lib_source_location
+# error "__cpp_lib_source_location should be defined in c++20"
+# endif
+# if __cpp_lib_source_location != 201907L
+# error "__cpp_lib_source_location should have the value 201907L in c++20"
# endif
# ifndef __cpp_lib_span
@@ -5539,17 +5533,11 @@
# error "__cpp_lib_smart_ptr_owner_equality should not be defined before c++26"
# endif
-# if __has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)
-# ifndef __cpp_lib_source_location
-# error "__cpp_lib_source_location should be defined in c++23"
-# endif
-# if __cpp_lib_source_location != 201907L
-# error "__cpp_lib_source_location should have the value 201907L in c++23"
-# endif
-# else
-# ifdef __cpp_lib_source_location
-# error "__cpp_lib_source_location should not be defined when the requirement '__has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)' is not met!"
-# endif
+# ifndef __cpp_lib_source_location
+# error "__cpp_lib_source_location should be defined in c++23"
+# endif
+# if __cpp_lib_source_location != 201907L
+# error "__cpp_lib_source_location should have the value 201907L in c++23"
# endif
# ifndef __cpp_lib_span
@@ -7282,17 +7270,11 @@
# endif
# endif
-# if __has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)
-# ifndef __cpp_lib_source_location
-# error "__cpp_lib_source_location should be defined in c++26"
-# endif
-# if __cpp_lib_source_location != 201907L
-# error "__cpp_lib_source_location should have the value 201907L in c++26"
-# endif
-# else
-# ifdef __cpp_lib_source_location
-# error "__cpp_lib_source_location should not be defined when the requirement '__has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)' is not met!"
-# endif
+# ifndef __cpp_lib_source_location
+# error "__cpp_lib_source_location should be defined in c++26"
+# endif
+# if __cpp_lib_source_location != 201907L
+# error "__cpp_lib_source_location should have the value 201907L in c++26"
# endif
# ifndef __cpp_lib_span
diff --git a/libcxx/test/support/msvc_stdlib_force_include.h b/libcxx/test/support/msvc_stdlib_force_include.h
index 3c61f0b880b18..b5ba33bd281c0 100644
--- a/libcxx/test/support/msvc_stdlib_force_include.h
+++ b/libcxx/test/support/msvc_stdlib_force_include.h
@@ -13,29 +13,38 @@
// MSVC standard library.
#ifndef _LIBCXX_IN_DEVCRT
- // Silence warnings about CRT machinery.
- #define _CRT_SECURE_NO_WARNINGS 1
+// Silence warnings about CRT machinery.
+# define _CRT_SECURE_NO_WARNINGS 1
- // Avoid assertion dialogs.
- #define _CRT_SECURE_INVALID_PARAMETER(EXPR) ::abort()
+// Avoid assertion dialogs.
+# define _CRT_SECURE_INVALID_PARAMETER(EXPR) ::abort()
+
+// Declare POSIX function names. (By default, Clang -fno-ms-compatibility causes them to be omitted.)
+# define _CRT_DECLARE_NONSTDC_NAMES 1
+
+// Silence warnings about POSIX function names.
+# define _CRT_NONSTDC_NO_WARNINGS 1
+
+// Avoid Windows.h macroizing min() and max().
+# define NOMINMAX 1
#endif // _LIBCXX_IN_DEVCRT
#include <crtdbg.h>
#include <stdlib.h>
#if defined(_LIBCPP_VERSION)
- #error This header may not be used when targeting libc++
+# error This header may not be used when targeting libc++
#endif
#ifndef _LIBCXX_IN_DEVCRT
struct AssertionDialogAvoider {
- AssertionDialogAvoider() {
- _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
- _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
+ AssertionDialogAvoider() {
+ _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
+ _CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
- _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
- _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
- }
+ _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
+ _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
+ }
};
const AssertionDialogAvoider assertion_dialog_avoider{};
@@ -43,68 +52,64 @@ const AssertionDialogAvoider assertion_dialog_avoider{};
// MSVC frontend only configurations
#if !defined(__clang__)
- // Simulate feature-test macros.
- #define __has_feature(X) _MSVC_HAS_FEATURE_ ## X
- #define _MSVC_HAS_FEATURE_cxx_exceptions 1
- #define _MSVC_HAS_FEATURE_cxx_rtti 1
- #define _MSVC_HAS_FEATURE_address_sanitizer 0
- #define _MSVC_HAS_FEATURE_memory_sanitizer 0
- #define _MSVC_HAS_FEATURE_thread_sanitizer 0
-
- #define __has_attribute(X) _MSVC_HAS_ATTRIBUTE_ ## X
- #define _MSVC_HAS_ATTRIBUTE_vector_size 0
-
- // Silence compiler warnings.
- #pragma warning(disable: 4180) // qualifier applied to function type has no meaning; ignored
- #pragma warning(disable: 4324) // structure was padded due to alignment specifier
- #pragma warning(disable: 4521) // multiple copy constructors specified
- #pragma warning(disable: 4702) // unreachable code
- #pragma warning(disable: 28251) // Inconsistent annotation for 'new': this instance has no annotations.
-#endif // !defined(__clang__)
+// Simulate feature-test macros.
+# define __has_feature(X) _MSVC_HAS_FEATURE_##X
+# define _MSVC_HAS_FEATURE_cxx_exceptions 1
+# define _MSVC_HAS_FEATURE_cxx_rtti 1
+# define _MSVC_HAS_FEATURE_address_sanitizer 0
+# define _MSVC_HAS_FEATURE_hwaddress_sanitizer 0
+# define _MSVC_HAS_FEATURE_memory_sanitizer 0
+# define _MSVC_HAS_FEATURE_thread_sanitizer 0
+
+# define __has_attribute(X) _MSVC_HAS_ATTRIBUTE_##X
+# define _MSVC_HAS_ATTRIBUTE_vector_size 0
+
+// Silence compiler warnings.
+# pragma warning(disable : 4180) // qualifier applied to function type has no meaning; ignored
+# pragma warning(disable : 4324) // structure was padded due to alignment specifier
+# pragma warning(disable : 4521) // multiple copy constructors specified
+# pragma warning(disable : 4702) // unreachable code
+# pragma warning(disable : 28251) // Inconsistent annotation for 'new': this instance has no annotations.
+#endif // !defined(__clang__)
#ifndef _LIBCXX_IN_DEVCRT
- // atomic_is_lock_free.pass.cpp needs this VS 2015 Update 2 fix.
- #define _ENABLE_ATOMIC_ALIGNMENT_FIX
+// atomic_is_lock_free.pass.cpp needs this VS 2015 Update 2 fix.
+# define _ENABLE_ATOMIC_ALIGNMENT_FIX
- // Restore features that are removed in C++20.
- #define _HAS_FEATURES_REMOVED_IN_CXX20 1
+// Restore features that are removed in C++20.
+# define _HAS_FEATURES_REMOVED_IN_CXX20 1
- // Silence warnings about the unspecified complex<non-floating-point>
- #define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING
+// Silence warnings about the unspecified complex<non-floating-point>
+# define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING
- // Silence warnings about features that are deprecated in non-default language modes.
- #define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
- #define _SILENCE_ALL_CXX20_DEPRECATION_WARNINGS
- #define _SILENCE_ALL_CXX23_DEPRECATION_WARNINGS
+// Silence warnings about features that are deprecated in non-default language modes.
+# define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
+# define _SILENCE_ALL_CXX20_DEPRECATION_WARNINGS
+# define _SILENCE_ALL_CXX23_DEPRECATION_WARNINGS
#endif // _LIBCXX_IN_DEVCRT
#include <version>
#if _HAS_CXX23
- #define TEST_STD_VER 99
+# define TEST_STD_VER 99
#elif _HAS_CXX20
- #define TEST_STD_VER 20
+# define TEST_STD_VER 20
#elif _HAS_CXX17
- #define TEST_STD_VER 17
+# define TEST_STD_VER 17
#else
- #define TEST_STD_VER 14
+# define TEST_STD_VER 14
#endif
#define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
#ifdef __clang__
-#define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
- _Pragma("GCC diagnostic push") \
- _Pragma("GCC diagnostic ignored \"-Wdeprecated\"")
-#define _LIBCPP_SUPPRESS_DEPRECATED_POP \
- _Pragma("GCC diagnostic pop")
+# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
+ _Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"")
+# define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop")
#else // ^^^ clang / MSVC vvv
-#define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
- __pragma(warning(push)) \
- __pragma(warning(disable : 4996)) \
- __pragma(warning(disable : 5215))
-#define _LIBCPP_SUPPRESS_DEPRECATED_POP \
- __pragma(warning(pop))
+# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
+ __pragma(warning(push)) __pragma(warning(disable : 4996)) __pragma(warning(disable : 5215))
+# define _LIBCPP_SUPPRESS_DEPRECATED_POP __pragma(warning(pop))
#endif // __clang__
#endif // SUPPORT_MSVC_STDLIB_FORCE_INCLUDE_H
diff --git a/libcxx/utils/generate_feature_test_macro_components.py b/libcxx/utils/generate_feature_test_macro_components.py
index 8943ad2557433..6a30324397883 100755
--- a/libcxx/utils/generate_feature_test_macro_components.py
+++ b/libcxx/utils/generate_feature_test_macro_components.py
@@ -1072,8 +1072,6 @@ def add_version_header(tc):
"name": "__cpp_lib_source_location",
"values": {"c++20": 201907},
"headers": ["source_location"],
- "test_suite_guard": "__has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)",
- "libcxx_guard": "__has_builtin(__builtin_source_location) && !(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER <= 1403)",
},
{
"name": "__cpp_lib_span",
More information about the libcxx-commits
mailing list