[libcxx-commits] [libcxx] [libc++] Add move constructor & assignment to `exception_ptr` (PR #164281)

Adrian Vogelsgesang via libcxx-commits libcxx-commits at lists.llvm.org
Fri Oct 31 06:50:38 PDT 2025


================
@@ -0,0 +1,44 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// <exception>
+
+// typedef unspecified exception_ptr;
+
+// Test the move assignment of exception_ptr
+
+#include <exception>
+#include <utility>
+#include <cassert>
+
+#include "test_macros.h"
+
+int main(int, char**)
+{
+    std::exception_ptr p = std::make_exception_ptr(42);
+    std::exception_ptr p2{p};
+    assert(p2 == p);
+    // Move assignment
+    std::exception_ptr p3
+    p3 = std::move(p2);
+    assert(p3 == p);
+    // `p2` was moved from. In libc++ it will be nullptr, but
+    // this is not guaranteed by the standard.
+    #if defined(_LIBCPP_VERSION) && !defined(_LIBCPP_ABI_MICROSOFT)
+    assert(p2 == nullptr);
+    assert(p2 == nullptr);
+    #endif
----------------
vogelsgesang wrote:

For MSVC, there are already existing implementations of move and assign which call into external `__ExceptionPtrSwap` and `__ExceptionPtrAssign` functions. Maybe they can be optimized / inlined, but I don't understand them.

There is a separate PR (#94977) which upstreams `__ExceptionPtrSwap`, `__ExceptionPtrAssign`. Before inlining & optimizing those functions, I guess this other PR should first be integrated.

The other PR states

> Petr explained to me that libc++ developers will be able to do the integration work 

but afaict none of the libc++ developers picked that work up so far.

I won't be able to do so either because I don't have a Windows machine at hand and won't be able to test it.
Furthermore, my motivation is rather low since I am not using libc++ on Windows and hence won't benefit from it

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


More information about the libcxx-commits mailing list