Skip to content

[cxx-interop] Do not import inherited methods with rvalue this #69746

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 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5481,6 +5481,13 @@ cloneBaseMemberDecl(ValueDecl *decl, DeclContext *newContext) {
(fn->getClangDecl() &&
isa<clang::FunctionTemplateDecl>(fn->getClangDecl())))
return nullptr;
if (auto cxxMethod =
dyn_cast_or_null<clang::CXXMethodDecl>(fn->getClangDecl())) {
// FIXME: if this function has rvalue this, we won't be able to synthesize
// the accessor correctly (https://github.com/apple/swift/issues/69745).
if (cxxMethod->getRefQualifier() == clang::RefQualifierKind::RQ_RValue)
return nullptr;
}

ASTContext &context = decl->getASTContext();
auto out = FuncDecl::createImplicit(
Expand Down
4 changes: 4 additions & 0 deletions test/Interop/Cxx/class/inheritance/Inputs/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ struct Base {
__attribute__((swift_attr("import_unsafe"))) {
return "Base::constInBase";
}
inline const char *rvalueThisInBase() const&&
__attribute__((swift_attr("import_unsafe"))) {
return "Base::rvalueThisInBase";
}
// TODO: if these are unnamed we hit an (unrelated) SILGen bug. Same for
// subscripts.
inline const char *takesArgsInBase(int a, int b, int c) const
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
// CHECK-NEXT: @discardableResult
// CHECK-NEXT: func constInBase() -> UnsafePointer<CChar>!
// CHECK-NEXT: @discardableResult
// CHECK-NEXT: func rvalueThisInBase() -> UnsafePointer<CChar>!
// CHECK-NEXT: @discardableResult
// CHECK-NEXT: func takesArgsInBase(_ a: Int32, _ b: Int32, _ c: Int32) -> UnsafePointer<CChar>!
// CHECK-NEXT: @discardableResult
// CHECK-NEXT: func takesNonTrivialInBase(_ a: NonTrivial) -> UnsafePointer<CChar>!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ Derived().sameMethodNameSameSignature()
Derived().sameMethodDifferentSignature(1)
// ok, this is the base class method.
Derived().sameMethodDifferentSignature()

// FIXME: we should import this (https://github.com/apple/swift/issues/69745):
Derived().rvalueThisInBase() // expected-error {{value of type 'Derived' has no member 'rvalueThisInBase'}}