mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Merge pull request #84223 from egorzhdan/egorzhdan/crash-any-cast
[cxx-interop] Fix a crash when calling `std::any_cast` from Swift
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
module StdAny {
|
||||
header "std-any.h"
|
||||
requires cplusplus
|
||||
export *
|
||||
}
|
||||
|
||||
module StdNumeric {
|
||||
header "std-numeric.h"
|
||||
requires cplusplus
|
||||
|
||||
6
test/Interop/Cxx/stdlib/Inputs/std-any.h
Normal file
6
test/Interop/Cxx/stdlib/Inputs/std-any.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#include <any>
|
||||
#include <string>
|
||||
|
||||
inline std::any getStdAnyString() {
|
||||
return std::string("abc210");
|
||||
}
|
||||
23
test/Interop/Cxx/stdlib/use-std-any.swift
Normal file
23
test/Interop/Cxx/stdlib/use-std-any.swift
Normal file
@@ -0,0 +1,23 @@
|
||||
// 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()
|
||||
Reference in New Issue
Block a user