Skip to content

Commit e3b3e82

Browse files
authored
Merge pull request #64460 from zoecarver/factor-owned-attr-into-is-safe-req
[cxx-interop] Object model: fix crash when importing explicitly owned…
2 parents 81637d9 + 0795083 commit e3b3e82

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6589,6 +6589,7 @@ bool IsSafeUseOfCxxDecl::evaluate(Evaluator &evaluator,
65896589

65906590
if (!cxxRecordReturnType->hasUserDeclaredCopyConstructor() &&
65916591
!cxxRecordReturnType->hasUserDeclaredMoveConstructor() &&
6592+
!hasOwnedValueAttr(cxxRecordReturnType) &&
65926593
hasPointerInSubobjects(cxxRecordReturnType)) {
65936594
return false;
65946595
}

test/Interop/Cxx/class/invalid-unsafe-projection-errors.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ module Test {
1010

1111
//--- Inputs/test.h
1212
struct Ptr { int *p; };
13+
struct __attribute__((swift_attr("import_owned"))) StirngLiteral { const char *name; };
1314

1415
struct M {
1516
int *_Nonnull test1() const;
1617
int &test2() const;
1718
Ptr test3() const;
1819

1920
int *begin() const;
21+
22+
StirngLiteral stringLiteral() const { return StirngLiteral{"M"}; }
2023
};
2124

2225
//--- test.swift
@@ -40,4 +43,7 @@ public func test(x: M) {
4043
// CHECK: note: C++ method 'begin' that returns an iterator is unavailable
4144
// CHECK: note: C++ methods that return iterators are potentially unsafe. Try re-writing to use Swift iterator APIs.
4245
x.begin()
46+
47+
// CHECK-NOT: error: value of type 'M' has no member 'stringLiteral'
48+
x.stringLiteral()
4349
}

0 commit comments

Comments
 (0)