[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:04 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:

#107715 means that an unguarded:

```c++
#define _LIBCPP_ASSERT_IS_CONSTANT_EVALUATED                                         \
  (_LIBCPP_DIAGNOSTIC_PUSH _LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wconstant-evaluated")  \
      __builtin_is_constant_evaluated() _LIBCPP_DIAGNOSTIC_POP)
```

doesn't actually ignore the diagnostic (The diagnostic being an assertion used in a consteval function or the true branch of a consteval if or some other manifestly constant evaluated context)


https://github.com/llvm/llvm-project/pull/107713


More information about the libcxx-commits mailing list