Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cpp2rust/converter/converter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4917,11 +4917,11 @@ void Converter::AddDefaultTrait(const clang::RecordDecl *decl) {
PushBrace impl_brace(*this);
StrCat("fn default() -> Self");
PushBrace fn_brace(*this);
StrCat(keyword_unsafe_);
PushBrace unsafe_brace(*this);

if (auto *cxx = clang::dyn_cast<clang::CXXRecordDecl>(decl)) {
if (auto *default_ctor = GetUserDefinedDefaultConstructor(cxx)) {
StrCat(keyword_unsafe_);
PushBrace unsafe_brace(*this);
Convert(MakeConstructExpr(ctx_, ctx_.getCanonicalTagType(decl),
default_ctor, {}));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ impl S {
}
impl Default for S {
fn default() -> Self {
S {
v: Rc::new(RefCell::new(Default::default())),
n: Rc::new(RefCell::new((0..2).map(|_| 0_i32).collect::<Box<[i32]>>())),
{
S {
v: Rc::new(RefCell::new(Default::default())),
n: Rc::new(RefCell::new((0..2).map(|_| 0_i32).collect::<Box<[i32]>>())),
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct S_int_ {
}
impl Default for S_int_ {
fn default() -> Self {
S_int_ { x: 0 }
{ S_int_ { x: 0 } }
}
}
pub fn main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl S_int_ {
}
impl Default for S_int_ {
fn default() -> Self {
S_int_ { x: 0 }
unsafe { S_int_ { x: 0 } }
}
}
pub fn main() {
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/out/refcount/10_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ impl Partial {
}
impl Default for Partial {
fn default() -> Self {
Partial {
p: Ptr::<i32>::null(),
{
Partial {
p: Ptr::<i32>::null(),
}
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions tests/unit/out/refcount/array_const_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ pub struct S {
}
impl Default for S {
fn default() -> Self {
S {
head: 0_i32,
tail: Rc::new(RefCell::new((0..3).map(|_| 0_i32).collect::<Box<[i32]>>())),
buf: Rc::new(RefCell::new((0..4).map(|_| 0_i8).collect::<Box<[i8]>>())),
{
S {
head: 0_i32,
tail: Rc::new(RefCell::new((0..3).map(|_| 0_i32).collect::<Box<[i32]>>())),
buf: Rc::new(RefCell::new((0..4).map(|_| 0_i8).collect::<Box<[i8]>>())),
}
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions tests/unit/out/refcount/array_field_addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ pub struct S {
}
impl Default for S {
fn default() -> Self {
S {
before: 0_i32,
mask: Rc::new(RefCell::new((0..4).map(|_| 0_u8).collect::<Box<[u8]>>())),
after: 0_i32,
{
S {
before: 0_i32,
mask: Rc::new(RefCell::new((0..4).map(|_| 0_u8).collect::<Box<[u8]>>())),
after: 0_i32,
}
}
}
}
Expand Down
8 changes: 5 additions & 3 deletions tests/unit/out/refcount/array_of_noncopy_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ pub struct NonCopy {
}
impl Default for NonCopy {
fn default() -> Self {
NonCopy {
data: Rc::new(RefCell::new(Default::default())),
tag: 0,
{
NonCopy {
data: Rc::new(RefCell::new(Default::default())),
tag: 0,
}
}
}
}
Expand Down
14 changes: 8 additions & 6 deletions tests/unit/out/refcount/clone_vs_move.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ pub struct Foo {
}
impl Default for Foo {
fn default() -> Self {
Foo {
x: 0_i32,
y: <Ptr<i32>>::default(),
z: Ptr::<i32>::null(),
a: Rc::new(RefCell::new((0..3).map(|_| 0_i32).collect::<Box<[i32]>>())),
bar: <Bar>::default(),
{
Foo {
x: 0_i32,
y: <Ptr<i32>>::default(),
z: Ptr::<i32>::null(),
a: Rc::new(RefCell::new((0..3).map(|_| 0_i32).collect::<Box<[i32]>>())),
bar: <Bar>::default(),
}
}
}
}
Expand Down
16 changes: 9 additions & 7 deletions tests/unit/out/refcount/copy_assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ pub struct Holder {
}
impl Default for Holder {
fn default() -> Self {
Holder {
p: <Partial>::default(),
arr: Rc::new(RefCell::new(
(0..2)
.map(|_| <Partial>::default())
.collect::<Box<[Partial]>>(),
)),
{
Holder {
p: <Partial>::default(),
arr: Rc::new(RefCell::new(
(0..2)
.map(|_| <Partial>::default())
.collect::<Box<[Partial]>>(),
)),
}
}
}
}
Expand Down
16 changes: 9 additions & 7 deletions tests/unit/out/refcount/copy_ctor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,15 @@ pub struct Holder {
}
impl Default for Holder {
fn default() -> Self {
Holder {
c: <Counted>::default(),
arr: Rc::new(RefCell::new(
(0..2)
.map(|_| <Counted>::default())
.collect::<Box<[Counted]>>(),
)),
{
Holder {
c: <Counted>::default(),
arr: Rc::new(RefCell::new(
(0..2)
.map(|_| <Counted>::default())
.collect::<Box<[Counted]>>(),
)),
}
}
}
}
Expand Down
44 changes: 26 additions & 18 deletions tests/unit/out/refcount/copy_move_defaulted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ impl Explicit {
}
impl Default for Explicit {
fn default() -> Self {
Explicit {
v: 0_i32,
inner: <Inner>::default(),
arr: Rc::new(RefCell::new((0..2).map(|_| 0_i32).collect::<Box<[i32]>>())),
{
Explicit {
v: 0_i32,
inner: <Inner>::default(),
arr: Rc::new(RefCell::new((0..2).map(|_| 0_i32).collect::<Box<[i32]>>())),
}
}
}
}
Expand All @@ -56,10 +58,12 @@ pub struct Implicit {
}
impl Default for Implicit {
fn default() -> Self {
Implicit {
v: 0_i32,
inner: <Inner>::default(),
arr: Rc::new(RefCell::new((0..2).map(|_| 0_i32).collect::<Box<[i32]>>())),
{
Implicit {
v: 0_i32,
inner: <Inner>::default(),
arr: Rc::new(RefCell::new((0..2).map(|_| 0_i32).collect::<Box<[i32]>>())),
}
}
}
}
Expand Down Expand Up @@ -159,11 +163,13 @@ impl Buffer {
}
impl Default for Buffer {
fn default() -> Self {
Buffer {
data: Rc::new(RefCell::new(Default::default())),
rows: Rc::new(RefCell::new(Vec::new())),
n: 0_i32,
arr: Rc::new(RefCell::new((0..2).map(|_| 0_i32).collect::<Box<[i32]>>())),
{
Buffer {
data: Rc::new(RefCell::new(Default::default())),
rows: Rc::new(RefCell::new(Vec::new())),
n: 0_i32,
arr: Rc::new(RefCell::new((0..2).map(|_| 0_i32).collect::<Box<[i32]>>())),
}
}
}
}
Expand Down Expand Up @@ -198,11 +204,13 @@ impl Owner {
}
impl Default for Owner {
fn default() -> Self {
Owner {
data: Rc::new(RefCell::new(Default::default())),
n: 0_i32,
arr: Rc::new(RefCell::new((0..2).map(|_| 0_i32).collect::<Box<[i32]>>())),
p: None,
{
Owner {
data: Rc::new(RefCell::new(Default::default())),
n: 0_i32,
arr: Rc::new(RefCell::new((0..2).map(|_| 0_i32).collect::<Box<[i32]>>())),
p: None,
}
}
}
}
Expand Down
64 changes: 35 additions & 29 deletions tests/unit/out/refcount/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,22 @@ pub struct Pointers {
}
impl Default for Pointers {
fn default() -> Self {
Pointers {
x1: Ptr::<i32>::null(),
x2: Ptr::<i32>::null(),
x3: Rc::new(RefCell::new(
(0..5)
.map(|_| Ptr::<i32>::null())
.collect::<Box<[Ptr<i32>]>>(),
)),
x4: Rc::new(RefCell::new(
(0..10)
.map(|_| Ptr::<i32>::null())
.collect::<Box<[Ptr<i32>]>>(),
)),
x5: 0_i32,
{
Pointers {
x1: Ptr::<i32>::null(),
x2: Ptr::<i32>::null(),
x3: Rc::new(RefCell::new(
(0..5)
.map(|_| Ptr::<i32>::null())
.collect::<Box<[Ptr<i32>]>>(),
)),
x4: Rc::new(RefCell::new(
(0..10)
.map(|_| Ptr::<i32>::null())
.collect::<Box<[Ptr<i32>]>>(),
)),
x5: 0_i32,
}
}
}
}
Expand All @@ -61,19 +63,21 @@ pub struct SmallArrays {
}
impl Default for SmallArrays {
fn default() -> Self {
SmallArrays {
a: Rc::new(RefCell::new((0..32).map(|_| 0_i32).collect::<Box<[i32]>>())),
f: FnPtr::<fn(i32) -> i32>::null(),
fs: Rc::new(RefCell::new(
(0..2)
.map(|_| FnPtr::<fn(i32) -> i32>::null())
.collect::<Box<[FnPtr<fn(i32) -> i32>]>>(),
)),
p: Rc::new(RefCell::new(
(0..2)
.map(|_| <Pointers>::default())
.collect::<Box<[Pointers]>>(),
)),
{
SmallArrays {
a: Rc::new(RefCell::new((0..32).map(|_| 0_i32).collect::<Box<[i32]>>())),
f: FnPtr::<fn(i32) -> i32>::null(),
fs: Rc::new(RefCell::new(
(0..2)
.map(|_| FnPtr::<fn(i32) -> i32>::null())
.collect::<Box<[FnPtr<fn(i32) -> i32>]>>(),
)),
p: Rc::new(RefCell::new(
(0..2)
.map(|_| <Pointers>::default())
.collect::<Box<[Pointers]>>(),
)),
}
}
}
}
Expand All @@ -86,8 +90,10 @@ pub struct BigArray {
}
impl Default for BigArray {
fn default() -> Self {
BigArray {
a: Rc::new(RefCell::new((0..33).map(|_| 0_i32).collect::<Box<[i32]>>())),
{
BigArray {
a: Rc::new(RefCell::new((0..33).map(|_| 0_i32).collect::<Box<[i32]>>())),
}
}
}
}
Expand Down
28 changes: 15 additions & 13 deletions tests/unit/out/refcount/default_in_statics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,21 @@ pub struct Outer {
}
impl Default for Outer {
fn default() -> Self {
Outer {
p1: Ptr::<i32>::null(),
p2: Ptr::<i32>::null(),
arr: Rc::new(RefCell::new(
(0..3)
.map(|_| Ptr::<i32>::null())
.collect::<Box<[Ptr<i32>]>>(),
)),
cp: Ptr::<i8>::null(),
pp: Ptr::<Ptr<i32>>::null(),
inner: <Inner>::default(),
x: 0_i32,
fn_: FnPtr::<fn(i32) -> i32>::null(),
{
Outer {
p1: Ptr::<i32>::null(),
p2: Ptr::<i32>::null(),
arr: Rc::new(RefCell::new(
(0..3)
.map(|_| Ptr::<i32>::null())
.collect::<Box<[Ptr<i32>]>>(),
)),
cp: Ptr::<i8>::null(),
pp: Ptr::<Ptr<i32>>::null(),
inner: <Inner>::default(),
x: 0_i32,
fn_: FnPtr::<fn(i32) -> i32>::null(),
}
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions tests/unit/out/refcount/destructor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ pub struct ArrayMember {
}
impl Default for ArrayMember {
fn default() -> Self {
ArrayMember {
items: Rc::new(RefCell::new(
(0..3).map(|_| <S>::default()).collect::<Box<[S]>>(),
)),
{
ArrayMember {
items: Rc::new(RefCell::new(
(0..3).map(|_| <S>::default()).collect::<Box<[S]>>(),
)),
}
}
}
}
Expand Down
Loading
Loading