File tree Expand file tree Collapse file tree 2 files changed +20
-0
lines changed
test/Interop/SwiftToCxx/stdlib/string Expand file tree Collapse file tree 2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,17 @@ SWIFT_INLINE_THUNK T_0_0 get() const
35
35
36
36
#ifndef SWIFT_CXX_INTEROP_HIDE_STL_OVERLAY
37
37
38
+ // / Constructs a Swift string from a C string.
39
+ SWIFT_INLINE_THUNK String (const char *cString) noexcept {
40
+ if (!cString) {
41
+ auto res = _impl::$sS2SycfC ();
42
+ memcpy (_getOpaquePointer (), &res, sizeof (res));
43
+ return ;
44
+ }
45
+ auto res = _impl::$sSS7cStringSSSPys4Int8VG_tcfC (cString);
46
+ memcpy (_getOpaquePointer (), &res, sizeof (res));
47
+ }
48
+
38
49
// / Constructs a Swift string from a C++ string.
39
50
SWIFT_INLINE_THUNK String (const std::string &str) noexcept {
40
51
auto res = _impl::$sSS7cStringSSSPys4Int8VG_tcfC (str.c_str ());
Original file line number Diff line number Diff line change @@ -34,8 +34,17 @@ int main() {
34
34
{
35
35
auto s = String (" hello world" );
36
36
printString (s);
37
+ swift::String s2 = " Hello literal" ;
38
+ printString (s2);
39
+ const char *literal = " Test literal via ptr" ;
40
+ printString (literal);
41
+ swift::String s3 = nullptr ;
42
+ printString (s3);
37
43
}
38
44
// CHECK: '''hello world'''
45
+ // CHECK-NEXT: '''Hello literal'''
46
+ // CHECK-NEXT: '''Test literal via ptr'''
47
+ // CHECK-NEXT: ''''''
39
48
40
49
{
41
50
std::string str = " test std::string" ;
You can’t perform that action at this time.
0 commit comments