Skip to content

Commit 8226358

Browse files
committed
Add test for default initialized static local vars
1 parent a417fcf commit 8226358

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

tests/unit/out/refcount/static_local.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,24 @@ use std::io::{Read, Write};
88
use std::os::fd::AsFd;
99
use std::rc::{Rc, Weak};
1010
pub fn foo_0() -> i32 {
11+
thread_local!(
12+
static static_i: Value<i32> = <Value<i32>>::default();
13+
);
14+
thread_local!(
15+
static static_f: Value<f32> = <Value<f32>>::default();
16+
);
17+
thread_local!(
18+
static static_b: Value<bool> = <Value<bool>>::default();
19+
);
1120
thread_local!(
1221
static kX1: Value<i32> = Rc::new(RefCell::new(1));
1322
);
1423
thread_local!(
1524
static kX2: Value<i32> = Rc::new(RefCell::new(2));
1625
);
1726
(*kX1.with(Value::clone).borrow_mut()) += 1;
18-
return ((*kX1.with(Value::clone).borrow()) + (*kX2.with(Value::clone).borrow()));
27+
return (((*kX1.with(Value::clone).borrow()) + (*kX2.with(Value::clone).borrow()))
28+
+ (*static_i.with(Value::clone).borrow()));
1929
}
2030
pub fn main() {
2131
std::process::exit(main_0());

tests/unit/out/unsafe/static_local.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,13 @@ use std::io::{Read, Write};
88
use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
99
use std::rc::Rc;
1010
pub unsafe fn foo_0() -> i32 {
11+
static mut static_i: i32 = 0_i32;;
12+
static mut static_f: f32 = 0.0_f32;;
13+
static mut static_b: bool = false;;
1114
static mut kX1: i32 = 1;;
1215
static kX2: i32 = 2;;
1316
kX1 += 1;
14-
return ((kX1) + (kX2));
17+
return (((kX1) + (kX2)) + (static_i));
1518
}
1619
pub fn main() {
1720
unsafe {

tests/unit/static_local.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,14 @@
22
// Distributed under the MIT license that can be found in the LICENSE file.
33

44
int foo() {
5+
static int static_i;
6+
static float static_f;
7+
static bool static_b;
8+
59
static int kX1 = 1;
610
static const int kX2 = 2;
711
kX1 += 1;
8-
return kX1 + kX2;
12+
return kX1 + kX2 + static_i;
913
}
1014

1115
int main() { return foo() + foo() + foo(); }

0 commit comments

Comments
 (0)