You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: test/Interop/Cxx/class/nonescapable-errors.swift
+46-20Lines changed: 46 additions & 20 deletions
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,14 @@ struct SWIFT_ESCAPABLE Owner {
27
27
int data;
28
28
};
29
29
30
+
template<typename T>
31
+
struct SWIFT_ESCAPABLE TemplatedOwner {
32
+
T data;
33
+
};
34
+
35
+
using TemplatedIntOwner =TemplatedOwner<int>;
36
+
using TemplatedFloatOwner = TemplatedOwner<float>;
37
+
30
38
Owner f(int* x [[clang::lifetimebound]]){
31
39
returnOwner{0};
32
40
}
@@ -35,6 +43,14 @@ Owner f2(int* x [[clang::lifetimebound]], int* y [[clang::lifetimebound]]) {
35
43
returnOwner{0};
36
44
}
37
45
46
+
TemplatedIntOwner f3(int* x [[clang::lifetimebound]]){
47
+
return TemplatedOwner<int>{0};
48
+
}
49
+
50
+
TemplatedFloatOwner f4(int* x [[clang::lifetimebound]]){
51
+
return TemplatedOwner<float>{0};
52
+
}
53
+
38
54
View g(int* x){
39
55
returnView(x);
40
56
}
@@ -111,42 +127,52 @@ public func importInvalid(_ x: Invalid) {
111
127
// CHECK: error: a function with a ~Escapable result needs a parameter to depend on
112
128
// CHECK-NO-LIFETIMES: test.swift:11:32: error: a function cannot return a ~Escapable result
113
129
publicfunc noAnnotations()->View{
114
-
// CHECK: nonescapable.h:16:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
115
-
// CHECK-NO-LIFETIMES: nonescapable.h:16:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
130
+
// CHECK: nonescapable.h:24:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
131
+
// CHECK-NO-LIFETIMES: nonescapable.h:24:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
116
132
f(nil)
117
-
// CHECK: nonescapable.h:20:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
118
-
// CHECK-NO-LIFETIMES: nonescapable.h:20:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
133
+
// CHECK: nonescapable.h:28:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
134
+
// CHECK-NO-LIFETIMES: nonescapable.h:28:7: warning: the returned type 'Owner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
119
135
// No duplicate warning for f2:
120
-
// CHECK-NOT: nonescapable.h:20
136
+
// CHECK-NOT: nonescapable.h:28
121
137
f2(nil,nil)
122
-
// CHECK: nonescapable.h:24:6: warning: the returned type 'View' is annotated as non-escapable; its lifetime dependencies must be annotated [#ClangDeclarationImport]
123
-
// CHECK-NO-LIFETIMES: nonescapable.h:24:6: warning: the returned type 'View' is annotated as non-escapable; its lifetime dependencies must be annotated [#ClangDeclarationImport]
124
-
// CHECK-NO-LIFETIMES: nonescapable.h:24:6: error: a function cannot return a ~Escapable result
138
+
// CHECK: nonescapable.h:32:19: warning: the returned type 'TemplatedIntOwner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
139
+
// CHECK-NO-LIFETIMES: nonescapable.h:32:19: warning: the returned type 'TemplatedIntOwner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
140
+
// No duplicate warning for f3:
141
+
// CHECK-NOT: nonescapable.h:32
142
+
f3(nil)
143
+
// CHECK: nonescapable.h:36:21: warning: the returned type 'TemplatedFloatOwner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
144
+
// CHECK-NO-LIFETIMES: nonescapable.h:36:21: warning: the returned type 'TemplatedFloatOwner' is annotated as escapable; it cannot have lifetime dependencies [#ClangDeclarationImport]
145
+
// No duplicate warning for f4:
146
+
// CHECK-NOT: nonescapable.h:34
147
+
f4(nil)
148
+
// CHECK: nonescapable.h:40:6: warning: the returned type 'View' is annotated as non-escapable; its lifetime dependencies must be annotated [#ClangDeclarationImport]
149
+
// CHECK-NO-LIFETIMES: nonescapable.h:40:6: warning: the returned type 'View' is annotated as non-escapable; its lifetime dependencies must be annotated [#ClangDeclarationImport]
150
+
// CHECK-NO-LIFETIMES: nonescapable.h:40:6: error: a function cannot return a ~Escapable result
125
151
g(nil)
126
152
h1(nil)
127
-
// CHECK-NO-LIFETIMES: nonescapable.h:34:21: error: a function cannot return a ~Escapable result
153
+
// CHECK-NO-LIFETIMES: nonescapable.h:50:21: error: a function cannot return a ~Escapable result
128
154
h2(nil)
129
-
// CHECK-NO-LIFETIMES: nonescapable.h:35:21: error: a function cannot return a ~Escapable result
155
+
// CHECK-NO-LIFETIMES: nonescapable.h:51:21: error: a function cannot return a ~Escapable result
130
156
h3(nil)
131
157
i1()
132
-
// CHECK: nonescapable.h:39:39: error: template parameter 'Missing' does not exist
133
-
// CHECK-NO-LIFETIMES: nonescapable.h:39:39: error: template parameter 'Missing' does not exist
158
+
// CHECK: nonescapable.h:55:39: error: template parameter 'Missing' does not exist
159
+
// CHECK-NO-LIFETIMES: nonescapable.h:55:39: error: template parameter 'Missing' does not exist
134
160
i2()
135
-
// CHECK: nonescapable.h:45:33: error: template parameter 'S' expected to be a type parameter
136
-
// CHECK-NO-LIFETIMES: nonescapable.h:45:33: error: template parameter 'S' expected to be a type parameter
161
+
// CHECK: nonescapable.h:61:33: error: template parameter 'S' expected to be a type parameter
162
+
// CHECK-NO-LIFETIMES: nonescapable.h:61:33: error: template parameter 'S' expected to be a type parameter
137
163
j1()
138
-
// CHECK-NO-LIFETIMES: nonescapable.h:63:41: error: a function cannot return a ~Escapable result
164
+
// CHECK-NO-LIFETIMES: nonescapable.h:79:41: error: a function cannot return a ~Escapable result
139
165
j2()
140
-
// CHECK-NO-LIFETIMES: nonescapable.h:64:41: error: a function cannot return a ~Escapable result
166
+
// CHECK-NO-LIFETIMES: nonescapable.h:80:41: error: a function cannot return a ~Escapable result
141
167
j3()
142
168
k1();
143
-
// CHECK-NO-LIFETIMES: nonescapable.h:70:15: error: a function cannot return a ~Escapable result
169
+
// CHECK-NO-LIFETIMES: nonescapable.h:86:15: error: a function cannot return a ~Escapable result
144
170
k2();
145
-
// CHECK-NO-LIFETIMES: nonescapable.h:71:22: error: a function cannot return a ~Escapable result
171
+
// CHECK-NO-LIFETIMES: nonescapable.h:87:22: error: a function cannot return a ~Escapable result
146
172
k3();
147
173
l1();
148
-
// CHECK: nonescapable.h:77:12: error: a function with a ~Escapable result needs a parameter to depend on
149
-
// CHECK-NO-LIFETIMES: nonescapable.h:77:12: error: a function cannot return a ~Escapable result
174
+
// CHECK: nonescapable.h:93:12: error: a function with a ~Escapable result needs a parameter to depend on
175
+
// CHECK-NO-LIFETIMES: nonescapable.h:93:12: error: a function cannot return a ~Escapable result
0 commit comments