Files
swift-mirror/test/Interop/Cxx/swiftify-import/span-in-ctor.swift
Gabor Horvath d5faddaa9b [cxx-interop] Support Swiftifying C++ constructors
Unfortunately, there is no common abstraction for initializers and
functions in SwiftSyntax, so this PR rolls our own. Alternatively, we
could probably achieve something similar with a new protocol, but we
only needed a handful of fields so this change keeps it simple.

rdar://152112660
2025-06-04 10:06:16 +01:00

41 lines
943 B
Swift

// REQUIRES: swift_feature_SafeInteropWrappers
// FIXME swift-ci linux tests do not support std::span
// UNSUPPORTED: OS=linux-gnu, OS=linux-android, OS=linux-androideabi
// RUN: rm -rf %t
// RUN: split-file %s %t
// RUN: %target-swift-frontend -c -plugin-path %swift-plugin-dir -I %t/Inputs -Xcc -std=c++20 -cxx-interoperability-mode=default -enable-experimental-feature SafeInteropWrappers %t/method.swift -dump-macro-expansions -verify 2>&1 | %FileCheck %s
// CHECK: @_alwaysEmitIntoClient
// CHECK: public init(_ sp: Span<CInt>) {
// CHECK: unsafe self.init(IntSpan(sp))
// CHECK: }
//--- Inputs/module.modulemap
module Method {
header "method.h"
requires cplusplus
}
//--- Inputs/method.h
#include <span>
using IntSpan = std::span<const int>;
class Foo {
public:
Foo();
Foo(IntSpan sp [[clang::noescape]]);
};
//--- method.swift
import CxxStdlib
import Method
func test(s: Span<Int32>) {
var _ = Foo(s)
}