[libcxx-commits] [libcxx] [libc++] Inline fast path for`exception_ptr` copy constructor & destructor (PR #165909)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Mon Nov 10 09:45:57 PST 2025


================
@@ -82,17 +85,42 @@ class _LIBCPP_EXPORTED_FROM_ABI exception_ptr {
   _LIBCPP_HIDE_FROM_ABI exception_ptr() _NOEXCEPT : __ptr_() {}
   _LIBCPP_HIDE_FROM_ABI exception_ptr(nullptr_t) _NOEXCEPT : __ptr_() {}
 
+// These symbols are still exported from the library to prevent ABI breakage.
+#  ifdef _LIBCPP_BUILDING_LIBRARY
   exception_ptr(const exception_ptr&) _NOEXCEPT;
+  exception_ptr& operator=(const exception_ptr&) _NOEXCEPT;
+  ~exception_ptr() _NOEXCEPT;
+#  else  // _LIBCPP_BUILDING_LIBRARY
+  _LIBCPP_HIDE_FROM_ABI exception_ptr(const exception_ptr&) _NOEXCEPT : __ptr_(__other.__ptr_) {
+    if (__ptr_)
+      __increment_refcount(__ptr_);
+  }
+  _LIBCPP_HIDE_FROM_ABI exception_ptr& operator=(const exception_ptr&) _NOEXCEPT {
+    if (__ptr_ != __other.__ptr_) {
+      if (__other.__ptr_)
+        __increment_refcount(__other.__ptr_);
+      if (__ptr_)
+        __decrement_refcount(__ptr_);
+      __ptr_ = __other.__ptr_;
+    }
+    return *this;
+  }
+  _LIBCPP_HIDE_FROM_ABI ~exception_ptr() _NOEXCEPT {
+    if (__ptr_)
+      __decrement_refcount(__ptr_);
+  }
+#  endif // _LIBCPP_BUILDING_LIBRARY
+
   _LIBCPP_HIDE_FROM_ABI exception_ptr(exception_ptr&& __other) _NOEXCEPT : __ptr_(__other.__ptr_) {
     __other.__ptr_ = nullptr;
   }
-  exception_ptr& operator=(const exception_ptr&) _NOEXCEPT;
   _LIBCPP_HIDE_FROM_ABI exception_ptr& operator=(exception_ptr&& __other) _NOEXCEPT {
-    exception_ptr __tmp(std::move(__other));
-    std::swap(__tmp, *this);
+    if (__ptr_)
+      __decrement_refcount(__ptr_);
+    __ptr_         = __other.__ptr_;
+    __other.__ptr_ = nullptr;
----------------
philnik777 wrote:

Is this change required?

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


More information about the libcxx-commits mailing list