Skip to content

Commit 3aee4a9

Browse files
[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.
1 parent bcb917e commit 3aee4a9

File tree

6 files changed

+92
-129
lines changed

6 files changed

+92
-129
lines changed

libcxx/include/source_location

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ namespace std {
3535

3636
_LIBCPP_BEGIN_NAMESPACE_STD
3737

38-
#if _LIBCPP_STD_VER >= 20 && __has_builtin(__builtin_source_location) && \
39-
!(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER <= 1403)
38+
#if _LIBCPP_STD_VER >= 20
4039

4140
class source_location {
4241
// The names source_location::__impl, _M_file_name, _M_function_name, _M_line, and _M_column
@@ -79,8 +78,7 @@ public:
7978
}
8079
};
8180

82-
#endif // _LIBCPP_STD_VER >= 20 && __has_builtin(__builtin_source_location) && !(defined(_LIBCPP_APPLE_CLANG_VER) &&
83-
// _LIBCPP_APPLE_CLANG_VER <= 1403)
81+
#endif // _LIBCPP_STD_VER >= 20
8482

8583
_LIBCPP_END_NAMESPACE_STD
8684

libcxx/include/version

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,7 @@ __cpp_lib_within_lifetime 202306L <type_traits>
414414
# define __cpp_lib_shared_ptr_arrays 201707L
415415
# define __cpp_lib_shift 201806L
416416
// # define __cpp_lib_smart_ptr_for_overwrite 202002L
417-
# if __has_builtin(__builtin_source_location) && !(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER <= 1403)
418-
# define __cpp_lib_source_location 201907L
419-
# endif
417+
# define __cpp_lib_source_location 201907L
420418
# define __cpp_lib_span 202002L
421419
# define __cpp_lib_ssize 201902L
422420
# define __cpp_lib_starts_ends_with 201711L

libcxx/test/std/language.support/support.limits/support.limits.general/source_location.version.compile.pass.cpp

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -42,47 +42,29 @@
4242

4343
#elif TEST_STD_VER == 20
4444

45-
# if __has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)
46-
# ifndef __cpp_lib_source_location
47-
# error "__cpp_lib_source_location should be defined in c++20"
48-
# endif
49-
# if __cpp_lib_source_location != 201907L
50-
# error "__cpp_lib_source_location should have the value 201907L in c++20"
51-
# endif
52-
# else
53-
# ifdef __cpp_lib_source_location
54-
# 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!"
55-
# endif
45+
# ifndef __cpp_lib_source_location
46+
# error "__cpp_lib_source_location should be defined in c++20"
47+
# endif
48+
# if __cpp_lib_source_location != 201907L
49+
# error "__cpp_lib_source_location should have the value 201907L in c++20"
5650
# endif
5751

5852
#elif TEST_STD_VER == 23
5953

60-
# if __has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)
61-
# ifndef __cpp_lib_source_location
62-
# error "__cpp_lib_source_location should be defined in c++23"
63-
# endif
64-
# if __cpp_lib_source_location != 201907L
65-
# error "__cpp_lib_source_location should have the value 201907L in c++23"
66-
# endif
67-
# else
68-
# ifdef __cpp_lib_source_location
69-
# 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!"
70-
# endif
54+
# ifndef __cpp_lib_source_location
55+
# error "__cpp_lib_source_location should be defined in c++23"
56+
# endif
57+
# if __cpp_lib_source_location != 201907L
58+
# error "__cpp_lib_source_location should have the value 201907L in c++23"
7159
# endif
7260

7361
#elif TEST_STD_VER > 23
7462

75-
# if __has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)
76-
# ifndef __cpp_lib_source_location
77-
# error "__cpp_lib_source_location should be defined in c++26"
78-
# endif
79-
# if __cpp_lib_source_location != 201907L
80-
# error "__cpp_lib_source_location should have the value 201907L in c++26"
81-
# endif
82-
# else
83-
# ifdef __cpp_lib_source_location
84-
# 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!"
85-
# endif
63+
# ifndef __cpp_lib_source_location
64+
# error "__cpp_lib_source_location should be defined in c++26"
65+
# endif
66+
# if __cpp_lib_source_location != 201907L
67+
# error "__cpp_lib_source_location should have the value 201907L in c++26"
8668
# endif
8769

8870
#endif // TEST_STD_VER > 23

libcxx/test/std/language.support/support.limits/support.limits.general/version.version.compile.pass.cpp

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4015,17 +4015,11 @@
40154015
# error "__cpp_lib_smart_ptr_owner_equality should not be defined before c++26"
40164016
# endif
40174017

4018-
# if __has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)
4019-
# ifndef __cpp_lib_source_location
4020-
# error "__cpp_lib_source_location should be defined in c++20"
4021-
# endif
4022-
# if __cpp_lib_source_location != 201907L
4023-
# error "__cpp_lib_source_location should have the value 201907L in c++20"
4024-
# endif
4025-
# else
4026-
# ifdef __cpp_lib_source_location
4027-
# 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!"
4028-
# endif
4018+
# ifndef __cpp_lib_source_location
4019+
# error "__cpp_lib_source_location should be defined in c++20"
4020+
# endif
4021+
# if __cpp_lib_source_location != 201907L
4022+
# error "__cpp_lib_source_location should have the value 201907L in c++20"
40294023
# endif
40304024

40314025
# ifndef __cpp_lib_span
@@ -5539,17 +5533,11 @@
55395533
# error "__cpp_lib_smart_ptr_owner_equality should not be defined before c++26"
55405534
# endif
55415535

5542-
# if __has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)
5543-
# ifndef __cpp_lib_source_location
5544-
# error "__cpp_lib_source_location should be defined in c++23"
5545-
# endif
5546-
# if __cpp_lib_source_location != 201907L
5547-
# error "__cpp_lib_source_location should have the value 201907L in c++23"
5548-
# endif
5549-
# else
5550-
# ifdef __cpp_lib_source_location
5551-
# 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!"
5552-
# endif
5536+
# ifndef __cpp_lib_source_location
5537+
# error "__cpp_lib_source_location should be defined in c++23"
5538+
# endif
5539+
# if __cpp_lib_source_location != 201907L
5540+
# error "__cpp_lib_source_location should have the value 201907L in c++23"
55535541
# endif
55545542

55555543
# ifndef __cpp_lib_span
@@ -7282,17 +7270,11 @@
72827270
# endif
72837271
# endif
72847272

7285-
# if __has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)
7286-
# ifndef __cpp_lib_source_location
7287-
# error "__cpp_lib_source_location should be defined in c++26"
7288-
# endif
7289-
# if __cpp_lib_source_location != 201907L
7290-
# error "__cpp_lib_source_location should have the value 201907L in c++26"
7291-
# endif
7292-
# else
7293-
# ifdef __cpp_lib_source_location
7294-
# 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!"
7295-
# endif
7273+
# ifndef __cpp_lib_source_location
7274+
# error "__cpp_lib_source_location should be defined in c++26"
7275+
# endif
7276+
# if __cpp_lib_source_location != 201907L
7277+
# error "__cpp_lib_source_location should have the value 201907L in c++26"
72967278
# endif
72977279

72987280
# ifndef __cpp_lib_span

libcxx/test/support/msvc_stdlib_force_include.h

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -13,98 +13,103 @@
1313
// MSVC standard library.
1414

1515
#ifndef _LIBCXX_IN_DEVCRT
16-
// Silence warnings about CRT machinery.
17-
#define _CRT_SECURE_NO_WARNINGS 1
16+
// Silence warnings about CRT machinery.
17+
# define _CRT_SECURE_NO_WARNINGS 1
1818

19-
// Avoid assertion dialogs.
20-
#define _CRT_SECURE_INVALID_PARAMETER(EXPR) ::abort()
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
2130
#endif // _LIBCXX_IN_DEVCRT
2231

2332
#include <crtdbg.h>
2433
#include <stdlib.h>
2534

2635
#if defined(_LIBCPP_VERSION)
27-
#error This header may not be used when targeting libc++
36+
# error This header may not be used when targeting libc++
2837
#endif
2938

3039
#ifndef _LIBCXX_IN_DEVCRT
3140
struct AssertionDialogAvoider {
32-
AssertionDialogAvoider() {
33-
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
34-
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
41+
AssertionDialogAvoider() {
42+
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
43+
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
3544

36-
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
37-
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
38-
}
45+
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
46+
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
47+
}
3948
};
4049

4150
const AssertionDialogAvoider assertion_dialog_avoider{};
4251
#endif // _LIBCXX_IN_DEVCRT
4352

4453
// MSVC frontend only configurations
4554
#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__)
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 : 4521) // multiple copy constructors specified
71+
# pragma warning(disable : 4702) // unreachable code
72+
# pragma warning(disable : 28251) // Inconsistent annotation for 'new': this instance has no annotations.
73+
#endif // !defined(__clang__)
6474

6575
#ifndef _LIBCXX_IN_DEVCRT
66-
// atomic_is_lock_free.pass.cpp needs this VS 2015 Update 2 fix.
67-
#define _ENABLE_ATOMIC_ALIGNMENT_FIX
76+
// atomic_is_lock_free.pass.cpp needs this VS 2015 Update 2 fix.
77+
# define _ENABLE_ATOMIC_ALIGNMENT_FIX
6878

69-
// Restore features that are removed in C++20.
70-
#define _HAS_FEATURES_REMOVED_IN_CXX20 1
79+
// Restore features that are removed in C++20.
80+
# define _HAS_FEATURES_REMOVED_IN_CXX20 1
7181

72-
// Silence warnings about the unspecified complex<non-floating-point>
73-
#define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING
82+
// Silence warnings about the unspecified complex<non-floating-point>
83+
# define _SILENCE_NONFLOATING_COMPLEX_DEPRECATION_WARNING
7484

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
85+
// Silence warnings about features that are deprecated in non-default language modes.
86+
# define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS
87+
# define _SILENCE_ALL_CXX20_DEPRECATION_WARNINGS
88+
# define _SILENCE_ALL_CXX23_DEPRECATION_WARNINGS
7989
#endif // _LIBCXX_IN_DEVCRT
8090

8191
#include <version>
8292

8393
#if _HAS_CXX23
84-
#define TEST_STD_VER 99
94+
# define TEST_STD_VER 99
8595
#elif _HAS_CXX20
86-
#define TEST_STD_VER 20
96+
# define TEST_STD_VER 20
8797
#elif _HAS_CXX17
88-
#define TEST_STD_VER 17
98+
# define TEST_STD_VER 17
8999
#else
90-
#define TEST_STD_VER 14
100+
# define TEST_STD_VER 14
91101
#endif
92102

93103
#define _LIBCPP_AVAILABILITY_THROW_BAD_ANY_CAST
94104

95105
#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")
106+
# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
107+
_Pragma("GCC diagnostic push") _Pragma("GCC diagnostic ignored \"-Wdeprecated\"")
108+
# define _LIBCPP_SUPPRESS_DEPRECATED_POP _Pragma("GCC diagnostic pop")
101109
#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))
110+
# define _LIBCPP_SUPPRESS_DEPRECATED_PUSH \
111+
__pragma(warning(push)) __pragma(warning(disable : 4996)) __pragma(warning(disable : 5215))
112+
# define _LIBCPP_SUPPRESS_DEPRECATED_POP __pragma(warning(pop))
108113
#endif // __clang__
109114

110115
#endif // SUPPORT_MSVC_STDLIB_FORCE_INCLUDE_H

libcxx/utils/generate_feature_test_macro_components.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,8 +1072,6 @@ def add_version_header(tc):
10721072
"name": "__cpp_lib_source_location",
10731073
"values": {"c++20": 201907},
10741074
"headers": ["source_location"],
1075-
"test_suite_guard": "__has_builtin(__builtin_source_location) && !(defined(TEST_APPLE_CLANG_VER) && TEST_APPLE_CLANG_VER <= 1403)",
1076-
"libcxx_guard": "__has_builtin(__builtin_source_location) && !(defined(_LIBCPP_APPLE_CLANG_VER) && _LIBCPP_APPLE_CLANG_VER <= 1403)",
10771075
},
10781076
{
10791077
"name": "__cpp_lib_span",

0 commit comments

Comments
 (0)