mirror of
https://github.com/apple/swift.git
synced 2026-02-27 18:26:24 +01:00
This patch addresses potential ambiguity and unsafe behavior by deprecating initializer overloads for `std.string` that accept optional arguments (`string?`). These overloads previously allowed implicit initialization from optional pointers (`UnsafePointer<CChar>?`), causing unclear or unintended behavior. - Deprecated: `init(_ string: UnsafePointer<CChar>?)`, guiding users toward the explicit, non-optional initializer. - Unavailable: `init(_ string: String?)`, explicitly preventing misuse from optional Swift strings. rdar://148041893
9 lines
390 B
Swift
9 lines
390 B
Swift
// RUN: %target-typecheck-verify-swift -I %S/Inputs -cxx-interoperability-mode=default
|
|
import CxxStdlib
|
|
|
|
let tmpOpt: String? = "üüüüüüü"
|
|
let cppString1 = std.string(tmpOpt) // expected-warning {{'init(_:)' is deprecated: unwrap the optional value and use init(_ string: UnsafePointer<CChar>) instead}}
|
|
|
|
let tmpNonOpt: String = "üüüüüüü"
|
|
let cppString2 = std.string(tmpNonOpt)
|