[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:
Doug Gregor
2025-04-02 16:55:52 -07:00
parent 14147bf87d
commit c522138987
2 changed files with 9 additions and 1 deletions

View File

@@ -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'}}
}