[libcxx-commits] [libcxx] [libc++] Handle Clang function effect analysis in hardening assertions (PR #177447)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Fri Jan 23 00:53:08 PST 2026


================
@@ -17,11 +17,17 @@
 #  pragma GCC system_header
 #endif
 
+// Note that we disable -Wfunction-effects inside _LIBCPP_ASSERT when the assertion fails since
+// function effect attributes don't provide any guarantees once a function is determined to be
+// out of contract.
 #define _LIBCPP_ASSERT(expression, message)                                                                            \
   (__builtin_expect(static_cast<bool>(expression), 1)                                                                  \
        ? (void)0                                                                                                       \
-       : _LIBCPP_ASSERTION_HANDLER(__FILE__ ":" _LIBCPP_TOSTRING(                                                      \
-             __LINE__) ": libc++ Hardening assertion " _LIBCPP_TOSTRING(expression) " failed: " message "\n"))
+       : _LIBCPP_DIAGNOSTIC_PUSH                                    /*                                              */ \
----------------
philnik777 wrote:

This seems like a rather big hammer to me. While usually acceptable, pushing and popping diagnostics is a relatively expensive operation, and this adds a scope to every single assert in our code base. More generally, how does this even show up? None of the warnings related to `-Wfunction-effects` seems to be shown in system headers or even macros, and the last time I checked we didn't support using `-Wsystem-headers`. Godbolt seems to support that they don't show up: https://godbolt.org/z/Gzcr386Tx

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


More information about the libcxx-commits mailing list