mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
When importing a C++ class template instantiation, Swift translates the template parameter type names from C++ into their Swift equivalent. For instance, `basic_string<wchar_t, char_traits<wchar_t>, allocator<wchar_t>>` gets imported as `basic_string<Scalar, char_traits<Scalar>, allocator<Scalar>>`: `wchar_t` is imported as `CWideChar`, which is a typealias for `Scalar` on most platforms including Darwin. Notice that Swift goes through the `CWideChar` typealias on the specific platform. Another instantiation `basic_string<uint32_t, char_traits<uint32_t>, allocator<uint32_t>>` also gets imported as `basic_string<Scalar, char_traits<Scalar>, allocator<Scalar>>`: `uint32_t` is also imported as `Scalar`. This is problematic because we have two distinct C++ types that have the same name in Swift. This change makes sure Swift doesn't go through typealiases when emitting names of template parameters, so `wchar_t` would now get printed as `CWideChar`, `int` would get printed as `CInt`, etc. This also encourages clients to use the correct type (`CInt`, `CWideChar`, etc) instead of relying on platform-specific typealiases. rdar://115673622
29 lines
1.6 KiB
Swift
29 lines
1.6 KiB
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: %target-swift-ide-test -print-module -module-to-print=CxxStdlib -source-filename=x -enable-experimental-cxx-interop -module-cache-path %t > %t/interface.swift
|
|
// RUN: %FileCheck %s -check-prefix=CHECK-STD < %t/interface.swift
|
|
// RUN: %FileCheck %s -check-prefix=CHECK-SIZE-T < %t/interface.swift
|
|
// RUN: %FileCheck %s -check-prefix=CHECK-TO-STRING < %t/interface.swift
|
|
// RUN: %FileCheck %s -check-prefix=CHECK-STRING < %t/interface.swift
|
|
|
|
// Running this test with different versions of libstdc++ will result in the decls being printed in different order.
|
|
|
|
// This test is specific to libstdc++ and only runs on platforms where libstdc++ is used.
|
|
// REQUIRES: OS=linux-gnu
|
|
|
|
// CHECK-STD: enum std {
|
|
// CHECK-STRING: struct basic_string<CChar, char_traits<CChar>, allocator<CChar>> : CxxRandomAccessCollection {
|
|
// CHECK-STRING: typealias value_type = std.char_traits<CChar>.char_type
|
|
// CHECK-STRING: }
|
|
// CHECK-STRING: struct basic_string<CWideChar, char_traits<CWideChar>, allocator<CWideChar>> : CxxRandomAccessCollection {
|
|
// CHECK-STRING: typealias value_type = std.char_traits<CWideChar>.char_type
|
|
// CHECK-STRING: }
|
|
|
|
// CHECK-TO-STRING: static func to_string(_ __val: Int32) -> std{{(.__cxx11)?}}.string
|
|
// CHECK-TO-STRING: static func to_wstring(_ __val: Int32) -> std{{(.__cxx11)?}}.wstring
|
|
|
|
// CHECK-SIZE-T: typealias size_t = Int
|
|
|
|
// CHECK-STRING: typealias string = std{{(.__cxx11)?}}.basic_string<CChar, char_traits<CChar>, allocator<CChar>>
|
|
// CHECK-STRING: typealias wstring = std{{(.__cxx11)?}}.basic_string<CWideChar, char_traits<CWideChar>, allocator<CWideChar>>
|
|
// CHECK-STD: }
|