Skip to content

Commit f084ff1

Browse files
committed
Update tests
1 parent 809019f commit f084ff1

3 files changed

Lines changed: 59 additions & 1 deletion

File tree

‎cpp2rust/converter/converter_lib.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ bool IsUserDefinedDecl(const clang::Decl *decl) {
266266
const auto &ctx = decl->getASTContext();
267267
const auto &src_mgr = ctx.getSourceManager();
268268
auto src_loc = decl->getLocation();
269-
if (auto *spec = clang::dyn_cast<clang::ClassTemplateSpecializationDecl>(decl);
269+
if (auto *spec =
270+
clang::dyn_cast<clang::ClassTemplateSpecializationDecl>(decl);
270271
spec && (spec->getSpecializationKind() ==
271272
clang::TSK_ExplicitInstantiationDeclaration ||
272273
spec->getSpecializationKind() ==

‎tests/unit/out/refcount/class_templates.rs‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ pub struct MyContainer_float_ {
2828
vec_: Value<Vec<f32>>,
2929
}
3030
#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)]
31+
#[byte_size(2)]
32+
pub struct Boxed_short_ {
33+
#[offset(0)]
34+
pub value: i16,
35+
}
36+
impl Boxed_short_ {
37+
pub fn twice(mut v: i16) -> i16 {
38+
return (((v as i32) + (v as i32)) as i16);
39+
}
40+
}
41+
#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)]
3142
#[byte_size(4)]
3243
pub struct Boxed_int_ {
3344
#[offset(0)]
@@ -85,11 +96,24 @@ pub struct Outer_long_ {
8596
#[offset(0)]
8697
pub v: i64,
8798
}
99+
#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)]
100+
#[byte_size(4)]
101+
pub struct Elem {
102+
#[offset(0)]
103+
pub i: i32,
104+
}
88105
pub fn main() {
89106
__cpp2rust_init_globals();
90107
std::process::exit(main_0());
91108
}
92109
fn main_0() -> i32 {
110+
let mut ev: Vec<Elem> = Vec::new();
111+
{
112+
let __a1 = Elem { i: 2 };
113+
ev.push(__a1)
114+
};
115+
assert!(({ ev[0_usize].i } == 2));
116+
assert!(((({ Boxed_short_::twice(2_i16,) }) as i32) == 4));
93117
let oi: Value<Outer_int_> = Rc::new(RefCell::new(Outer_int_ { v: 3 }));
94118
assert!(
95119
(({
@@ -181,6 +205,14 @@ impl Boxed_long_Impl for Ptr<Boxed_long_> {
181205
return ((*self).with(|__s| __s.value) + other);
182206
}
183207
}
208+
pub trait Boxed_short_Impl {
209+
fn plus(&self, other: i16) -> i16;
210+
}
211+
impl Boxed_short_Impl for Ptr<Boxed_short_> {
212+
fn plus(&self, mut other: i16) -> i16 {
213+
return ((((*self).with(|__s| __s.value) as i32) + (other as i32)) as i16);
214+
}
215+
}
184216
pub trait MyContainer_char_Impl {
185217
fn empty(&self) -> bool;
186218
fn size(&self) -> usize;

‎tests/unit/out/unsafe/class_templates.rs‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,19 @@ impl MyContainer_float_ {
8686
}
8787
#[repr(C)]
8888
#[derive(Copy, Clone, VaArg, FnPtrArg, Default)]
89+
pub struct Boxed_short_ {
90+
pub value: i16,
91+
}
92+
impl Boxed_short_ {
93+
pub unsafe fn twice(mut v: i16) -> i16 {
94+
return (((v as i32) + (v as i32)) as i16);
95+
}
96+
pub unsafe fn plus(&self, mut other: i16) -> i16 {
97+
return (((self.value as i32) + (other as i32)) as i16);
98+
}
99+
}
100+
#[repr(C)]
101+
#[derive(Copy, Clone, VaArg, FnPtrArg, Default)]
89102
pub struct Boxed_int_ {
90103
pub value: i32,
91104
}
@@ -163,13 +176,25 @@ impl Outer_long_ {
163176
return Outer_long__Inner_int_ { t: self.v, u: n };
164177
}
165178
}
179+
#[repr(C)]
180+
#[derive(Copy, Clone, VaArg, FnPtrArg, Default)]
181+
pub struct Elem {
182+
pub i: i32,
183+
}
166184
pub fn main() {
167185
unsafe {
168186
__cpp2rust_init_globals();
169187
std::process::exit(main_0() as i32);
170188
}
171189
}
172190
unsafe fn main_0() -> i32 {
191+
let mut ev: Vec<Elem> = Vec::new();
192+
{
193+
let __a1 = Elem { i: 2 };
194+
ev.push(__a1)
195+
};
196+
assert!(((ev[(0_usize)].i) == (2)));
197+
assert!((((unsafe { Boxed_short_::twice(2_i16,) }) as i32) == (4)));
173198
let mut oi: Outer_int_ = Outer_int_ { v: 3 };
174199
assert!(
175200
((unsafe { Outer_int__Inner_int_::sum(&(unsafe { Outer_int_::with(&oi, 4,) }),) }) == (7))

0 commit comments

Comments
 (0)