Skip to content

Commit cda402c

Browse files
Xazax-hunGabor Horvath
authored andcommitted
[6.2][cxx-interop] Do not define inherited copy/move operations
Explanationi: 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. Issues: rdar://153081347 Original PRs: swiftlang#83694 Risk: Low, we do not import some ctors that can never be called. Testing: Added a compiler test. Reviewers: @egorzhdan
1 parent f15d600 commit cda402c

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
@@ -2991,7 +2991,9 @@ namespace {
29912991
usingShadowDecl)) {
29922992
auto baseCtorDecl = dyn_cast<clang::CXXConstructorDecl>(
29932993
ctorUsingShadowDecl->getTargetDecl());
2994-
if (!baseCtorDecl || baseCtorDecl->isDeleted())
2994+
if (!baseCtorDecl || baseCtorDecl->isDeleted() ||
2995+
baseCtorDecl->isCopyConstructor() ||
2996+
baseCtorDecl->isMoveConstructor())
29952997
continue;
29962998
auto loc = ctorUsingShadowDecl->getLocation();
29972999

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
@@ -115,6 +115,43 @@ namespace NS {
115115
}
116116
}
117117

118+
namespace rdar153081347 {
119+
namespace Detail {
120+
template<typename T>
121+
class SWIFT_NONESCAPABLE Span {
122+
public:
123+
constexpr Span() = default;
124+
constexpr Span(T* p [[clang::lifetimebound]], unsigned long s) : m_ptr(p), m_size(s) {}
125+
126+
template<unsigned long size>
127+
constexpr Span(T (&a)[size]) : m_ptr(a), m_size(size) {}
128+
protected:
129+
T* m_ptr { nullptr };
130+
unsigned long m_size { 0 };
131+
};
132+
} // namespace Detail
133+
134+
template <typename T>
135+
class SWIFT_NONESCAPABLE Span : public Detail::Span<T> {
136+
public:
137+
using Detail::Span<T>::Span;
138+
139+
constexpr Span() = default;
140+
141+
constexpr T const* data() const { return this->m_ptr; }
142+
constexpr T* data() { return this->m_ptr; }
143+
144+
constexpr unsigned long size() const { return this->m_size; }
145+
146+
};
147+
148+
template<typename T>
149+
using ReadonlySpan = Span<T const>;
150+
151+
using ReadonlyBytes = ReadonlySpan<unsigned char>;
152+
using Bytes = Span<unsigned char>;
153+
} // namespace rdar153081347
154+
118155
// CHECK: sil [clang makeOwner] {{.*}}: $@convention(c) () -> Owner
119156
// CHECK: sil [clang getView] {{.*}} : $@convention(c) (@in_guaranteed Owner) -> @lifetime(borrow address_for_deps 0) @owned View
120157
// CHECK: sil [clang getViewFromFirst] {{.*}} : $@convention(c) (@in_guaranteed Owner, @in_guaranteed Owner) -> @lifetime(borrow address_for_deps 0) @owned View
@@ -157,3 +194,5 @@ public func test() {
157194
public func test2(_ x: AggregateView) {
158195
let _ = AggregateView(member: x.member)
159196
}
197+
198+
func testInheritedCtors(_ s: rdar153081347.Bytes) {}

0 commit comments

Comments
 (0)