Skip to content

Commit c173c88

Browse files
committed
Add test with field-less template tha trequires Clone
1 parent f59e173 commit c173c88

3 files changed

Lines changed: 104 additions & 0 deletions

File tree

‎tests/unit/opaque_record_copy.cpp‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include <cassert>
2+
3+
class Probe {
4+
public:
5+
Probe &operator++();
6+
};
7+
8+
template <class T>
9+
struct Wrapper {
10+
T base_;
11+
int tag;
12+
};
13+
14+
int main() {
15+
Wrapper<Probe> a{};
16+
a.tag = 3;
17+
Wrapper<Probe> b = a;
18+
assert(b.tag == 3);
19+
return 0;
20+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
extern crate libcc2rs;
2+
use libcc2rs::*;
3+
use std::cell::RefCell;
4+
use std::collections::BTreeMap;
5+
use std::io::prelude::*;
6+
use std::io::{Read, Seek, Write};
7+
use std::os::fd::AsFd;
8+
use std::rc::{Rc, Weak};
9+
#[derive(Default)]
10+
pub struct Wrapper_Probe_ {
11+
pub base_: Value<Probe>,
12+
pub tag: Value<i32>,
13+
}
14+
impl Clone for Wrapper_Probe_ {
15+
fn clone(&self) -> Self {
16+
let __this: Value<Wrapper_Probe_> = Rc::new(RefCell::new(Self {
17+
base_: Rc::new(RefCell::new((*self.base_.borrow()).clone())),
18+
tag: Rc::new(RefCell::new((*self.tag.borrow()))),
19+
}));
20+
let this: Ptr<Wrapper_Probe_> = __this.as_pointer();
21+
Rc::try_unwrap(__this).ok().unwrap().into_inner()
22+
}
23+
}
24+
impl ByteRepr for Wrapper_Probe_ {
25+
fn byte_size() -> usize {
26+
8
27+
}
28+
fn to_bytes(&self, buf: &mut [u8]) {
29+
(*self.base_.borrow()).to_bytes(&mut buf[0..1]);
30+
(*self.tag.borrow()).to_bytes(&mut buf[4..8]);
31+
}
32+
fn from_bytes(buf: &[u8]) -> Self {
33+
Self {
34+
base_: Rc::new(RefCell::new(<Probe>::from_bytes(&buf[0..1]))),
35+
tag: Rc::new(RefCell::new(<i32>::from_bytes(&buf[4..8]))),
36+
}
37+
}
38+
}
39+
pub fn main() {
40+
std::process::exit(main_0());
41+
}
42+
fn main_0() -> i32 {
43+
let a: Value<Wrapper_Probe_> = Rc::new(RefCell::new(Wrapper_Probe_ {
44+
base_: Rc::new(RefCell::new(Probe {})),
45+
tag: Rc::new(RefCell::new(<i32>::default())),
46+
}));
47+
(*(*a.borrow()).tag.borrow_mut()) = 3;
48+
let b: Value<Wrapper_Probe_> = Rc::new(RefCell::new((*a.borrow()).clone()));
49+
assert!(((*(*b.borrow()).tag.borrow()) == 3));
50+
return 0;
51+
}
52+
#[derive(Clone, Copy, Default, ByteRepr)]
53+
pub struct Probe;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
extern crate libc;
2+
use libc::*;
3+
extern crate libcc2rs;
4+
use libcc2rs::*;
5+
use std::collections::BTreeMap;
6+
use std::io::{Read, Seek, Write};
7+
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
8+
use std::rc::Rc;
9+
#[repr(C)]
10+
#[derive(Clone, Default)]
11+
pub struct Wrapper_Probe_ {
12+
pub base_: Probe,
13+
pub tag: i32,
14+
}
15+
pub fn main() {
16+
unsafe {
17+
std::process::exit(main_0() as i32);
18+
}
19+
}
20+
unsafe fn main_0() -> i32 {
21+
let mut a: Wrapper_Probe_ = Wrapper_Probe_ {
22+
base_: Probe {},
23+
tag: 0_i32,
24+
};
25+
a.tag = 3;
26+
let mut b: Wrapper_Probe_ = a.clone();
27+
assert!(((b.tag) == (3)));
28+
return 0;
29+
}
30+
#[derive(Clone, Copy, Default, ByteRepr)]
31+
pub struct Probe;

0 commit comments

Comments
 (0)