Skip to content

Commit c21b602

Browse files
committed
Add static-member template test
1 parent 2035c00 commit c21b602

3 files changed

Lines changed: 101 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
thread_local!(
10+
pub static s_0: Value<i32> = Rc::new(RefCell::new(55));
11+
);
12+
#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)]
13+
#[byte_size(1)]
14+
pub struct Static_int_ {}
15+
thread_local!(
16+
pub static s_1: Value<u8> = Rc::new(RefCell::new(55_u8));
17+
);
18+
#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)]
19+
#[byte_size(1)]
20+
pub struct Static_char_ {}
21+
thread_local!(
22+
pub static s_2: Value<i64> = Rc::new(RefCell::new(55_i64));
23+
);
24+
#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)]
25+
#[byte_size(1)]
26+
pub struct Static_long_ {}
27+
pub fn main() {
28+
__cpp2rust_init_globals();
29+
std::process::exit(main_0());
30+
}
31+
fn main_0() -> i32 {
32+
s_0.with(|rc| *rc.borrow_mut() = 22);
33+
s_1.with(|rc| *rc.borrow_mut() = 33_u8);
34+
assert!((s_0.with(|rc| *rc.borrow()) == 22));
35+
assert!(((s_1.with(|rc| *rc.borrow()) as i32) == 33));
36+
assert!((s_2.with(|rc| *rc.borrow()) == 55_i64));
37+
return 0;
38+
}
39+
pub fn __cpp2rust_init_globals() {
40+
let _ = s_0.with(|_| ());
41+
let _ = s_1.with(|_| ());
42+
let _ = s_2.with(|_| ());
43+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
pub static mut s_0: std::cell::LazyCell<i32> = std::cell::LazyCell::new(|| unsafe { 55 });
10+
#[repr(C)]
11+
#[derive(Copy, Clone, VaArg, Default)]
12+
pub struct Static_int_ {}
13+
pub static mut s_1: std::cell::LazyCell<libc::c_char> =
14+
std::cell::LazyCell::new(|| unsafe { (55 as libc::c_char) });
15+
#[repr(C)]
16+
#[derive(Copy, Clone, VaArg, Default)]
17+
pub struct Static_char_ {}
18+
pub static mut s_2: std::cell::LazyCell<i64> = std::cell::LazyCell::new(|| unsafe { 55_i64 });
19+
#[repr(C)]
20+
#[derive(Copy, Clone, VaArg, Default)]
21+
pub struct Static_long_ {}
22+
pub fn main() {
23+
unsafe {
24+
__cpp2rust_init_globals();
25+
std::process::exit(main_0() as i32);
26+
}
27+
}
28+
unsafe fn main_0() -> i32 {
29+
(*std::cell::LazyCell::force_mut(&mut *&raw mut s_0)) = 22;
30+
(*std::cell::LazyCell::force_mut(&mut *&raw mut s_1)) = (33 as libc::c_char);
31+
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut s_0)) == (22)));
32+
assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut s_1)) as i32) == (33)));
33+
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut s_2)) == (55_i64)));
34+
return 0;
35+
}
36+
pub unsafe fn __cpp2rust_init_globals() {
37+
std::cell::LazyCell::force(&*&raw const s_0);
38+
std::cell::LazyCell::force(&*&raw const s_1);
39+
std::cell::LazyCell::force(&*&raw const s_2);
40+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <cassert>
2+
3+
template <class T> struct Static {
4+
static T s;
5+
};
6+
7+
template <class T> T Static<T>::s = 55;
8+
9+
int main() {
10+
Static<int>::s = 22;
11+
Static<char>::s = 33;
12+
13+
assert(Static<int>::s == 22);
14+
assert(Static<char>::s == 33);
15+
assert(Static<long>::s == 55);
16+
17+
return 0;
18+
}

0 commit comments

Comments
 (0)