Skip to content

Commit 055d2fd

Browse files
authored
Merge pull request #60267 from apple/egorzhdan/cxx-std-string-literal
[cxx-interop] Conform `std::string` to `ExpressibleByStringLiteral`
2 parents 8da01aa + d6089c9 commit 055d2fd

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

stdlib/public/Cxx/std/String.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ extension std.string {
1919
}
2020
}
2121

22+
extension std.string: ExpressibleByStringLiteral {
23+
public init(stringLiteral value: String) {
24+
self.init(value)
25+
}
26+
}
27+
2228
extension String {
2329
public init(cxxString: std.string) {
2430
self.init(cString: cxxString.__c_strUnsafe())

test/Interop/Cxx/stdlib/overlay/std-string-overlay.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ StdStringOverlayTestSuite.test("std::string <=> Swift.String") {
1616
let cxx2 = std.string("something123")
1717
let swift2 = String(cxxString: cxx2)
1818
expectEqual(swift2, "something123")
19+
20+
let cxx3: std.string = "literal"
21+
expectEqual(cxx3.size(), 7)
1922
}
2023

2124
extension std.string.const_iterator: UnsafeCxxInputIterator {

0 commit comments

Comments
 (0)