Skip to content

Commit 8c84ee2

Browse files
authored
Merge pull request #80986 from swiftlang/gaborh/namespace-scope-lifetime-annotations
[cxx-interop] Properly import annotations from functions in namespace scope
2 parents 685572e + 4dd3540 commit 8c84ee2

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4198,7 +4198,8 @@ namespace {
41984198
return;
41994199

42004200
// FIXME: support C functions imported as members.
4201-
if (result->getImportAsMemberStatus().isImportAsMember() &&
4201+
if (!isClangNamespace(result->getDeclContext()) &&
4202+
result->getImportAsMemberStatus().isImportAsMember() &&
42024203
!isa<clang::CXXMethodDecl, clang::ObjCMethodDecl>(decl))
42034204
return;
42044205

test/Interop/Cxx/class/nonescapable-lifetimebound.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,12 @@ struct SWIFT_NONESCAPABLE AggregateView {
109109
const int *member;
110110
};
111111

112+
namespace NS {
113+
View getView(const Owner& owner [[clang::lifetimebound]]) {
114+
return View(&owner.data);
115+
}
116+
}
117+
112118
// CHECK: sil [clang makeOwner] {{.*}}: $@convention(c) () -> Owner
113119
// CHECK: sil [clang getView] {{.*}} : $@convention(c) (@in_guaranteed Owner) -> @lifetime(borrow 0) @owned View
114120
// CHECK: sil [clang getViewFromFirst] {{.*}} : $@convention(c) (@in_guaranteed Owner, @in_guaranteed Owner) -> @lifetime(borrow 0) @owned View
@@ -123,6 +129,7 @@ struct SWIFT_NONESCAPABLE AggregateView {
123129
// CHECK: sil [clang getCaptureView] {{.*}} : $@convention(c) (@in_guaranteed Owner) -> @lifetime(borrow 0) @owned CaptureView
124130
// CHECK: sil [clang CaptureView.captureView] {{.*}} : $@convention(cxx_method) (View, @lifetime(copy 0) @inout CaptureView) -> ()
125131
// CHECK: sil [clang CaptureView.handOut] {{.*}} : $@convention(cxx_method) (@lifetime(copy 1) @inout View, @in_guaranteed CaptureView) -> ()
132+
// CHECK: sil [clang NS.getView] {{.*}} : $@convention(c) (@in_guaranteed Owner) -> @lifetime(borrow 0) @owned View
126133

127134
//--- test.swift
128135

@@ -144,6 +151,7 @@ public func test() {
144151
var cv = getCaptureView(o)
145152
cv.captureView(v1)
146153
cv.handOut(&v1)
154+
var _ = NS.getView(o)
147155
}
148156

149157
public func test2(_ x: AggregateView) {

0 commit comments

Comments
 (0)