Skip to content

Commit 5c71fa0

Browse files
committed
[cxx-interop] always mark begin and end methods as unsafe (to help automatic rac conformance); update tests accordingly.
1 parent f7a2e18 commit 5c71fa0

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6780,6 +6780,12 @@ bool IsSafeUseOfCxxDecl::evaluate(Evaluator &evaluator,
67806780
if (isForeignReferenceType(method->getReturnType()))
67816781
return true;
67826782

6783+
// begin and end methods likely return an interator, so they're unsafe. This
6784+
// is required so that automatic the conformance to RAC works properly.
6785+
if (method->getNameAsString() == "begin" ||
6786+
method->getNameAsString() == "end")
6787+
return false;
6788+
67836789
auto parentQualType = method
67846790
->getParent()->getTypeForDecl()->getCanonicalTypeUnqualified();
67856791

test/Interop/Cxx/stdlib/overlay/Inputs/custom-sequence.h

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ struct SimpleCopyAwareSequence {
2424
SimpleCopyAwareSequence(const SimpleCopyAwareSequence &other) { copiesCount++; }
2525
};
2626

27-
struct
28-
__attribute__((swift_attr("import_owned")))
29-
SimpleArrayWrapper {
27+
struct SimpleArrayWrapper {
3028
private:
3129
int a[5] = {10, 20, 30, 40, 50};
3230

@@ -35,9 +33,7 @@ SimpleArrayWrapper {
3533
const int *end() const __attribute__((returns_nonnull)) { return &a[5]; }
3634
};
3735

38-
struct
39-
__attribute__((swift_attr("import_owned")))
40-
SimpleArrayWrapperNullableIterators {
36+
struct SimpleArrayWrapperNullableIterators {
4137
private:
4238
int a[5] = {10, 20, 30, 40, 50};
4339

@@ -46,9 +42,7 @@ SimpleArrayWrapperNullableIterators {
4642
const int *end() const { return &a[5]; }
4743
};
4844

49-
struct
50-
__attribute__((swift_attr("import_owned")))
51-
SimpleEmptySequence {
45+
struct SimpleEmptySequence {
5246
const int *begin() const { return nullptr; }
5347
const int *end() const { return nullptr; }
5448
};

0 commit comments

Comments
 (0)