[libcxx-commits] [libcxxabi] [libcxx] [libc++] Fix noexcept behaviour of operator new helper functions (PR #74337)

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Jan 15 06:50:16 PST 2024


================
@@ -0,0 +1,42 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+// UNSUPPORTED: no-exceptions
+#include <new>
+#include <cassert>
+#include <limits>
+#include <cstdlib>
+
+struct construction_key {};
+struct my_bad_alloc : std::bad_alloc {
+  my_bad_alloc(const my_bad_alloc&) : self(this) { std::abort(); }
+  my_bad_alloc(construction_key) : self(this) {}
+  const my_bad_alloc* const self;
+};
+
+int new_handler_called = 0;
+
+void my_new_handler() {
+  ++new_handler_called;
+  throw my_bad_alloc(construction_key{});
----------------
ldionne wrote:

This construction pattern isn't valid in C++03 mode. You should use `throw my_bad_alloc(construction_key())`

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


More information about the libcxx-commits mailing list