Skip to content

[cxx-interop] Import using decls that expose methods from private base classes #69623

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
Nov 14, 2023

Conversation

egorzhdan
Copy link
Contributor

If a C++ type Derived inherits from Base privately, the public methods from Base should not be callable on an instance of Derived. However, C++ supports exposing such methods via a using declaration: using MyPrivateBase::myPublicMethod;.

MSVC started using this feature for std::optional which means Swift doesn't correctly import var pointee: Pointee for instantiations of std::optional on Windows. This prevents the automatic conformance to CxxOptional from being synthesized.

rdar://114282353 / resolves #68068

@egorzhdan egorzhdan added the c++ interop Feature: Interoperability with C++ label Nov 2, 2023
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan egorzhdan force-pushed the egorzhdan/using-base-cxx-method branch from c875b03 to 1e6954b Compare November 6, 2023 15:03
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan
Copy link
Contributor Author

@swift-ci please test

@egorzhdan
Copy link
Contributor Author

@swift-ci please test source compatibility

@egorzhdan egorzhdan force-pushed the egorzhdan/using-base-cxx-method branch from 1e6954b to e583acf Compare November 8, 2023 21:19
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@hyp
Copy link
Contributor

hyp commented Nov 10, 2023

is this source breaking by any chance?

@egorzhdan egorzhdan force-pushed the egorzhdan/using-base-cxx-method branch from 63d4947 to 35325af Compare November 10, 2023 18:10
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan
Copy link
Contributor Author

is this source breaking by any chance?

Yes, it is, I should probably guard this by version, thanks!

@egorzhdan egorzhdan force-pushed the egorzhdan/using-base-cxx-method branch 3 times, most recently from 9ba60f3 to ae8cf95 Compare November 13, 2023 17:04
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan egorzhdan force-pushed the egorzhdan/using-base-cxx-method branch from ae8cf95 to 0d35e5b Compare November 13, 2023 18:05
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@@ -2697,6 +2697,30 @@ namespace {
// SemaLookup.cpp).
if (!decl->isBeingDefined() && !decl->isDependentContext() &&
areRecordFieldsComplete(decl)) {
if (decl->hasInheritedConstructor() &&
Impl.isCxxInteropCompatVersionAtLeast(5, 11)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You should use isCxxInteropCompatVersionAtLeast(version::getUpcomingCxxInteropCompatVersion()) here instead. that will convert to a concrete one once we know the next version :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks!

// 2. C++ methods from privately inherited base classes
if (!isa<clang::TypeDecl>(decl->getTargetDecl()) &&
!(isa<clang::CXXMethodDecl>(decl->getTargetDecl()) &&
Impl.isCxxInteropCompatVersionAtLeast(5, 11)))
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto here.

Copy link
Contributor

@hyp hyp left a comment

Choose a reason for hiding this comment

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

Looks good with requested changes.

@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan egorzhdan force-pushed the egorzhdan/using-base-cxx-method branch from b0fc16e to 71aa696 Compare November 13, 2023 19:30
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan egorzhdan enabled auto-merge November 13, 2023 19:33
@ahoppen ahoppen removed their request for review November 13, 2023 20:39
@egorzhdan egorzhdan force-pushed the egorzhdan/using-base-cxx-method branch from 71aa696 to 25d9200 Compare November 13, 2023 21:30
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

…e classes

If a C++ type `Derived` inherits from `Base` privately, the public methods from `Base` should not be callable on an instance of `Derived`. However, C++ supports exposing such methods via a using declaration: `using MyPrivateBase::myPublicMethod;`.

MSVC started using this feature for `std::optional` which means Swift doesn't correctly import `var pointee: Pointee` for instantiations of `std::optional` on Windows. This prevents the automatic conformance to `CxxOptional` from being synthesized.

 rdar://114282353 / resolves #68068
@egorzhdan egorzhdan force-pushed the egorzhdan/using-base-cxx-method branch from 25d9200 to efc008a Compare November 14, 2023 00:31
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan egorzhdan merged commit 3ab2064 into main Nov 14, 2023
@egorzhdan egorzhdan deleted the egorzhdan/using-base-cxx-method branch November 14, 2023 06:10
hjyamauchi added a commit to hjyamauchi/swift that referenced this pull request Nov 13, 2024
…e classes

If a C++ type `Derived` inherits from `Base` privately, the public methods from `Base` should not be callable on an instance of `Derived`. However, C++ supports exposing such methods via a using declaration: `using MyPrivateBase::myPublicMethod;`.

MSVC started using this feature for `std::optional` which means Swift doesn't correctly import `var pointee: Pointee` for instantiations of `std::optional` on Windows. This prevents the automatic conformance to `CxxOptional` from being synthesized.

rdar://114282353 / resolves swiftlang#68068

Cherrypick commit efc008a
Cherrypick PR swiftlang#69623
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.

std.optional.pointee not synthesized on newer MSVC STL releases
2 participants