[libcxx-commits] [libcxx] [libc++][hardening] Always enable all checks during constant evaluation (PR #107713)
Mital Ashok via libcxx-commits
libcxx-commits at lists.llvm.org
Sun Sep 8 09:09:07 PDT 2024
================
@@ -17,23 +17,38 @@
# pragma GCC system_header
#endif
+#ifdef _LIBCPP_COMPILER_CLANG_BASED
+// TODO: use `_LIBCPP_DIAGNOSTIC_*` macros after #107715 is fixed in all supported clang compilers
+# define _LIBCPP_ASSERT_IS_CONSTANT_EVALUATED \
+ (_Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wconstant-evaluated\"") \
+ __builtin_is_constant_evaluated() _Pragma("clang diagnostic pop"))
+#else
+# define _LIBCPP_ASSERT_IS_CONSTANT_EVALUATED (__builtin_is_constant_evaluated())
+#endif
+
#define _LIBCPP_ASSERT(expression, message) \
- (__builtin_expect(static_cast<bool>(expression), 1) \
- ? (void)0 \
+ (__builtin_expect(static_cast<bool>(expression), 1) ? (void)0 \
+ : _LIBCPP_ASSERT_IS_CONSTANT_EVALUATED \
+ ? __builtin_unreachable() \
----------------
MitalAshok wrote:
The original idea was the diagnostic would be consistent, but on second thoughts that isn't worth the extra complexity. I'll revert this.
https://github.com/llvm/llvm-project/pull/107713
More information about the libcxx-commits
mailing list