Files
swift-mirror/test/Interop/Cxx/stdlib/use-std-any.swift
Egor Zhdan 18c5e23a31 [cxx-interop] Fix a crash when calling std::any_cast from Swift
In libc++, `std::any_cast` is declared as a friend function of `std::any`.

ClangImporter was not correctly handling friend functions declared within structs within namespaces correctly.

rdar://147261941
2025-10-09 13:10:17 +01:00

24 lines
769 B
Swift

// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=upcoming-swift)
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=upcoming-swift -Xcc -std=c++17)
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=upcoming-swift -Xcc -std=c++20)
// REQUIRES: executable_test
// In Microsoft STL, all overloads of std::any_cast return a dependent templated
// type, which Swift isn't able to instantiate.
// UNSUPPORTED: OS=windows-msvc
import StdlibUnittest
import StdAny
import CxxStdlib
var StdAnyTestSuite = TestSuite("StdAny")
StdAnyTestSuite.test("std.any_cast<std.string>") {
let a1 = getStdAnyString()
let c1 = std.any_cast(a1) as std.string
expectEqual(c1, std.string("abc210"))
}
runAllTests()