mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Strict memory safety] Union member accessors are always unsafe
Union member accessors have no way to know what the "active field" is, so consider them to always be unsafe.
This commit is contained in:
@@ -2392,6 +2392,9 @@ namespace {
|
||||
// field type.
|
||||
synthesizer.makeUnionFieldAccessors(result, member);
|
||||
|
||||
// Union accessors are always unsafe.
|
||||
member->getAttrs().add(new (Impl.SwiftContext) UnsafeAttr(/*Implicit=*/true));
|
||||
|
||||
// Create labeled initializers for unions that take one of the
|
||||
// fields, which only initializes the data for that field.
|
||||
auto valueCtor =
|
||||
|
||||
@@ -19,4 +19,9 @@ struct StoreAllTheThings {
|
||||
let ln: ListNode // expected-note{{property 'ln' involves unsafe type 'ListNode'}}
|
||||
|
||||
let sc: SomeColor
|
||||
};
|
||||
}
|
||||
|
||||
func readFromUnion(npu: NoPointersUnion) {
|
||||
// expected-warning@+1{{expression uses unsafe constructs but is not marked with 'unsafe'}}
|
||||
_ = npu.x // expected-note{{reference to unsafe property 'x'}}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user