mirror of
https://github.com/apple/swift.git
synced 2026-03-04 18:24:35 +01:00
We were previously marking synthesized FRT initializers as "returns_retained" unconditionally (for non-immortal types), which can cause memory errors and also suppresses diagnostics about the lack of such annotations. This patch fixes that behavior, and also adjusts the source locations of the synthesized C++ factory method to point to the actual constructor decl when its location is available, so that the diagnostics make sense when warning about the lack of annotations. rdar://163127315
78 lines
1.8 KiB
Swift
78 lines
1.8 KiB
Swift
// RUN: %target-run-simple-swift(-I %S/Inputs -cxx-interoperability-mode=default -Xfrontend -disable-availability-checking)
|
|
// REQUIRES: executable_test
|
|
|
|
import FRTConstructors
|
|
import StdlibUnittest
|
|
|
|
func clone<T: Copyable>(_ t: T) -> (T, T) { return (t, t) }
|
|
|
|
var FRTConstructorsTests = TestSuite("Calling synthesized foreign reference type initializers")
|
|
|
|
FRTConstructorsTests.test("explicit defaulted default constructor at +1") {
|
|
let x = FRTExplicitDefaultCtor1()
|
|
let (y, z) = clone(x)
|
|
x.check()
|
|
y.check()
|
|
z.check()
|
|
}
|
|
|
|
FRTConstructorsTests.test("explicit defaulted default constructor at +0") {
|
|
let x = FRTExplicitDefaultCtor0()
|
|
let (y, z) = clone(x)
|
|
x.check()
|
|
y.check()
|
|
z.check()
|
|
}
|
|
|
|
FRTConstructorsTests.test("user-defined default constructor at +1") {
|
|
let x = FRTUserDefaultCtor1()
|
|
let (y, z) = clone(x)
|
|
x.check()
|
|
y.check()
|
|
z.check()
|
|
}
|
|
|
|
FRTConstructorsTests.test("user-defined default constructor at +0") {
|
|
let x = FRTUserDefaultCtor0()
|
|
let (y, z) = clone(x)
|
|
x.check()
|
|
y.check()
|
|
z.check()
|
|
}
|
|
|
|
FRTConstructorsTests.test("constructors with mixed ownership conventions") {
|
|
let a0 = FRTMixedConventionCtors()
|
|
let (a1, a2) = clone(a0)
|
|
a0.check()
|
|
a1.check()
|
|
a2.check()
|
|
|
|
let b0 = FRTMixedConventionCtors(0)
|
|
let (b1, b2) = clone(b0)
|
|
b0.check()
|
|
b1.check()
|
|
b2.check()
|
|
}
|
|
|
|
FRTConstructorsTests.test("constructors with mixed ownership conventions, unretained by default") {
|
|
let a0 = FRTMixedConventionCtorsUnretainedByDefault()
|
|
let (a1, a2) = clone(a0)
|
|
a0.check()
|
|
a1.check()
|
|
a2.check()
|
|
|
|
let b0 = FRTMixedConventionCtorsUnretainedByDefault(0)
|
|
let (b1, b2) = clone(b0)
|
|
b0.check()
|
|
b1.check()
|
|
b2.check()
|
|
|
|
let c0 = FRTMixedConventionCtorsUnretainedByDefault(0, 0)
|
|
let (c1, c2) = clone(c0)
|
|
c0.check()
|
|
c1.check()
|
|
c2.check()
|
|
}
|
|
|
|
runAllTests()
|