mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Strict memory safety] Eliminate spurious warnings with synthesized Codable
When synthesizing code for Codable conformances involving unsafe types, make sure to wrap the resulting expressions in "unsafe" when strict memory safety is enabled. Tweak the warning-emission logic to suppress warnings about spurious "unsafe" expressions when the compiler generated the "unsafe" itself, so we don't spam the developer with warnings they can't fix. Also make the checking for other suppression considerations safe when there are no source locations, eliminating a potential assertion. Fixes rdar://153665692.
This commit is contained in:
26
test/Unsafe/codable_synthesis.swift
Normal file
26
test/Unsafe/codable_synthesis.swift
Normal file
@@ -0,0 +1,26 @@
|
||||
// RUN: %target-typecheck-verify-swift -strict-memory-safety
|
||||
|
||||
@unsafe public struct UnsafeStruct: Codable {
|
||||
public var string: String
|
||||
}
|
||||
|
||||
|
||||
@unsafe public enum UnsafeEnum: Codable {
|
||||
case something(Int)
|
||||
}
|
||||
|
||||
@safe public struct SafeStruct: Codable {
|
||||
public var us: UnsafeStruct
|
||||
}
|
||||
|
||||
@safe public enum SafeEnum: Codable {
|
||||
case something(UnsafeEnum)
|
||||
}
|
||||
|
||||
@unsafe public class C1: Codable {
|
||||
public var string: String = ""
|
||||
}
|
||||
|
||||
@unsafe public class C2: C1 {
|
||||
public var otherString: String = ""
|
||||
}
|
||||
18
test/Unsafe/hashable_synthesis.swift
Normal file
18
test/Unsafe/hashable_synthesis.swift
Normal file
@@ -0,0 +1,18 @@
|
||||
// RUN: %target-typecheck-verify-swift -strict-memory-safety
|
||||
|
||||
@unsafe public struct UnsafeStruct: Hashable {
|
||||
public var string: String
|
||||
}
|
||||
|
||||
|
||||
@unsafe public enum UnsafeEnum: Hashable {
|
||||
case something(Int)
|
||||
}
|
||||
|
||||
@safe public struct SafeStruct: Hashable {
|
||||
public var us: UnsafeStruct
|
||||
}
|
||||
|
||||
@safe public enum SafeEnum: Hashable {
|
||||
case something(UnsafeEnum)
|
||||
}
|
||||
Reference in New Issue
Block a user