Skip to content

Commit 175b64e

Browse files
authored
Merge pull request #65665 from hyp/eng/function-template-rvalue-ref
[interop] do not import function template with templated rvalue ref
2 parents 42bd9d0 + 196c717 commit 175b64e

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2346,6 +2346,12 @@ ClangImporter::Implementation::importParameterType(
23462346
return None;
23472347
} else if (isa<clang::ReferenceType>(paramTy) &&
23482348
isa<clang::TemplateTypeParmType>(paramTy->getPointeeType())) {
2349+
// We don't support rvalue reference / universal perfect ref, bail.
2350+
if (paramTy->isRValueReferenceType()) {
2351+
addImportDiagnosticFn(Diagnostic(diag::rvalue_ref_params_not_imported));
2352+
return None;
2353+
}
2354+
23492355
auto templateParamType =
23502356
cast<clang::TemplateTypeParmType>(paramTy->getPointeeType());
23512357
swiftParamTy = findGenericTypeInGenericDecls(

test/Interop/Cxx/reference/reference-cannot-import-diagnostic.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: rm -rf %t
22
// RUN: split-file %s %t
3+
// RUN: %target-swift-frontend -typecheck -verify -I %t/Inputs %t/test.swift -enable-experimental-cxx-interop
34
// RUN: not %target-swift-frontend -typecheck -I %t/Inputs %t/test.swift -enable-experimental-cxx-interop 2>&1 | %FileCheck %s
45

56
//--- Inputs/module.modulemap
@@ -12,13 +13,20 @@ module Test {
1213

1314
void acceptRValueRef(int &&);
1415

16+
template<class T>
17+
void notStdMove(T &&);
18+
1519
//--- test.swift
1620

1721
import Test
1822

1923
public func test() {
2024
var x: CInt = 2
21-
acceptRValueRef(x)
25+
acceptRValueRef(x) // expected-error {{cannot find 'acceptRValueRef' in scope}}
2226
// CHECK: note: function 'acceptRValueRef' unavailable (cannot import)
2327
// CHECK: note: C++ functions with rvalue reference parameters are unavailable in Swift
28+
29+
notStdMove(x) // expected-error {{cannot find 'notStdMove' in scope}}
30+
// CHECK: note: function 'notStdMove' unavailable (cannot import)
31+
// CHECK: note: C++ functions with rvalue reference parameters are unavailable in Swift
2432
}

test/Interop/Cxx/templates/function-template-module-interface.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
// CHECK: func lvalueReference<T>(_ ref: inout T)
2222
// CHECK: func constLvalueReference<T>(_: T)
23-
// CHECK: func forwardingReference<T>(_: inout T)
2423
// CHECK: func PointerTemplateParameter<T>(_: UnsafeMutablePointer<T>)
2524

2625
// CHECK: enum Orbiters {

0 commit comments

Comments
 (0)