Skip to content

Commit 9320bb2

Browse files
committed
Fix test failures
1 parent 817d019 commit 9320bb2

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

libcxx/include/__assert

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@
1717
# pragma GCC system_header
1818
#endif
1919

20-
#define _LIBCPP_ASSERT_IS_CONSTANT_EVALUATED \
21-
(_LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wconstant-evaluated") __builtin_is_constant_evaluated() \
22-
_LIBCPP_DIAGNOSTIC_POP)
20+
#ifdef _LIBCPP_COMPILER_CLANG_BASED
21+
// TODO: use `_LIBCPP_DIAGNOSTIC_*` macros after #107715 is fixed in all supported clang compilers
22+
# define _LIBCPP_ASSERT_IS_CONSTANT_EVALUATED \
23+
(_Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wconstant-evaluated\"") \
24+
__builtin_is_constant_evaluated() _Pragma("clang diagnostic pop"))
25+
#else
26+
# define _LIBCPP_ASSERT_IS_CONSTANT_EVALUATED (__builtin_is_constant_evaluated())
27+
#endif
2328

2429
#define _LIBCPP_ASSERT(expression, message) \
2530
(__builtin_expect(static_cast<bool>(expression), 1) ? (void)0 \

libcxx/test/std/algorithms/alg.sorting/alg.clamp/ranges.clamp.pass.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,12 @@ constexpr bool test() {
108108
return value;
109109
};
110110
assert(std::ranges::clamp(3, 2, 4, std::ranges::less{}, projection_function) == 3);
111+
// When assertions are enabled, we call the projection more times
111112
#if defined(_LIBCPP_HARDENING_MODE) && \
112113
_LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_EXTENSIVE && \
113114
_LIBCPP_HARDENING_MODE != _LIBCPP_HARDENING_MODE_DEBUG
114-
assert(counter <= 3);
115+
if (!std::__libcpp_is_constant_evaluated())
116+
assert(counter <= 3);
115117
#endif
116118
}
117119

0 commit comments

Comments
 (0)