Skip to content

Commit 9167694

Browse files
authored
Merge pull request swiftlang#75959 from hyp/eng/cxx-string-fix
[cxx][windows] fix the CxxStdlib build for recent MSVC versions after…
2 parents 083b10a + c8fa166 commit 9167694

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

stdlib/public/Cxx/std/String.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,27 @@ extension std.string {
2121
/// Swift string.
2222
public init(_ string: String) {
2323
self = string.withCString(encodedAs: UTF8.self) { buffer in
24+
#if os(Windows)
25+
// Use the 2 parameter constructor.
26+
// The MSVC standard library has a enable_if template guard
27+
// on the 3 parameter constructor, and thus it's not imported into Swift.
28+
std.string(buffer, string.utf8.count)
29+
#else
2430
std.string(buffer, string.utf8.count, .init())
31+
#endif
2532
}
2633
}
2734

2835
public init(_ string: UnsafePointer<CChar>?) {
2936
if let str = string {
37+
#if os(Windows)
38+
// Use the 2 parameter constructor.
39+
// The MSVC standard library has a enable_if template guard
40+
// on the 3 parameter constructor, and thus it's not imported into Swift.
41+
self.init(str, UTF8._nullCodeUnitOffset(in: str))
42+
#else
3043
self.init(str, UTF8._nullCodeUnitOffset(in: str), .init())
44+
#endif
3145
} else {
3246
self.init()
3347
}

0 commit comments

Comments
 (0)