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

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Fri Oct 31 06:15:49 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
----------------
philnik777 wrote:

```suggestion
    // `p2` was moved from. In libc++ it will be nullptr, but
    // this is not guaranteed by the standard.
    LIBCPP_ASSERT(p2 == nullptr);
    LIBCPP_ASSERT(p2 == nullptr);
```

or is there a reason we can't implement this for MSVC?

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


More information about the libcxx-commits mailing list