Skip to content

Commit 0e672dc

Browse files
committed
Translate out-of-line copy constructors
1 parent f467a98 commit 0e672dc

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,8 +1134,7 @@ bool Converter::VisitCXXConstructorDecl(clang::CXXConstructorDecl *decl) {
11341134
}
11351135
PushCurrFunction push_fn(*this, decl);
11361136

1137-
if (decl->isCopyOrMoveConstructor() &&
1138-
!decl->doesThisDeclarationHaveABody()) {
1137+
if (decl->isCopyOrMoveConstructor() && !decl->hasBody()) {
11391138
return false;
11401139
}
11411140

‎tests/unit/copy_ctor.cpp‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ struct Owner {
3939
Box<int> box;
4040
};
4141

42+
struct OutOfLine {
43+
int v;
44+
OutOfLine(int v) : v(v) {}
45+
OutOfLine(const OutOfLine &o);
46+
};
47+
48+
OutOfLine::OutOfLine(const OutOfLine &o) : v(o.v + 100) { ++copies; }
49+
4250
static int by_value(Counted c) { return c.v; }
4351

4452
static Counted make(int v) {
@@ -89,6 +97,11 @@ int main() {
8997
Owner o2 = std::move(o);
9098
assert(o2.box.val == 3);
9199

100+
OutOfLine ol1(5);
101+
OutOfLine ol2(ol1);
102+
assert(ol2.v == 105);
103+
assert(copies == 12);
104+
92105
NonConst n;
93106
NonConst n1(n);
94107
const NonConst cn;

0 commit comments

Comments
 (0)