mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
With the acceptance of SE-0458, allow the use of unsafe expressions, the @safe and @unsafe attributes, and the `unsafe` effect on the for..in loop in all Swift code. Introduce the `-strict-memory-safety` flag detailed in the proposal to enable strict memory safety checking. This enables a new class of feature, an optional feature (that is *not* upcoming or experimental), and which can be detected via `hasFeature(StrictMemorySafety)`.
20 lines
841 B
Swift
20 lines
841 B
Swift
// RUN: %target-typecheck-verify-swift -strict-memory-safety
|
|
|
|
// Make sure everything compiles without error when unsafe code is allowed.
|
|
// RUN: %target-swift-frontend -typecheck -warnings-as-errors %s
|
|
|
|
func test(
|
|
x: OpaquePointer,
|
|
other: UnsafeMutablePointer<Int>
|
|
) {
|
|
var array = [1, 2, 3]
|
|
// expected-warning@+2{{expression uses unsafe constructs but is not marked with 'unsafe'}}{{3-3=unsafe }}
|
|
// expected-note@+1{{reference to instance method 'withUnsafeBufferPointer' involves unsafe type 'UnsafeBufferPointer<Int>'}}
|
|
array.withUnsafeBufferPointer{ buffer in
|
|
// expected-warning@+1{{expression uses unsafe constructs but is not marked with 'unsafe'}}{{5-5=unsafe }}
|
|
print(buffer) // expected-note{{reference to parameter 'buffer' involves unsafe type 'UnsafeBufferPointer<Int>'}}
|
|
}
|
|
array.append(4)
|
|
_ = array
|
|
}
|