[libcxx-commits] [libcxx] [libc++] Fix missing 'get_new_handler()' for Windows builds (PR #150182)
via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Aug 15 00:56:44 PDT 2026
================
@@ -6,20 +6,37 @@
//
//===----------------------------------------------------------------------===//
+// a test will allocate an impossible amount of memory on purpose
+// and it will trigger an expected failure
+// UNSUPPORTED: asan, msan, tsan
+
// test set_new_handler
#include <new>
#include <cassert>
+#include <cstdlib>
+#include <limits>
+#include <climits>
#include "test_macros.h"
void f1() {}
void f2() {}
+void f3() { std::exit(0); }
+
+int main(int, char**) {
+ assert(std::set_new_handler(f1) == 0);
+ assert(std::set_new_handler(f2) == f1);
-int main(int, char**)
-{
- assert(std::set_new_handler(f1) == 0);
- assert(std::set_new_handler(f2) == f1);
+ // note: this test must be the last test since it will trigger
+ // the new handler and exit on the first call to it to signal success
+ // else we would be stuck in the handler being called in a loop
+ std::set_new_handler(f3);
+ size_t max_size = std::numeric_limits<size_t>::max();
+ // cap size to (~4GB) on 32-bit, (~1Exabytes) on 64-bit
+ size_t alloc_size = max_size > UINT_MAX ? max_size / 16 : max_size - 1;
----------------
siradam7th wrote:
It doesn't seem to be necessary anymore with SAN disabled, since just assigning `numeric_limits<size_t>::max()` to a variable is enough to stop Clang from issuing a warning.
https://github.com/llvm/llvm-project/pull/150182
More information about the libcxx-commits
mailing list