[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;
----------------
philnik777 wrote:

```suggestion
    if (__ptr_ == __other.__ptr_)
      return *this;
    if (__other.__ptr_)
      __increment_refcount(__other.__ptr_);
    if (__ptr_)
      __decrement_refcount(__ptr_);
    __ptr_ = __other.__ptr_;
    return *this;
```


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


More information about the libcxx-commits mailing list