Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cpp2rust/converter/converter_lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,10 @@ static std::string GetLexicalSpecializationID(const clang::Decl *decl) {
clang::dyn_cast<clang::VarTemplateSpecializationDecl>(decl)) {
id += GetMangledName(var);
}
if (const auto *fn = clang::dyn_cast<clang::FunctionDecl>(decl);
fn && fn->getTemplateSpecializationArgs()) {
id += GetMangledName(fn);
}
if (const auto *self =
clang::dyn_cast<clang::ClassTemplateSpecializationDecl>(decl)) {
id += GetMangledTypeName(self);
Expand Down
10 changes: 7 additions & 3 deletions tests/std/basic/basic.def.odr/p15-function-template/a.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@
#include "../../../support/asserts-dtor-count-at-exit.h"
#include "h.h"

AssertsDtorCountAtExit check{2};
AssertsDtorCountAtExit check{4};

int main() {
assert(LifetimeTracked::ctorCount == 0);
struct S {};
assert(count<S>() == 1);
assert(b_count_local() == 1);
assert(count<S>() == 2);
assert(count<int>() == 1);
assert(b_count_int() == 2);
assert(count<int>() == 3);
assert(LifetimeTracked::ctorCount == 1);
assert(LifetimeTracked::ctorCount == 3);
assert(count<long>() == 1);
assert(b_count_long() == 2);
assert(LifetimeTracked::ctorCount == 2);
assert(LifetimeTracked::ctorCount == 4);
return 0;
}
5 changes: 5 additions & 0 deletions tests/std/basic/basic.def.odr/p15-function-template/b.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@
int b_count_int() { return count<int>(); }

int b_count_long() { return count<long>(); }

int b_count_local() {
struct S {};
return count<S>();
}
2 changes: 2 additions & 0 deletions tests/std/basic/basic.def.odr/p15-function-template/h.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ template <class T> int count() {

int b_count_int();
int b_count_long();

int b_count_local();
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ pub fn count_4() -> i32 {
pub fn count_7() -> i32 {
return (*n_9.with(Value::clone).borrow_mut()).prefix_inc();
}
pub fn count_10() -> i32 {
return (*n_12.with(Value::clone).borrow_mut()).prefix_inc();
}
thread_local!(
static t_5: Value<LifetimeTracked> = Rc::new(RefCell::new(LifetimeTracked::new()));
);
Expand All @@ -92,8 +95,14 @@ thread_local!(
static n_9: Value<i32> = Rc::new(RefCell::new(0));
);
thread_local!(
pub static check_10: Value<AssertsDtorCountAtExit> =
Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 2 }));
static t_11: Value<LifetimeTracked> = Rc::new(RefCell::new(LifetimeTracked::new()));
);
thread_local!(
static n_12: Value<i32> = Rc::new(RefCell::new(0));
);
thread_local!(
pub static check_13: Value<AssertsDtorCountAtExit> =
Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 4 }));
);
pub fn main() {
__cpp2rust_init_globals();
Expand All @@ -102,20 +111,41 @@ pub fn main() {
fn main_0() -> i32 {
assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0));
assert!((({ count_4() }) == 1));
assert!((({ b_count_int_11() }) == 2));
assert!((({ count_4() }) == 3));
assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1));
assert!((({ b_count_local_15() }) == 1));
assert!((({ count_4() }) == 2));
assert!((({ count_7() }) == 1));
assert!((({ b_count_long_12() }) == 2));
assert!((ctorCount_0.with(|rc| *rc.borrow()) == 2));
assert!((({ b_count_int_16() }) == 2));
assert!((({ count_7() }) == 3));
assert!((ctorCount_0.with(|rc| *rc.borrow()) == 3));
assert!((({ count_10() }) == 1));
assert!((({ b_count_long_17() }) == 2));
assert!((ctorCount_0.with(|rc| *rc.borrow()) == 4));
return 0;
}
pub fn b_count_int_11() -> i32 {
return ({ count_4() });
#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)]
#[byte_size(1)]
pub struct S_14 {}
pub fn count_18() -> i32 {
return (*n_20.with(Value::clone).borrow_mut()).prefix_inc();
}
pub fn b_count_long_12() -> i32 {
thread_local!(
static t_19: Value<LifetimeTracked> = Rc::new(RefCell::new(LifetimeTracked::new()));
);
thread_local!(
static n_20: Value<i32> = Rc::new(RefCell::new(0));
);
pub fn b_count_int_16() -> i32 {
return ({ count_7() });
}
pub fn b_count_long_17() -> i32 {
return ({ count_10() });
}
pub fn b_count_local_15() -> i32 {
return ({ count_18() });
}
#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)]
#[byte_size(1)]
pub struct S_21 {}
pub trait AssertsDtorCountAtExitImpl {
fn destructor(&self);
}
Expand Down Expand Up @@ -147,5 +177,5 @@ pub fn __cpp2rust_init_globals() {
let _ = copyCount_1.with(|_| ());
let _ = dtorCount_2.with(|_| ());
let _ = useCount_3.with(|_| ());
let _ = check_10.with(|_| ());
let _ = check_13.with(|_| ());
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,20 @@ pub unsafe fn count_4() -> i32 {
pub unsafe fn count_7() -> i32 {
return (*std::cell::LazyCell::force_mut(&mut *&raw mut n_9)).prefix_inc();
}
pub unsafe fn count_10() -> i32 {
return (*std::cell::LazyCell::force_mut(&mut *&raw mut n_12)).prefix_inc();
}
static mut t_5: std::cell::LazyCell<LifetimeTracked> =
std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() });
static mut n_6: std::cell::LazyCell<i32> = std::cell::LazyCell::new(|| unsafe { 0 });
static mut t_8: std::cell::LazyCell<LifetimeTracked> =
std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() });
static mut n_9: std::cell::LazyCell<i32> = std::cell::LazyCell::new(|| unsafe { 0 });
pub static mut check_10: std::cell::LazyCell<AssertsDtorCountAtExit> =
std::cell::LazyCell::new(|| unsafe { AssertsDtorCountAtExit { expected: 2 } });
static mut t_11: std::cell::LazyCell<LifetimeTracked> =
std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() });
static mut n_12: std::cell::LazyCell<i32> = std::cell::LazyCell::new(|| unsafe { 0 });
pub static mut check_13: std::cell::LazyCell<AssertsDtorCountAtExit> =
std::cell::LazyCell::new(|| unsafe { AssertsDtorCountAtExit { expected: 4 } });
pub fn main() {
unsafe {
__cpp2rust_init_globals();
Expand All @@ -93,24 +99,42 @@ pub fn main() {
unsafe fn main_0() -> i32 {
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0)));
assert!(((unsafe { count_4() }) == (1)));
assert!(((unsafe { b_count_int_11() }) == (2)));
assert!(((unsafe { count_4() }) == (3)));
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1)));
assert!(((unsafe { b_count_local_15() }) == (1)));
assert!(((unsafe { count_4() }) == (2)));
assert!(((unsafe { count_7() }) == (1)));
assert!(((unsafe { b_count_long_12() }) == (2)));
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (2)));
assert!(((unsafe { b_count_int_16() }) == (2)));
assert!(((unsafe { count_7() }) == (3)));
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (3)));
assert!(((unsafe { count_10() }) == (1)));
assert!(((unsafe { b_count_long_17() }) == (2)));
assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (4)));
return 0;
}
pub unsafe fn b_count_int_11() -> i32 {
return (unsafe { count_4() });
#[repr(C)]
#[derive(Copy, Clone, VaArg, FnPtrArg, Default)]
pub struct S_14 {}
pub unsafe fn count_18() -> i32 {
return (*std::cell::LazyCell::force_mut(&mut *&raw mut n_20)).prefix_inc();
}
pub unsafe fn b_count_long_12() -> i32 {
static mut t_19: std::cell::LazyCell<LifetimeTracked> =
std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() });
static mut n_20: std::cell::LazyCell<i32> = std::cell::LazyCell::new(|| unsafe { 0 });
pub unsafe fn b_count_int_16() -> i32 {
return (unsafe { count_7() });
}
pub unsafe fn b_count_long_17() -> i32 {
return (unsafe { count_10() });
}
pub unsafe fn b_count_local_15() -> i32 {
return (unsafe { count_18() });
}
#[repr(C)]
#[derive(Copy, Clone, VaArg, FnPtrArg, Default)]
pub struct S_21 {}
pub unsafe fn __cpp2rust_init_globals() {
std::cell::LazyCell::force(&*&raw const ctorCount_0);
std::cell::LazyCell::force(&*&raw const copyCount_1);
std::cell::LazyCell::force(&*&raw const dtorCount_2);
std::cell::LazyCell::force(&*&raw const useCount_3);
std::cell::LazyCell::force(&*&raw const check_10);
std::cell::LazyCell::force(&*&raw const check_13);
}
Loading