Skip to content

Commit 59bb4cb

Browse files
authored
Merge pull request swiftlang#59297 from apple/egorzhdan/cxx-overlay-dangling-ptr
[cxx-interop] Fix a potential dangling pointer in `String(cxxString:)`
2 parents 11f24ca + 737507e commit 59bb4cb

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

stdlib/public/Cxx/String.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ extension std.string {
2222
extension String {
2323
public init(cxxString: std.string) {
2424
self.init(cString: cxxString.c_str())
25+
withExtendedLifetime(cxxString) {}
2526
}
2627
}

0 commit comments

Comments
 (0)