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
3535
3636#ifndef SWIFT_CXX_INTEROP_HIDE_STL_OVERLAY
3737
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+
3849// / Constructs a Swift string from a C++ string.
3950SWIFT_INLINE_THUNK String (const std::string &str) noexcept {
4051 auto res = _impl::$sSS7cStringSSSPys4Int8VG_tcfC (str.c_str ());
Original file line number Diff line number Diff line change @@ -34,8 +34,17 @@ int main() {
3434 {
3535 auto s = String (" hello world" );
3636 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);
3743 }
3844// CHECK: '''hello world'''
45+ // CHECK-NEXT: '''Hello literal'''
46+ // CHECK-NEXT: '''Test literal via ptr'''
47+ // CHECK-NEXT: ''''''
3948
4049 {
4150 std::string str = " test std::string" ;
You can’t perform that action at this time.
0 commit comments