@@ -22,13 +22,17 @@ extension std.string {
22
22
@_alwaysEmitIntoClient
23
23
public init ( _ string: String ) {
24
24
self = unsafe string. withCString ( encodedAs: UTF8 . self) { buffer in
25
- #if os(Windows)
26
- // Use the 2 parameter constructor.
27
- // The MSVC standard library has a enable_if template guard
28
- // on the 3 parameter constructor, and thus it's not imported into Swift.
29
- unsafe std. string ( buffer, string. utf8. count)
30
- #else
25
+ // MSVC STL has a enable_if template guard on the 3-parameter constructor,
26
+ // and thus it's not imported into Swift.
27
+ // libc++ provides both 2-parameter and 3-parameter constructors.
28
+ // libstdc++ only provides the 3-parameter constructor.
29
+
30
+ // Note that we might be compiling with libc++ on Linux, even if it's not
31
+ // the default stdlib on a particular distro.
32
+ #if os(Linux)
31
33
unsafe std. string ( buffer, string. utf8. count, . init( ) )
34
+ #else
35
+ unsafe std. string ( buffer, string. utf8. count)
32
36
#endif
33
37
}
34
38
}
@@ -42,14 +46,11 @@ extension std.string {
42
46
43
47
@_alwaysEmitIntoClient
44
48
public init ( _ string: UnsafePointer < CChar > ) {
45
- #if os(Windows)
46
- // Use the 2 parameter constructor.
47
- // The MSVC standard library has a enable_if template guard
48
- // on the 3 parameter constructor, and thus it's not imported into Swift.
49
- unsafe self. init ( string, UTF8 . _nullCodeUnitOffset ( in: string) )
50
- #else
49
+ #if os(Linux)
51
50
unsafe self. init ( string, UTF8 . _nullCodeUnitOffset ( in: string) , . init( ) )
52
- #endif
51
+ #else
52
+ unsafe self. init ( string, UTF8 . _nullCodeUnitOffset ( in: string) )
53
+ #endif
53
54
}
54
55
55
56
@_alwaysEmitIntoClient
0 commit comments