Skip to content

Commit 63086df

Browse files
committed
Don't translate partial specializations
1 parent 540902a commit 63086df

4 files changed

Lines changed: 21 additions & 0 deletions

File tree

‎cpp2rust/converter/converter.cpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,9 @@ void Converter::ConvertGlobalVarDecl(clang::VarDecl *decl) {
635635
}
636636

637637
bool Converter::VisitVarDecl(clang::VarDecl *decl) {
638+
if (clang::isa<clang::VarTemplatePartialSpecializationDecl>(decl)) {
639+
return false;
640+
}
638641
if (ConvertLambdaVarDecl(decl)) {
639642
return false;
640643
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ thread_local!(
5050
thread_local!(
5151
pub static half_7: Value<f64> = Rc::new(RefCell::new((1_f64 / 2_f64)));
5252
);
53+
thread_local!(
54+
pub static half_8: Value<Ptr<i32>> = Rc::new(RefCell::new(Ptr::<i32>::null()));
55+
);
5356
pub fn main() {
5457
__cpp2rust_init_globals();
5558
std::process::exit(main_0());
@@ -70,9 +73,13 @@ fn main_0() -> i32 {
7073
half_6.with(|rc| *rc.borrow_mut() = 7);
7174
assert!((half_6.with(|rc| *rc.borrow()) == 7));
7275
assert!((half_7.with(|rc| *rc.borrow()) == 5.0E-1));
76+
assert!((half_8.with(|rc| rc.borrow().clone())).is_null());
77+
half_8.with(|rc| *rc.borrow_mut() = (x.as_pointer()));
78+
assert!(((half_8.with(|rc| rc.borrow().clone()).read()) == 10));
7379
return 0;
7480
}
7581
pub fn __cpp2rust_init_globals() {
7682
let _ = half_6.with(|_| ());
7783
let _ = half_7.with(|_| ());
84+
let _ = half_8.with(|_| ());
7885
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ pub static mut half_6: std::cell::LazyCell<i32> =
2828
std::cell::LazyCell::new(|| unsafe { ((1) / (2)) });
2929
pub static mut half_7: std::cell::LazyCell<f64> =
3030
std::cell::LazyCell::new(|| unsafe { ((1_f64) / (2_f64)) });
31+
pub static mut half_8: std::cell::LazyCell<*mut i32> =
32+
std::cell::LazyCell::new(|| unsafe { std::ptr::null_mut() });
3133
pub fn main() {
3234
unsafe {
3335
__cpp2rust_init_globals();
@@ -50,9 +52,13 @@ unsafe fn main_0() -> i32 {
5052
(*std::cell::LazyCell::force_mut(&mut *&raw mut half_6)) = 7;
5153
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut half_6)) == (7)));
5254
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut half_7)) == (5.0E-1)));
55+
assert!((*std::cell::LazyCell::force_mut(&mut *&raw mut half_8)).is_null());
56+
(*std::cell::LazyCell::force_mut(&mut *&raw mut half_8)) = (&mut x as *mut i32);
57+
assert!(((*(*std::cell::LazyCell::force_mut(&mut *&raw mut half_8))) == (10)));
5358
return 0;
5459
}
5560
pub unsafe fn __cpp2rust_init_globals() {
5661
std::cell::LazyCell::force(&*&raw const half_6);
5762
std::cell::LazyCell::force(&*&raw const half_7);
63+
std::cell::LazyCell::force(&*&raw const half_8);
5864
}

‎tests/unit/templates.cpp‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ template <typename T1, typename T2, typename T3> int func(T1 x1, T2 x2, T3 x3) {
1010

1111
template <typename T> T half = T(1) / T(2);
1212

13+
template <typename T> T *half<T *> = nullptr;
14+
1315
int main() {
1416
int x = 10;
1517
double y = x;
@@ -21,5 +23,8 @@ int main() {
2123
half<int> = 7;
2224
assert(half<int> == 7);
2325
assert(half<double> == 0.5);
26+
assert(half<int *> == nullptr);
27+
half<int *> = &x;
28+
assert(*half<int *> == 10);
2429
return 0;
2530
}

0 commit comments

Comments
 (0)