-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathunsafe_imports.swift
39 lines (28 loc) · 1.58 KB
/
unsafe_imports.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// RUN: %empty-directory(%t)
// RUN: %target-swift-frontend -emit-module-path %t/unsafe_swift_decls.swiftmodule %S/Inputs/unsafe_swift_decls.swift
// RUN: %target-typecheck-verify-swift -strict-memory-safety -I %S/Inputs -I %t
import unsafe_decls
import unsafe_swift_decls
func testUnsafe(_ ut: UnsafeType) {
// expected-warning@+1{{expression uses unsafe constructs but is not marked with 'unsafe'}}{{3-3=unsafe }}
unsafe_c_function() // expected-note{{reference to unsafe global function 'unsafe_c_function()'}}
var array: [CInt] = [1, 2, 3, 4, 5]
// expected-warning@+1{{expression uses unsafe constructs but is not marked with 'unsafe'}}{{3-3=unsafe }}
print_ints(&array, CInt(array.count))
// expected-note@-1{{reference to global function 'print_ints' involves unsafe type 'UnsafeMutablePointer<Int32>'}}
}
// Reference a typealias that isn't itself @unsafe, but refers to an unsafe
// type.
func testUnsafeThroughAlias(_ ut: UnsafeTypeAlias) {
}
func callThroughAlias(ut: UnsafeTypeAlias) {
// expected-warning@+1{{expression uses unsafe constructs but is not marked with 'unsafe'}}
testUnsafeThroughAlias(ut) // expected-note{{reference to global function 'testUnsafeThroughAlias' involves unsafe type 'UnsafeTypeAlias' (aka 'PointerType')}}
// expected-note@-1{{reference to parameter 'ut' involves unsafe type 'UnsafeTypeAlias' (aka 'PointerType')}}
}
struct ConformsToUnsafeRequirement: HasUnsafeRequirement {
@unsafe func f(_: PointerType) { }
}
class SubclassWithUnsafeMethod: SuperclassWithUnsafeMethod {
@unsafe override func implicitlyUnsafe(_: PointerType) { }
}