diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 8499531211..c1d37cb829 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -1039,6 +1039,10 @@ static std::string GetLexicalSpecializationID(const clang::Decl *decl) { clang::dyn_cast(decl)) { id += GetMangledName(var); } + if (const auto *fn = clang::dyn_cast(decl); + fn && fn->getTemplateSpecializationArgs()) { + id += GetMangledName(fn); + } if (const auto *self = clang::dyn_cast(decl)) { id += GetMangledTypeName(self); diff --git a/tests/std/basic/basic.def.odr/p15-function-template/a.cpp b/tests/std/basic/basic.def.odr/p15-function-template/a.cpp index 6462d0bf58..b9fd0901e6 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/a.cpp +++ b/tests/std/basic/basic.def.odr/p15-function-template/a.cpp @@ -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() == 1); + assert(b_count_local() == 1); + assert(count() == 2); assert(count() == 1); assert(b_count_int() == 2); assert(count() == 3); - assert(LifetimeTracked::ctorCount == 1); + assert(LifetimeTracked::ctorCount == 3); assert(count() == 1); assert(b_count_long() == 2); - assert(LifetimeTracked::ctorCount == 2); + assert(LifetimeTracked::ctorCount == 4); return 0; } diff --git a/tests/std/basic/basic.def.odr/p15-function-template/b.cpp b/tests/std/basic/basic.def.odr/p15-function-template/b.cpp index 1068ec9648..51c775fd42 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/b.cpp +++ b/tests/std/basic/basic.def.odr/p15-function-template/b.cpp @@ -3,3 +3,8 @@ int b_count_int() { return count(); } int b_count_long() { return count(); } + +int b_count_local() { + struct S {}; + return count(); +} diff --git a/tests/std/basic/basic.def.odr/p15-function-template/h.h b/tests/std/basic/basic.def.odr/p15-function-template/h.h index 59a1696008..65f3305a1d 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/h.h +++ b/tests/std/basic/basic.def.odr/p15-function-template/h.h @@ -14,3 +14,5 @@ template int count() { int b_count_int(); int b_count_long(); + +int b_count_local(); diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs index 23e85e5d19..1ec062701b 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs +++ b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs @@ -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 = Rc::new(RefCell::new(LifetimeTracked::new())); ); @@ -92,8 +95,14 @@ thread_local!( static n_9: Value = Rc::new(RefCell::new(0)); ); thread_local!( - pub static check_10: Value = - Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 2 })); + static t_11: Value = Rc::new(RefCell::new(LifetimeTracked::new())); +); +thread_local!( + static n_12: Value = Rc::new(RefCell::new(0)); +); +thread_local!( + pub static check_13: Value = + Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 4 })); ); pub fn main() { __cpp2rust_init_globals(); @@ -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 = Rc::new(RefCell::new(LifetimeTracked::new())); +); +thread_local!( + static n_20: Value = 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); } @@ -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(|_| ()); } diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs index 930c85a943..b044d15810 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs +++ b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs @@ -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 = std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); static mut n_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); static mut t_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); static mut n_9: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); -pub static mut check_10: std::cell::LazyCell = - std::cell::LazyCell::new(|| unsafe { AssertsDtorCountAtExit { expected: 2 } }); +static mut t_11: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); +static mut n_12: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); +pub static mut check_13: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { AssertsDtorCountAtExit { expected: 4 } }); pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -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 = + std::cell::LazyCell::new(|| unsafe { LifetimeTracked::new() }); +static mut n_20: std::cell::LazyCell = 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); }