mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[cxx-interop] Fix import virtual methods with rvalue ref params
We generate forwarding calls for virutal methods. These forwarding calls had a type error when the original parameter had an rvalue reference type. In those scenarios we need to insert a static cast to make the type checker happy. rdar://154969620
This commit is contained in:
@@ -2176,11 +2176,18 @@ clang::CXXMethodDecl *SwiftDeclSynthesizer::synthesizeCXXForwardingMethod(
|
||||
for (size_t i = 0; i < newMethod->getNumParams(); ++i) {
|
||||
auto *param = newMethod->getParamDecl(i);
|
||||
auto type = param->getType();
|
||||
if (type->isReferenceType())
|
||||
type = type->getPointeeType();
|
||||
args.push_back(new (clangCtx) clang::DeclRefExpr(
|
||||
clangCtx, param, false, type, clang::ExprValueKind::VK_LValue,
|
||||
clang::SourceLocation()));
|
||||
clang::Expr *argExpr = new (clangCtx) clang::DeclRefExpr(
|
||||
clangCtx, param, false, type.getNonReferenceType(),
|
||||
clang::ExprValueKind::VK_LValue, clang::SourceLocation());
|
||||
if (type->isRValueReferenceType()) {
|
||||
argExpr = clangSema
|
||||
.BuildCXXNamedCast(
|
||||
clang::SourceLocation(), clang::tok::kw_static_cast,
|
||||
clangCtx.getTrivialTypeSourceInfo(type), argExpr,
|
||||
clang::SourceRange(), clang::SourceRange())
|
||||
.get();
|
||||
}
|
||||
args.push_back(argExpr);
|
||||
}
|
||||
auto memberCall = clangSema.BuildCallExpr(
|
||||
nullptr, memberExpr, clang::SourceLocation(), args,
|
||||
|
||||
Reference in New Issue
Block a user