Files
swift-mirror/test/Unsafe/unsafe_c_imports.swift
Doug Gregor c522138987 [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.
2025-04-02 16:59:17 -07:00

28 lines
1.1 KiB
Swift

// RUN: %target-typecheck-verify-swift -strict-memory-safety -I %S/Inputs
import unsafe_decls
// expected-warning@+3{{struct 'StoreAllTheThings' has storage involving unsafe types}}
// expected-note@+2{{add '@unsafe' if this type is also unsafe to use}}
// expected-note@+1{{add '@safe' if this type encapsulates the unsafe storage in a safe interface}}
struct StoreAllTheThings {
let np: NoPointers
let npu: NoPointersUnion
let npu2: NoPointersUnsafe // expected-note{{property 'npu2' involves unsafe type 'NoPointersUnsafe'}}
let hp: HasPointers // expected-note{{property 'hp' involves unsafe type 'HasPointers'}}
let hpu: HasPointersUnion // expected-note{{property 'hpu' involves unsafe type 'HasPointersUnion'}}
let nps: HasPointersSafe
let hrc: HasRefCounted
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'}}
}