Skip to content

C++ foreign type's dtor needs to be invoked on moved-from objects #77894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Xazax-hun opened this issue Dec 2, 2024 · 0 comments · Fixed by #79576
Closed

C++ foreign type's dtor needs to be invoked on moved-from objects #77894

Xazax-hun opened this issue Dec 2, 2024 · 0 comments · Fixed by #79576
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++ clang importer Area → compiler: The clang importer compiler The Swift compiler itself ownership Feature: Ownership modifiers and semantics swift 6.0 unexpected behavior Bug: Unexpected behavior or incorrect output

Comments

@Xazax-hun
Copy link
Contributor

Description

When passing a type imported from C++ to a consuming Swift function (or a C++ foreign API taking an rvalue reference), the caller is still responsible for destroying the object (calling the dtor) regardless whether the object.

Reproduction

let x = getCppMoveOnlyType()
consumingFunction(x)

Expected behavior

The dtor for x is invoked after the last use.

Environment

swift-driver version: 1.115 Apple Swift version 6.0.2 (swiftlang-6.0.2.1.2 clang-1600.0.26.4)
Target: arm64-apple-macosx15.0

Additional information

No response

@Xazax-hun Xazax-hun added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++ triage needed This issue needs more specific labels labels Dec 2, 2024
Xazax-hun pushed a commit that referenced this issue Feb 24, 2025
In C++, we always expected to invoke the dtor for moved-from objects.
This is not the case for swift. Fortunately, @incxx calling convention
is already expressing that the caller supposed to destroy the object.
This fixes the missing dtor calls when calling C++ functions taking
rvalue references. Fixes #77894.

rdar://140786022
Xazax-hun pushed a commit that referenced this issue Feb 25, 2025
In C++, we always expected to invoke the dtor for moved-from objects.
This is not the case for swift. Fortunately, @incxx calling convention
is already expressing that the caller supposed to destroy the object.
This fixes the missing dtor calls when calling C++ functions taking
rvalue references. Fixes #77894.

rdar://140786022
Xazax-hun pushed a commit that referenced this issue Feb 26, 2025
In C++, we always expected to invoke the dtor for moved-from objects.
This is not the case for swift. Fortunately, @incxx calling convention
is already expressing that the caller supposed to destroy the object.
This fixes the missing dtor calls when calling C++ functions taking
rvalue references. Fixes #77894.

rdar://140786022
Xazax-hun pushed a commit that referenced this issue Mar 3, 2025
In C++, we always expected to invoke the dtor for moved-from objects.
This is not the case for swift. Fortunately, @incxx calling convention
is already expressing that the caller supposed to destroy the object.
This fixes the missing dtor calls when calling C++ functions taking
rvalue references. Fixes #77894.

rdar://140786022
@AnthonyLatsis AnthonyLatsis added compiler The Swift compiler itself ownership Feature: Ownership modifiers and semantics swift 6.0 clang importer Area → compiler: The clang importer unexpected behavior Bug: Unexpected behavior or incorrect output and removed triage needed This issue needs more specific labels labels Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. c++ interop Feature: Interoperability with C++ clang importer Area → compiler: The clang importer compiler The Swift compiler itself ownership Feature: Ownership modifiers and semantics swift 6.0 unexpected behavior Bug: Unexpected behavior or incorrect output
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants