Skip to content

Commit 6dafae8

Browse files
authored
Merge pull request #69746 from apple/egorzhdan/avoid-rvalue-this-inheritance
[cxx-interop] Do not import inherited methods with rvalue this
2 parents aa9f129 + f9bf957 commit 6dafae8

File tree

4 files changed

+16
-0
lines changed

4 files changed

+16
-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-module-interface.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
// CHECK-NEXT: @discardableResult
1616
// CHECK-NEXT: func constInBase() -> UnsafePointer<CChar>!
1717
// CHECK-NEXT: @discardableResult
18+
// CHECK-NEXT: func rvalueThisInBase() -> UnsafePointer<CChar>!
19+
// CHECK-NEXT: @discardableResult
1820
// CHECK-NEXT: func takesArgsInBase(_ a: Int32, _ b: Int32, _ c: Int32) -> UnsafePointer<CChar>!
1921
// CHECK-NEXT: @discardableResult
2022
// CHECK-NEXT: func takesNonTrivialInBase(_ a: NonTrivial) -> UnsafePointer<CChar>!

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)