File tree Expand file tree Collapse file tree 5 files changed +46
-2
lines changed Expand file tree Collapse file tree 5 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -7370,6 +7370,10 @@ static bool hasNonCopyableAttr(const clang::RecordDecl *decl) {
7370
7370
return hasSwiftAttribute (decl, " ~Copyable" );
7371
7371
}
7372
7372
7373
+ bool importer::hasNonEscapableAttr (const clang::RecordDecl *decl) {
7374
+ return hasSwiftAttribute (decl, " ~Escapable" );
7375
+ }
7376
+
7373
7377
// / Recursively checks that there are no pointers in any fields or base classes.
7374
7378
// / Does not check C++ records with specific API annotations.
7375
7379
static bool hasPointerInSubobjects (const clang::CXXRecordDecl *decl) {
Original file line number Diff line number Diff line change @@ -2201,6 +2201,12 @@ namespace {
2201
2201
MoveOnlyAttr (/* Implicit=*/ true ));
2202
2202
}
2203
2203
2204
+ if (Impl.SwiftContext .LangOpts .hasFeature (Feature::NonescapableTypes) &&
2205
+ importer::hasNonEscapableAttr (decl)) {
2206
+ result->getAttrs ().add (new (Impl.SwiftContext )
2207
+ NonEscapableAttr (/* Implicit=*/ true ));
2208
+ }
2209
+
2204
2210
// FIXME: Figure out what to do with superclasses in C++. One possible
2205
2211
// solution would be to turn them into members and add conversion
2206
2212
// functions.
Original file line number Diff line number Diff line change @@ -2029,9 +2029,11 @@ inline std::string getPrivateOperatorName(const std::string &OperatorToken) {
2029
2029
2030
2030
bool hasUnsafeAPIAttr (const clang::Decl *decl);
2031
2031
2032
+ bool hasNonEscapableAttr (const clang::RecordDecl *decl);
2033
+
2032
2034
bool isViewType (const clang::CXXRecordDecl *decl);
2033
2035
2034
- }
2035
- }
2036
+ } // end namespace importer
2037
+ } // end namespace swift
2036
2038
2037
2039
#endif
Original file line number Diff line number Diff line change 158
158
#define SWIFT_NONCOPYABLE \
159
159
__attribute__ ((swift_attr(" ~Copyable" )))
160
160
161
+ // / Specifies that a specific c++ type such class or struct should be imported
162
+ // / as a non-escapable Swift value type when the non-escapable language feature
163
+ // / is enabled.
164
+ #define SWIFT_NONESCAPABLE \
165
+ __attribute__ ((swift_attr(" ~Escapable" )))
166
+
161
167
#else // #if _CXX_INTEROP_HAS_ATTRIBUTE(swift_attr)
162
168
163
169
// Empty defines for compilers that don't support `attribute(swift_attr)`.
172
178
#define SWIFT_MUTATING
173
179
#define SWIFT_UNCHECKED_SENDABLE
174
180
#define SWIFT_NONCOPYABLE
181
+ #define SWIFT_NONESCAPABLE
175
182
176
183
#endif // #if _CXX_INTEROP_HAS_ATTRIBUTE(swift_attr)
177
184
Original file line number Diff line number Diff line change
1
+ // RUN: rm -rf %t
2
+ // RUN: split-file %s %t
3
+ // RUN: not %target-swift-frontend -typecheck -I %swift_src_root/lib/ClangImporter/SwiftBridging -I %t/Inputs %t/test.swift -enable-experimental-feature NonescapableTypes -cxx-interoperability-mode=default -diagnostic-style llvm 2>&1 | %FileCheck %s
4
+
5
+ //--- Inputs/module.modulemap
6
+ module Test {
7
+ header " nonescapable.h "
8
+ requires cplusplus
9
+ }
10
+
11
+ //--- Inputs/nonescapable.h
12
+ #include " swift/bridging "
13
+
14
+ struct SWIFT_NONESCAPABLE A {
15
+ int a;
16
+ } ;
17
+
18
+ //--- test.swift
19
+
20
+ import Test
21
+
22
+ // CHECK: error: cannot infer lifetime dependence, no parameters found that are either ~Escapable or Escapable with a borrowing ownership
23
+ public func test( ) -> A {
24
+ A ( )
25
+ }
You can’t perform that action at this time.
0 commit comments