Skip to content

Commit 3ba22e2

Browse files
authored
Merge pull request swiftlang#84080 from Xazax-hun/fix-rvalue-ref-virtual-on-6.2
[6.2][cxx-interop] Fix import virtual methods with rvalue ref params
2 parents a2ced86 + 448cdce commit 3ba22e2

File tree

4 files changed

+46
-5
lines changed

4 files changed

+46
-5
lines changed

lib/ClangImporter/SwiftDeclSynthesizer.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2168,11 +2168,18 @@ clang::CXXMethodDecl *SwiftDeclSynthesizer::synthesizeCXXForwardingMethod(
21682168
for (size_t i = 0; i < newMethod->getNumParams(); ++i) {
21692169
auto *param = newMethod->getParamDecl(i);
21702170
auto type = param->getType();
2171-
if (type->isReferenceType())
2172-
type = type->getPointeeType();
2173-
args.push_back(new (clangCtx) clang::DeclRefExpr(
2174-
clangCtx, param, false, type, clang::ExprValueKind::VK_LValue,
2175-
clang::SourceLocation()));
2171+
clang::Expr *argExpr = new (clangCtx) clang::DeclRefExpr(
2172+
clangCtx, param, false, type.getNonReferenceType(),
2173+
clang::ExprValueKind::VK_LValue, clang::SourceLocation());
2174+
if (type->isRValueReferenceType()) {
2175+
argExpr = clangSema
2176+
.BuildCXXNamedCast(
2177+
clang::SourceLocation(), clang::tok::kw_static_cast,
2178+
clangCtx.getTrivialTypeSourceInfo(type), argExpr,
2179+
clang::SourceRange(), clang::SourceRange())
2180+
.get();
2181+
}
2182+
args.push_back(argExpr);
21762183
}
21772184
auto memberCall = clangSema.BuildCallExpr(
21782185
nullptr, memberExpr, clang::SourceLocation(), args,

test/Interop/Cxx/foreign-reference/Inputs/module.modulemap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,8 @@ module Printed {
6868
header "printed.h"
6969
requires cplusplus
7070
}
71+
72+
module VirtMethodWithRvalRef {
73+
header "virtual-methods-with-rvalue-reference.h"
74+
requires cplusplus
75+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#pragma once
2+
3+
#include "swift/bridging"
4+
5+
class CxxForeignRef;
6+
7+
void retain(CxxForeignRef * obj);
8+
void release(CxxForeignRef * obj);
9+
10+
struct NonTrivial {
11+
NonTrivial(const NonTrivial &other);
12+
~NonTrivial();
13+
};
14+
15+
class CxxForeignRef {
16+
public:
17+
CxxForeignRef(const CxxForeignRef &) = delete;
18+
CxxForeignRef() = default;
19+
20+
virtual void takesRValRef(NonTrivial &&);
21+
} SWIFT_SHARED_REFERENCE(retain, release);
22+
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %target-swift-frontend -typecheck -verify -I %S/Inputs -I %swift_src_root/lib/ClangImporter/SwiftBridging %s -cxx-interoperability-mode=default -disable-availability-checking
2+
3+
import VirtMethodWithRvalRef
4+
5+
func f(_ x: CxxForeignRef, _ y: NonTrivial) {
6+
x.takesRValRef(consuming: y)
7+
}

0 commit comments

Comments
 (0)