Skip to content

Conversation

Xazax-hun
Copy link
Contributor

In the reverse interop header we generated move constructors that call abort at runtime. This is problematic for several reasons:

  • In C++14 and below some of our own generated functions like _make ended up calling the move constructor. Those are calling abort and also trigger unreachable code warning in newer versions of Clang. In C++17 and up it is fine due to the guaranteed copy elision.
  • Type traits are fooled and think these types are movable. As a result, libraries could generate calls to the aborting move ctor.

This PR removes the generation of move operations. As we generate copy operations, the compiler will not declare or define the move operations implicitly. Whenever the user goes out of their way and try to move an object they will get a copy instead.

rdar://150793518

In the reverse interop header we generated move constructors that call
abort at runtime. This is problematic for several reasons:
* In C++14 and below some of our own generated functions like _make
  ended up calling the move constructor. Those are calling abort and
  also trigger unreachable code warning in newer versions of Clang.
  In C++17 and up it is fine due to the guaranteed copy elision.
* Type traits are fooled and think these types are movable. As a result,
  libraries could generate calls to the aborting move ctor.

This PR removes the generation of move operations. As we generate copy
operations, the compiler will not declare or define the move operations
implicitly. Whenever the user goes out of their way and try to move an
object they will get a copy instead.

rdar://150793518
@Xazax-hun Xazax-hun added the c++ interop Feature: Interoperability with C++ label Jul 8, 2025
@Xazax-hun
Copy link
Contributor Author

@swift-ci please smoke test

Copy link
Contributor

@egorzhdan egorzhdan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks!

@AnthonyLatsis
Copy link
Collaborator

@swift-ci please smoke test macOS

@Xazax-hun Xazax-hun enabled auto-merge July 8, 2025 21:24
@Xazax-hun
Copy link
Contributor Author

@swift-ci please smoke test macOS

@Xazax-hun Xazax-hun merged commit 2e789dc into swiftlang:main Jul 9, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ interop Feature: Interoperability with C++

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants