[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
Fri Sep 13 06:50:42 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
----------------
MitalAshok wrote:
This would be diagnosed if used in a manifestly constant evaluated context. This is mainly in an `if consteval` branch or `consteval` function. No `if consteval` currently exists in libc++ and no `consteval` libc++ functions contain any assertions, but in the future they might.
Also more exotic cases, like when the assertion is directly in a constinit initialiser, array bound or static_assert, like in the added test. But these will never happen in real libc++ code.
https://github.com/llvm/llvm-project/pull/107713
More information about the libcxx-commits
mailing list