mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Since this is a C++ stdlib type we need make sure that any overloads that use it are preferred over custom types that also conform to `ExpressibleByStringLiteral` when argument is a string literal. This is important for operators like `==` which could be heterogenous and have a custom C++ type that conforms to `ExpressibleByStringLiteral` on either side together with `std.string` i.e. `==(std.string, const CustomString &)`, such overloads should only be selected if argument passed to `CustomString` is non-literal because literals are convered by a stdlib `==(std.string, std.string)` overload.
23 lines
876 B
Swift
23 lines
876 B
Swift
// RUN: %target-swift-emit-silgen -verify -I %S/Inputs -cxx-interoperability-mode=upcoming-swift %s | %FileCheck %s
|
|
|
|
import CxxStdlib
|
|
import StdString
|
|
|
|
extension StringBox: @retroactive ExpressibleByStringLiteral {
|
|
public init(stringLiteral value: String) {
|
|
self.value = std.string(value)
|
|
}
|
|
}
|
|
|
|
// CHECK-LABEL: sil hidden [ossa] @$s4main4testyyF
|
|
// CHECK: // function_ref static std{{.*}}basic_string<CChar, std{{.*}}char_traits<CChar>, std{{.*}}allocator<CChar>>.== infix(_:_:)
|
|
// CHECK: // function_ref static std{{.*}}basic_string<CChar, std{{.*}}char_traits<CChar>, std{{.*}}allocator<CChar>>.== infix(_:_:)
|
|
// CHECK: // function_ref static String.== infix(_:_:)
|
|
// CHECK: } // end sil function '$s4main4testyyF'
|
|
func test() {
|
|
let cxxString: std.string = ""
|
|
let _ = cxxString == "def" // Ok
|
|
let _ = "def" == cxxString // Ok
|
|
let _ = "def" == "hello" // Ok
|
|
}
|