Skip to content

Commit 99f542a

Browse files
committed
[cxx-interop] Do not import inherited methods with rvalue this
We do not synthesize the inheritance thunks correctly for such methods. Do not try to synthesize them, as that causes issues when there are two overloads of the same method, one with rvalue this and one without. The proper solution is tracked as #69745 Unblocks rdar://114282353
1 parent 3eea9d6 commit 99f542a

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5481,6 +5481,13 @@ cloneBaseMemberDecl(ValueDecl *decl, DeclContext *newContext) {
54815481
(fn->getClangDecl() &&
54825482
isa<clang::FunctionTemplateDecl>(fn->getClangDecl())))
54835483
return nullptr;
5484+
if (auto cxxMethod =
5485+
dyn_cast_or_null<clang::CXXMethodDecl>(fn->getClangDecl())) {
5486+
// FIXME: if this function has rvalue this, we won't be able to synthesize
5487+
// the accessor correctly (https://github.com/apple/swift/issues/69745).
5488+
if (cxxMethod->getRefQualifier() == clang::RefQualifierKind::RQ_RValue)
5489+
return nullptr;
5490+
}
54845491

54855492
ASTContext &context = decl->getASTContext();
54865493
auto out = FuncDecl::createImplicit(

test/Interop/Cxx/class/inheritance/Inputs/functions.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ struct Base {
2222
__attribute__((swift_attr("import_unsafe"))) {
2323
return "Base::constInBase";
2424
}
25+
inline const char *rvalueThisInBase() const&&
26+
__attribute__((swift_attr("import_unsafe"))) {
27+
return "Base::rvalueThisInBase";
28+
}
2529
// TODO: if these are unnamed we hit an (unrelated) SILGen bug. Same for
2630
// subscripts.
2731
inline const char *takesArgsInBase(int a, int b, int c) const

test/Interop/Cxx/class/inheritance/functions-typechecker.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,6 @@ Derived().sameMethodNameSameSignature()
1717
Derived().sameMethodDifferentSignature(1)
1818
// ok, this is the base class method.
1919
Derived().sameMethodDifferentSignature()
20+
21+
// FIXME: we should import this (https://github.com/apple/swift/issues/69745):
22+
Derived().rvalueThisInBase() // expected-error {{value of type 'Derived' has no member 'rvalueThisInBase'}}

0 commit comments

Comments
 (0)