Skip to content

[iOS] Swift/C++ interop instantiates implicit copy ctor of TraceRecordingState, fails on RuntimeSamplingProfile's deleted copy ctor ("no matching function for call to '__construct_at'") #57632

Description

@kapooraryan

Description

Gist : When a Swift file in an iOS app talks to React Native's C++ code with
Swift/C++ interop turned on, the build fails, because the compiler tries to make
a copy of an internal tracing object that was only ever designed to be moved, not
copied.

Note: This particular PR : #57606 may have already resolved this issue

Building an iOS app with Swift/C++ interop enabled (-cxx-interoperability-mode=default)
alongside a Swift file that imports React Native's C++ headers (directly, or
transitively through a library using Swift C++ interop) fails to compile with:

    error: no matching function for call to '__construct_at'
    note: in instantiation of member function 'std::vector<...RuntimeSamplingProfile>::vector' requested here
    note: in implicit copy constructor for
    'facebook::react::jsinspector_modern::tracing::TraceRecordingState' first required here

TraceRecordingState (in ReactCommon/jsinspector-modern/tracing/TraceRecordingState.h)
holds a std::vector<RuntimeSamplingProfile> runtimeSamplingProfiles.
RuntimeSamplingProfile explicitly deletes its copy constructor, since it owns a
std::unique_ptr<RawRuntimeProfile> and is move-only.
TraceRecordingState itself declares no copy/move members, so its implicit copy
constructor exists but is ill-formed the moment anything asks for a copy.

Plain C++/ObjC++ compilation never asks for a copy. Every usage in RN passes by
reference or moves, so this has always compiled fine outside of Swift interop. But
Swift's ClangImporter surfaces the type to Swift as copyable and synthesizes a copy
when bridging it, forcing instantiation of the broken implicit copy constructor,
which hard-errors the whole module import.

Suggested Fix (specific to TraceRecordingState.h)

TraceRecordingState.h should explicitly declare itself move-only, matching the
actual semantics of its RuntimeSamplingProfile member instead of relying on an
implicit copy constructor that was never meant to be usable:

// Movable.
TraceRecordingState(TraceRecordingState &&) = default;
TraceRecordingState &operator=(TraceRecordingState &&) = default;

// Not copyable (contains RuntimeSamplingProfile, which owns a unique_ptr
// and is itself move-only).
TraceRecordingState(const TraceRecordingState &) = delete;
TraceRecordingState &operator=(const TraceRecordingState &) = delete;

I've verified locally that this resolves the build failure via patch-package.

Steps to reproduce

  1. Create a React Native 0.85.1 app with the new architecture enabled.
  2. Add any Swift file to the iOS project that subclasses RCTEventEmitter (or
    RCTViewManager) and import React.
  3. Build for Debug .
  4. Observe the build fail with no matching function for call to '__construct_at' originating in allocator_traits.h, tracing back through
    TraceRecordingState's implicit copy constructor.

React Native Version

0.85.1

Affected Platforms

Runtime - iOS

Output of npx @react-native-community/cli info

info Fetching system and libraries information...
System:
  OS: macOS 26.5.2
  CPU: (8) arm64 Apple M3
  Memory: 197.92 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 22.12.0
    path: /usr/local/bin/node
  Yarn:
    version: 1.22.22
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.9.0
    path: /usr/local/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods:
    version: 1.16.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 25.1
      - iOS 26.1
      - macOS 26.1
      - tvOS 26.1
      - visionOS 26.1
      - watchOS 26.1
  Android SDK: Not Found
IDEs:
  Android Studio: 2026.1 AI-261.23567.138.2611.15646644
  Xcode:
    version: 26.1.1/17B100
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.17
    path: /opt/homebrew/opt/openjdk@17/bin/javac
  Ruby:
    version: 3.4.1
    path: /opt/homebrew/opt/ruby/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 20.1.0
    wanted: 20.1.0
  react:
    installed: 19.2.3
    wanted: 19.2.3
  react-native:
    installed: 0.85.1
    wanted: 0.85.1
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

info React Native v0.86.0 is now available (your project is running on v0.85.1).
info Changelog: https://github.com/facebook/react-native/releases/tag/v0.86.0
info Diff: https://react-native-community.github.io/upgrade-helper/?from=0.85.1&to=0.86.0
info For more info, check out "https://reactnative.dev/docs/upgrading?os=macos".

Stacktrace or Logs

error: no matching function for call to '__construct_at'
    std::__construct_at(__p, std::forward<_Args>(__args)...);
    ^
<toolchain>/usr/include/c++/v1/__memory/allocator_traits.h:318:5: error: no matching function for call to '__construct_at'
    std::__construct_at(__p, std::forward<_Args>(__args)...);
    ^
<toolchain>/usr/include/c++/v1/__memory/uninitialized_algorithms.h:550:31: note: in instantiation of function template specialization 'std::allocator_traits<std::allocator<facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile>>::construct<facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile, facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile &, void, 0>' requested here
    allocator_traits<_Alloc>::construct(__alloc, std::__to_address(__first2), *__first1);
                              ^
<toolchain>/usr/include/c++/v1/__memory/uninitialized_algorithms.h:589:33: note: in instantiation of function template specialization 'std::__uninitialized_allocator_copy_impl<std::allocator<facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile>, facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile *, facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile *, facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile *>' requested here
  auto __result          = std::__uninitialized_allocator_copy_impl(
                                ^
<toolchain>/usr/include/c++/v1/__vector/vector.h:931:22: note: in instantiation of function template specialization 'std::__uninitialized_allocator_copy<std::allocator<facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile>, facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile *, facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile *, facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile *>' requested here
  __tx.__pos_ = std::__uninitialized_allocator_copy(this->__alloc_, std::move(__first), std::move(__last), __tx.__pos_);
                     ^
<toolchain>/usr/include/c++/v1/__vector/vector.h:581:7: note: in instantiation of function template specialization 'std::vector<facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile>::__construct_at_end<facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile *, facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile *>' requested here
      __construct_at_end(std::move(__first), std::move(__last), __n);
      ^
<toolchain>/usr/include/c++/v1/__vector/vector.h:263:5: note: in instantiation of function template specialization 'std::vector<facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile>::__init_with_size<facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile *, facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile *>' requested here
    __init_with_size(__x.__begin_, __x.__end_, __x.size());
    ^
Pods/Headers/Public/React-jsinspectortracing/jsinspector-modern/tracing/TraceRecordingState.h:25:8: note: in instantiation of member function 'std::vector<facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile>::vector' requested here
struct TraceRecordingState {
       ^
<unknown>:0: note: in implicit copy constructor for 'facebook::react::jsinspector_modern::tracing::TraceRecordingState' first required here
<toolchain>/usr/include/c++/v1/__memory/construct_at.h:46:58: note: candidate template ignored: substitution failure [with _Tp = facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile, _Args = <facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile &>]: call to deleted constructor of 'facebook::react::jsinspector_modern::tracing::RuntimeSamplingProfile'
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 _Tp* __construct_at(_Tp* __location, _Args&&... __args) {
                                                         ^

MANDATORY Reproducer

Screenshots and Videos

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Author FeedbackNeeds: ReproThis issue could be improved with a clear list of steps to reproduce the issue.Platform: iOSiOS applications.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions