Files
swift-mirror/test/Interop/Cxx/templates/function-template.swift
Egor Zhdan 5b5ffde79e [cxx-interop] Do not crash when passing Bool as const T& parameter
The type bridging logic assumed that if a value of type `Swift.Bool` is passed to a Clang function as an argument, then the type of the parameter must be a Clang built-in type (usually `_Bool`). This is not always correct. For instance, the type might be a templated const reference.

rdar://125508505
2024-05-09 15:28:33 +01:00

46 lines
1.2 KiB
Swift

// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop)
// REQUIRES: executable_test
import FunctionTemplates
import StdlibUnittest
var FunctionTemplateTestSuite = TestSuite("Function Templates")
FunctionTemplateTestSuite.test("passThrough<T> where T == Int") {
let result = passThrough(42)
expectEqual(42, result)
}
FunctionTemplateTestSuite.test("addSameTypeParams<T> where T == Int") {
let result = addSameTypeParams(42, 23)
expectEqual(65, result)
}
FunctionTemplateTestSuite.test("addSameTypeParams<T, U> where T, U == Int") {
let result = addMixedTypeParams(42, 23)
expectEqual(65, result)
}
FunctionTemplateTestSuite.test("lvalueReference<T> where T == Int") {
var value = 0
lvalueReference(&value)
expectEqual(value, 42)
}
FunctionTemplateTestSuite.test("lvalueReferenceZero<T> where T == Bool") {
var value = true
lvalueReferenceZero(&value)
expectEqual(value, false)
}
FunctionTemplateTestSuite.test("constLvalueReferenceToBool<T> where T == Bool") {
expectTrue(constLvalueReferenceToBool(true))
expectFalse(constLvalueReferenceToBool(false))
}
// TODO: Generics, Any, and Protocols should be tested here but need to be
// better supported in ClangTypeConverter first.
runAllTests()