Skip to content

[cxx-interop] Check the safety of C++ template arguments #78522

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

Merged
merged 1 commit into from
Jan 20, 2025

Conversation

Xazax-hun
Copy link
Contributor

Swift imports template specializations as a standalone type (not as an instantiation of a generic) so unsafety is not propagated from the template arguments to the specialization. This PR propagates this information explicitly.

@Xazax-hun Xazax-hun added the c++ interop Feature: Interoperability with C++ label Jan 9, 2025
@Xazax-hun
Copy link
Contributor Author

@swift-ci please smoke test

@Xazax-hun Xazax-hun force-pushed the gaborh/instantiation-unsafe branch from 62ff0d6 to 9856c1d Compare January 14, 2025 13:12
@Xazax-hun Xazax-hun requested a review from jckarter as a code owner January 14, 2025 13:12
@Xazax-hun
Copy link
Contributor Author

@swift-ci please smoke test

@Xazax-hun
Copy link
Contributor Author

@swift-ci please build toolchain macOS

@Xazax-hun Xazax-hun force-pushed the gaborh/instantiation-unsafe branch from 9856c1d to d6499b8 Compare January 16, 2025 13:18
@Xazax-hun
Copy link
Contributor Author

@swift-ci please smoke test

Comment on lines 2197 to 2198
if (arg.getKind() != clang::TemplateArgument::Type)
continue;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this work with pack arguments, e.g. std::tuple<Safe, Safe, Unsafe>?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! Added support or that.

Swift imports template specializations as a standalone type (not as an
instantiation of a generic) so unsafety is not propagated from the
template arguments to the specialization. This PR propagates this
information explicitly.
@Xazax-hun Xazax-hun force-pushed the gaborh/instantiation-unsafe branch from d6499b8 to f12b48a Compare January 17, 2025 17:39
@Xazax-hun
Copy link
Contributor Author

@swift-ci please smoke test

@Xazax-hun
Copy link
Contributor Author

@swift-ci please smoke test linux

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.

LGTM, thanks!

@Xazax-hun Xazax-hun merged commit 3bbb126 into main Jan 20, 2025
3 checks passed
@Xazax-hun Xazax-hun deleted the gaborh/instantiation-unsafe branch January 20, 2025 17:00
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.

2 participants