Skip to content

Commit 8b9a17b

Browse files
committed
Add test for returning class with destructor by value
1 parent 2289cee commit 8b9a17b

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

test/src/header.h

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef header_h__
2+
#define header_h__
3+
4+
class A {
5+
public:
6+
int a;
7+
int b;
8+
A(int a, int b) : a(a), b(b) {}
9+
~A() {}
10+
};
11+
static_assert(sizeof(A) == 8, "size should be 8");
12+
13+
#endif // defined(header_h__)

test/src/lib.rs

+21
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ mod inner;
99
cpp!{{
1010
#define _USE_MATH_DEFINES
1111
#include <math.h>
12+
#include "src/header.h"
1213
}}
1314

15+
#[repr(C)]
16+
struct A {
17+
_opaque: [i32; 2],
18+
}
19+
1420
#[test]
1521
fn captures() {
1622
let x: i32 = 10;
@@ -66,3 +72,18 @@ fn plusplus() {
6672
assert_eq!(x, 1);
6773
}
6874
}
75+
76+
#[test]
77+
fn destructor() {
78+
unsafe {
79+
let a = cpp!([] -> A as "A" {
80+
return A(5, 10);
81+
});
82+
83+
let first = cpp!([a as "A"] -> i32 as "int32_t" {
84+
return a.a;
85+
});
86+
87+
assert_eq!(first, 5);
88+
}
89+
}

0 commit comments

Comments
 (0)