Files
swift-mirror/test/Interop/Cxx/reference/reference-cannot-import-diagnostic.swift
Gabor Horvath 1601564342 [cxx-interop] Import rvalue references as consuming parameters
Unfortunately, importing them as is results in ambiguous call sites.
E.g., std::vector::push_back has overloads for lvalue reference and
rvalue reference and we have no way to distinguish them at the call site
in Swift. To overcome this issue, functions with rvalue reference
parameters are imported with 'consuming:' argument labels.

Note that, in general, move only types and consuming is not properly
supported in Swift yet. We do not invoke the dtor for the moved-from
objects. This is a preexisting problem that can be observed with move
only types before this PR, so the fix will be done in a separate PR.
Fortunately, for most types, the moved-from objects do not require
additional cleanups.

rdar://125816354
2024-12-02 13:09:21 +00:00

31 lines
804 B
Swift

// RUN: rm -rf %t
// RUN: split-file %s %t
// RUN: %target-swift-frontend -typecheck -verify -I %t/Inputs %t/test.swift -enable-experimental-cxx-interop
// RUN: not %target-swift-frontend -typecheck -I %t/Inputs %t/test.swift -enable-experimental-cxx-interop 2>&1 | %FileCheck %s
//--- Inputs/module.modulemap
module Test {
header "test.h"
requires cplusplus
}
//--- Inputs/test.h
void acceptRValueRef(int &&);
template<class T>
void notStdMove(T &&);
//--- test.swift
import Test
public func test() {
var x: CInt = 2
acceptRValueRef(consuming: x)
notStdMove(x) // expected-error {{cannot find 'notStdMove' in scope}}
// CHECK: note: function 'notStdMove' unavailable (cannot import)
// CHECK: note: C++ functions with rvalue reference parameters are unavailable in Swift
}