diff options
-rw-r--r-- | src/ir/context.rs | 8 | ||||
-rw-r--r-- | src/ir/item.rs | 3 |
2 files changed, 9 insertions, 2 deletions
diff --git a/src/ir/context.rs b/src/ir/context.rs index c5c321c4..fc06375c 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -505,9 +505,15 @@ impl<'ctx> BindgenContext<'ctx> { found_invalid_template_ref = true; } if c.kind() == CXCursor_TypeRef { + // The `with_id` id will potentially end up unused if we give up + // on this type (for example, its a tricky partial template + // specialization), so if we pass `with_id` as the parent, it is + // potentially a dangling reference. Instead, use the canonical + // template declaration as the parent. It is already parsed and + // has a known-resolvable `ItemId`. let new_ty = Item::from_ty_or_ref(c.cur_type(), Some(c), - Some(with_id), + Some(wrapping), self); args.push(new_ty); } diff --git a/src/ir/item.rs b/src/ir/item.rs index 6eff60c9..6d2d4b02 100644 --- a/src/ir/item.rs +++ b/src/ir/item.rs @@ -88,7 +88,8 @@ impl ItemId { /// Allocate the next `ItemId`. pub fn next() -> Self { static NEXT_ITEM_ID: AtomicUsize = ATOMIC_USIZE_INIT; - ItemId(NEXT_ITEM_ID.fetch_add(1, Ordering::Relaxed)) + let next_id = NEXT_ITEM_ID.fetch_add(1, Ordering::Relaxed); + ItemId(next_id) } } |