Skip to content

Commit f6d5e50

Browse files
author
Gabor Horvath
committed
[cxx-interop] Do not define inherited copy/move operations
When inheriting constructors, we define the inherited ctors in the derived class. We should not do that for copy and move operations as these operations can never be invoked (the implicit/defined/deleted ctor in the derived class always takes precedence). This fixes an issue where the lifetime parameters are not getting inferred for these spurious constructor definitions. This should also save us from doing some redundant work in the importer. Fixes #82183. rdar://153081347
1 parent a868d92 commit f6d5e50

File tree

3 files changed

+42
-5
lines changed

3 files changed

+42
-5
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2985,7 +2985,9 @@ namespace {
29852985
usingShadowDecl)) {
29862986
auto baseCtorDecl = dyn_cast<clang::CXXConstructorDecl>(
29872987
ctorUsingShadowDecl->getTargetDecl());
2988-
if (!baseCtorDecl || baseCtorDecl->isDeleted())
2988+
if (!baseCtorDecl || baseCtorDecl->isDeleted() ||
2989+
baseCtorDecl->isCopyConstructor() ||
2990+
baseCtorDecl->isMoveConstructor())
29892991
continue;
29902992
auto loc = ctorUsingShadowDecl->getLocation();
29912993

test/Interop/Cxx/class/inheritance/using-base-members-module-interface.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,13 @@
4848
// CHECK-NEXT: }
4949

5050
// CHECK: public struct UsingBaseConstructorWithParam {
51-
// CHECK-NEXT: public init(consuming _: consuming IntBox)
52-
// CHECK-NEXT: public init(_: IntBox)
5351
// CHECK-NEXT: public init(_: UInt32)
5452
// CHECK-NEXT: public init(_: Int32)
5553
// CHECK-NEXT: public var value: Int32
5654
// CHECK-NEXT: }
5755

5856
// CHECK: public struct UsingBaseConstructorEmpty {
5957
// CHECK-NEXT: public init()
60-
// CHECK-NEXT: public init(consuming _: consuming Empty)
61-
// CHECK-NEXT: public init(_: Empty)
6258
// CHECK-NEXT: public var value: Int32
6359
// CHECK-NEXT: }
6460

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,43 @@ private:
130130

131131
MoveOnly moveOnlyId(const MoveOnly& p [[clang::lifetimebound]]);
132132

133+
namespace rdar153081347 {
134+
namespace Detail {
135+
template<typename T>
136+
class SWIFT_NONESCAPABLE Span {
137+
public:
138+
constexpr Span() = default;
139+
constexpr Span(T* p [[clang::lifetimebound]], unsigned long s) : m_ptr(p), m_size(s) {}
140+
141+
template<unsigned long size>
142+
constexpr Span(T (&a)[size]) : m_ptr(a), m_size(size) {}
143+
protected:
144+
T* m_ptr { nullptr };
145+
unsigned long m_size { 0 };
146+
};
147+
} // namespace Detail
148+
149+
template <typename T>
150+
class SWIFT_NONESCAPABLE Span : public Detail::Span<T> {
151+
public:
152+
using Detail::Span<T>::Span;
153+
154+
constexpr Span() = default;
155+
156+
constexpr T const* data() const { return this->m_ptr; }
157+
constexpr T* data() { return this->m_ptr; }
158+
159+
constexpr unsigned long size() const { return this->m_size; }
160+
161+
};
162+
163+
template<typename T>
164+
using ReadonlySpan = Span<T const>;
165+
166+
using ReadonlyBytes = ReadonlySpan<unsigned char>;
167+
using Bytes = Span<unsigned char>;
168+
} // namespace rdar153081347
169+
133170
// CHECK: sil [clang makeOwner] {{.*}}: $@convention(c) () -> Owner
134171
// CHECK: sil [clang getView] {{.*}} : $@convention(c) (@in_guaranteed Owner) -> @lifetime(borrow address 0) @owned View
135172
// CHECK: sil [clang getViewFromFirst] {{.*}} : $@convention(c) (@in_guaranteed Owner, @in_guaranteed Owner) -> @lifetime(borrow address 0) @owned View
@@ -177,3 +214,5 @@ public func test2(_ x: AggregateView) {
177214
func canImportMoveOnlyNonEscapable(_ x: borrowing MoveOnly) {
178215
let _ = moveOnlyId(x);
179216
}
217+
218+
func testInheritedCtors(_ s: rdar153081347.Bytes) {}

0 commit comments

Comments
 (0)