diff options
49 files changed, 572 insertions, 104 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 4f0ea371..73aa17c0 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -435,6 +435,16 @@ impl CodeGenerator for Var { } result.saw_var(&canonical_name); + // We can't generate bindings to static variables of templates. The + // number of actual variables for a single declaration are open ended + // and we don't know what instantiations do or don't exist. + let type_params = item.all_template_params(ctx); + if let Some(params) = type_params { + if !params.is_empty() { + return; + } + } + let ty = self.ty().to_rust_ty_or_opaque(ctx, &()); if let Some(val) = self.val() { @@ -752,6 +762,13 @@ impl CodeGenerator for TemplateInstantiation { return } + // If there are any unbound type parameters, then we can't generate a + // layout test because we aren't dealing with a concrete type with a + // concrete size and alignment. + if ctx.uses_any_template_parameters(item.id()) { + return; + } + let layout = item.kind().expect_type().layout(ctx); if let Some(layout) = layout { @@ -759,8 +776,11 @@ impl CodeGenerator for TemplateInstantiation { let align = layout.align; let name = item.canonical_name(ctx); - let fn_name = format!("__bindgen_test_layout_{}_instantiation_{}", - name, item.exposed_id(ctx)); + let mut fn_name = format!("__bindgen_test_layout_{}_instantiation", name); + let times_seen = result.overload_number(&fn_name); + if times_seen > 0 { + write!(&mut fn_name, "_{}", times_seen).unwrap(); + } let fn_name = ctx.rust_ident_raw(&fn_name); @@ -2920,6 +2940,17 @@ impl CodeGenerator for Function { item: &Item) { debug!("<Function as CodeGenerator>::codegen: item = {:?}", item); + // Similar to static member variables in a class template, we can't + // generate bindings to template functions, because the set of + // instantiations is open ended and we have no way of knowing which + // monomorphizations actually exist. + let type_params = item.all_template_params(ctx); + if let Some(params) = type_params { + if !params.is_empty() { + return; + } + } + let name = self.name(); let mut canonical_name = item.canonical_name(ctx); let mangled_name = self.mangled_name(); diff --git a/src/ir/context.rs b/src/ir/context.rs index a5ae1962..f61f92e2 100644 --- a/src/ir/context.rs +++ b/src/ir/context.rs @@ -2,7 +2,7 @@ use super::derive::{CanDeriveCopy, CanDeriveDebug, CanDeriveDefault}; use super::int::IntKind; -use super::item::{Item, ItemCanonicalPath, ItemSet}; +use super::item::{Item, ItemAncestors, ItemCanonicalPath, ItemSet}; use super::item_kind::ItemKind; use super::module::{Module, ModuleKind}; use super::named::{UsedTemplateParameters, analyze}; @@ -348,14 +348,8 @@ impl<'ctx> BindgenContext<'ctx> { let is_template_instantiation = is_type && item.expect_type().is_template_instantiation(); - // Be sure to track all the generated children under namespace, even - // those generated after resolving typerefs, etc. - if item.id() != item.parent_id() { - if let Some(mut parent) = self.items.get_mut(&item.parent_id()) { - if let Some(mut module) = parent.as_module_mut() { - module.children_mut().push(item.id()); - } - } + if item.id() != self.root_module { + self.add_item_to_module(&item); } if is_type && item.expect_type().is_comp() { @@ -407,6 +401,38 @@ impl<'ctx> BindgenContext<'ctx> { } } + /// Ensure that every item (other than the root module) is in a module's + /// children list. This is to make sure that every whitelisted item get's + /// codegen'd, even if its parent is not whitelisted. See issue #769 for + /// details. + fn add_item_to_module(&mut self, item: &Item) { + assert!(item.id() != self.root_module); + assert!(!self.items.contains_key(&item.id())); + + if let Some(mut parent) = self.items.get_mut(&item.parent_id()) { + if let Some(mut module) = parent.as_module_mut() { + debug!("add_item_to_module: adding {:?} as child of parent module {:?}", + item.id(), + item.parent_id()); + + module.children_mut().insert(item.id()); + return; + } + } + + debug!("add_item_to_module: adding {:?} as child of current module {:?}", + item.id(), + self.current_module); + + self.items + .get_mut(&self.current_module) + .expect("Should always have an item for self.current_module") + .as_module_mut() + .expect("self.current_module should always be a module") + .children_mut() + .insert(item.id()); + } + /// Add a new named template type parameter to this context's item set. pub fn add_named_type(&mut self, item: Item, definition: clang::Cursor) { debug!("BindgenContext::add_named_type: item = {:?}; definition = {:?}", @@ -418,6 +444,8 @@ impl<'ctx> BindgenContext<'ctx> { assert_eq!(definition.kind(), clang_sys::CXCursor_TemplateTypeParameter); + self.add_item_to_module(&item); + let id = item.id(); let old_item = self.items.insert(id, item); assert!(old_item.is_none(), @@ -620,41 +648,65 @@ impl<'ctx> BindgenContext<'ctx> { item.parent_id() }; + // Relocate the replacement item from where it was declared, to + // where the thing it is replacing was declared. + // + // First, we'll make sure that its parent id is correct. - // Reparent the item. let old_parent = self.resolve_item(replacement).parent_id(); - if new_parent == old_parent { + // Same parent and therefore also same containing + // module. Nothing to do here. continue; } - if let Some(mut module) = self.items - .get_mut(&old_parent) + self.items + .get_mut(&replacement) .unwrap() - .as_module_mut() { - // Deparent the replacement. - let position = module.children() - .iter() - .position(|id| *id == replacement) - .unwrap(); - module.children_mut().remove(position); - } + .set_parent_for_replacement(new_parent); - if let Some(mut module) = self.items - .get_mut(&new_parent) - .unwrap() - .as_module_mut() { - module.children_mut().push(replacement); + // Second, make sure that it is in the correct module's children + // set. + + let old_module = { + let immut_self = &*self; + old_parent.ancestors(immut_self) + .chain(Some(immut_self.root_module)) + .find(|id| { + let item = immut_self.resolve_item(*id); + item.as_module().map_or(false, |m| m.children().contains(&replacement)) + }) + }; + let old_module = old_module.expect("Every replacement item should be in a module"); + + let new_module = { + let immut_self = &*self; + new_parent.ancestors(immut_self).find(|id| { + immut_self.resolve_item(*id).is_module() + }) + }; + let new_module = new_module.unwrap_or(self.root_module); + + if new_module == old_module { + // Already in the correct module. + continue; } self.items - .get_mut(&replacement) + .get_mut(&old_module) .unwrap() - .set_parent_for_replacement(new_parent); + .as_module_mut() + .unwrap() + .children_mut() + .remove(&replacement); + self.items - .get_mut(&id) + .get_mut(&new_module) + .unwrap() + .as_module_mut() .unwrap() - .set_parent_for_replacement(old_parent); + .children_mut() + .insert(replacement); } } @@ -783,6 +835,21 @@ impl<'ctx> BindgenContext<'ctx> { .map_or(false, |items_used_params| items_used_params.contains(&template_param)) } + /// Return `true` if `item` uses any unbound, generic template parameters, + /// `false` otherwise. + /// + /// Has the same restrictions that `uses_template_parameter` has. + pub fn uses_any_template_parameters(&self, item: ItemId) -> bool { + assert!(self.in_codegen_phase(), + "We only compute template parameter usage as we enter codegen"); + + self.used_template_parameters + .as_ref() + .expect("should have template parameter usage info in codegen phase") + .get(&item) + .map_or(false, |used| !used.is_empty()) + } + // This deserves a comment. Builtin types don't get a valid declaration, so // we can't add it to the cursor->type map. // @@ -794,6 +861,7 @@ impl<'ctx> BindgenContext<'ctx> { fn add_builtin_item(&mut self, item: Item) { debug!("add_builtin_item: item = {:?}", item); debug_assert!(item.kind().is_type()); + self.add_item_to_module(&item); let id = item.id(); let old_item = self.items.insert(id, item); assert!(old_item.is_none(), "Inserted type twice?"); @@ -932,7 +1000,6 @@ impl<'ctx> BindgenContext<'ctx> { fn instantiate_template(&mut self, with_id: ItemId, template: ItemId, - parent_id: ItemId, ty: &clang::Type, location: clang::Cursor) -> Option<ItemId> { @@ -1038,13 +1105,14 @@ impl<'ctx> BindgenContext<'ctx> { let sub_item = Item::new(sub_id, None, None, - template_decl_id, + self.current_module, ItemKind::Type(sub_ty)); // Bypass all the validations in add_item explicitly. debug!("instantiate_template: inserting nested \ instantiation item: {:?}", sub_item); + self.add_item_to_module(&sub_item); debug_assert!(sub_id == sub_item.id()); self.items.insert(sub_id, sub_item); args.push(sub_id); @@ -1086,10 +1154,11 @@ impl<'ctx> BindgenContext<'ctx> { type_kind, ty.is_const()); let item = - Item::new(with_id, None, None, parent_id, ItemKind::Type(ty)); + Item::new(with_id, None, None, self.current_module, ItemKind::Type(ty)); // Bypass all the validations in add_item explicitly. debug!("instantiate_template: inserting item: {:?}", item); + self.add_item_to_module(&item); debug_assert!(with_id == item.id()); self.items.insert(with_id, item); Some(with_id) @@ -1143,11 +1212,6 @@ impl<'ctx> BindgenContext<'ctx> { location.is_some() { let location = location.unwrap(); - // It is always safe to hang instantiations off of the root - // module. They use their template definition for naming, - // and don't need the parent for anything else. - let parent_id = self.root_module(); - // For specialized type aliases, there's no way to get the // template parameters as of this writing (for a struct // specialization we wouldn't be in this branch anyway). @@ -1166,7 +1230,6 @@ impl<'ctx> BindgenContext<'ctx> { return self.instantiate_template(with_id, id, - parent_id, ty, location) .or_else(|| Some(id)); diff --git a/src/ir/module.rs b/src/ir/module.rs index ee3912c5..09070247 100644 --- a/src/ir/module.rs +++ b/src/ir/module.rs @@ -1,7 +1,8 @@ //! Intermediate representation for modules (AKA C++ namespaces). -use super::context::{BindgenContext, ItemId}; +use super::context::BindgenContext; use super::dot::DotAttributes; +use super::item::ItemSet; use clang; use parse::{ClangSubItemParser, ParseError, ParseResult}; use parse_one; @@ -24,7 +25,7 @@ pub struct Module { /// The kind of module this is. kind: ModuleKind, /// The children of this module, just here for convenience. - children_ids: Vec<ItemId>, + children: ItemSet, } impl Module { @@ -33,7 +34,7 @@ impl Module { Module { name: name, kind: kind, - children_ids: vec![], + children: ItemSet::new(), } } @@ -43,13 +44,13 @@ impl Module { } /// Get a mutable reference to this module's children. - pub fn children_mut(&mut self) -> &mut Vec<ItemId> { - &mut self.children_ids + pub fn children_mut(&mut self) -> &mut ItemSet { + &mut self.children } /// Get this module's children. - pub fn children(&self) -> &[ItemId] { - &self.children_ids + pub fn children(&self) -> &ItemSet { + &self.children } /// Whether this namespace is inline. diff --git a/tests/expectations/tests/anon_union.rs b/tests/expectations/tests/anon_union.rs index 5a12dccc..8b102c79 100644 --- a/tests/expectations/tests/anon_union.rs +++ b/tests/expectations/tests/anon_union.rs @@ -80,7 +80,7 @@ impl Default for ErrorResult { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_TErrorResult_instantiation_1() { +fn __bindgen_test_layout_TErrorResult_instantiation() { assert_eq!(::std::mem::size_of::<TErrorResult>() , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( TErrorResult ) )); diff --git a/tests/expectations/tests/class_nested.rs b/tests/expectations/tests/class_nested.rs index 5ab0c918..d5f4e1a9 100644 --- a/tests/expectations/tests/class_nested.rs +++ b/tests/expectations/tests/class_nested.rs @@ -78,7 +78,7 @@ extern "C" { pub static mut var: A_B; } #[test] -fn __bindgen_test_layout_A_D_instantiation_1() { +fn __bindgen_test_layout_A_D_instantiation() { assert_eq!(::std::mem::size_of::<A_D<::std::os::raw::c_int>>() , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( diff --git a/tests/expectations/tests/class_with_dtor.rs b/tests/expectations/tests/class_with_dtor.rs index c3cd31f2..d291a983 100644 --- a/tests/expectations/tests/class_with_dtor.rs +++ b/tests/expectations/tests/class_with_dtor.rs @@ -35,7 +35,7 @@ impl Default for WithoutDtor { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_HandleWithDtor_instantiation_1() { +fn __bindgen_test_layout_HandleWithDtor_instantiation() { assert_eq!(::std::mem::size_of::<HandleWithDtor<::std::os::raw::c_int>>() , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( diff --git a/tests/expectations/tests/crtp.rs b/tests/expectations/tests/crtp.rs index 03fef4cd..f76f78f8 100644 --- a/tests/expectations/tests/crtp.rs +++ b/tests/expectations/tests/crtp.rs @@ -51,7 +51,7 @@ impl Default for DerivedFromBaseWithDestructor { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_Base_instantiation_1() { +fn __bindgen_test_layout_Base_instantiation() { assert_eq!(::std::mem::size_of::<Base>() , 1usize , concat ! ( "Size of template specialization: " , stringify ! ( Base ) )); assert_eq!(::std::mem::align_of::<Base>() , 1usize , concat ! ( @@ -59,7 +59,7 @@ fn __bindgen_test_layout_Base_instantiation_1() { )); } #[test] -fn __bindgen_test_layout_BaseWithDestructor_instantiation_2() { +fn __bindgen_test_layout_BaseWithDestructor_instantiation() { assert_eq!(::std::mem::size_of::<BaseWithDestructor>() , 1usize , concat ! ( "Size of template specialization: " , stringify ! ( diff --git a/tests/expectations/tests/default-template-parameter.rs b/tests/expectations/tests/default-template-parameter.rs index 5781c7fb..e57761ce 100644 --- a/tests/expectations/tests/default-template-parameter.rs +++ b/tests/expectations/tests/default-template-parameter.rs @@ -16,7 +16,7 @@ impl <T, U> Default for Foo<T, U> { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_Foo_instantiation_1() { +fn __bindgen_test_layout_Foo_instantiation() { assert_eq!(::std::mem::size_of::<Foo<bool, ::std::os::raw::c_int>>() , 8usize , concat ! ( "Size of template specialization: " , stringify ! ( diff --git a/tests/expectations/tests/enum_and_vtable_mangling.rs b/tests/expectations/tests/enum_and_vtable_mangling.rs index 2b58a6b2..9cdd1127 100644 --- a/tests/expectations/tests/enum_and_vtable_mangling.rs +++ b/tests/expectations/tests/enum_and_vtable_mangling.rs @@ -34,3 +34,7 @@ impl Clone for C { impl Default for C { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } +extern "C" { + #[link_name = "_ZN1C5matchEv"] + pub fn C_match(this: *mut ::std::os::raw::c_void); +} diff --git a/tests/expectations/tests/forward-declaration-autoptr.rs b/tests/expectations/tests/forward-declaration-autoptr.rs index 3d2708d5..df519fe9 100644 --- a/tests/expectations/tests/forward-declaration-autoptr.rs +++ b/tests/expectations/tests/forward-declaration-autoptr.rs @@ -41,3 +41,12 @@ impl Clone for Bar { impl Default for Bar { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } +#[test] +fn __bindgen_test_layout_RefPtr_instantiation() { + assert_eq!(::std::mem::size_of::<RefPtr<Foo>>() , 8usize , concat ! ( + "Size of template specialization: " , stringify ! ( RefPtr<Foo> + ) )); + assert_eq!(::std::mem::align_of::<RefPtr<Foo>>() , 8usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + RefPtr<Foo> ) )); +} diff --git a/tests/expectations/tests/gen-constructors-neg.rs b/tests/expectations/tests/gen-constructors-neg.rs index c894b95c..834d5f2e 100644 --- a/tests/expectations/tests/gen-constructors-neg.rs +++ b/tests/expectations/tests/gen-constructors-neg.rs @@ -19,3 +19,7 @@ fn bindgen_test_layout_Foo() { impl Clone for Foo { fn clone(&self) -> Self { *self } } +extern "C" { + #[link_name = "_ZN3FooC1Ei"] + pub fn Foo_Foo(this: *mut Foo, a: ::std::os::raw::c_int); +} diff --git a/tests/expectations/tests/gen-destructors-neg.rs b/tests/expectations/tests/gen-destructors-neg.rs index 64373d75..c7c97104 100644 --- a/tests/expectations/tests/gen-destructors-neg.rs +++ b/tests/expectations/tests/gen-destructors-neg.rs @@ -21,3 +21,7 @@ fn bindgen_test_layout_Foo() { "Alignment of field: " , stringify ! ( Foo ) , "::" , stringify ! ( bar ) )); } +extern "C" { + #[link_name = "_ZN3FooD1Ev"] + pub fn Foo_Foo_destructor(this: *mut Foo); +} diff --git a/tests/expectations/tests/inner_template_self.rs b/tests/expectations/tests/inner_template_self.rs index e1a5302f..26b35d8a 100644 --- a/tests/expectations/tests/inner_template_self.rs +++ b/tests/expectations/tests/inner_template_self.rs @@ -36,3 +36,12 @@ impl Clone for InstantiateIt { impl Default for InstantiateIt { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } +#[test] +fn __bindgen_test_layout_LinkedList_instantiation() { + assert_eq!(::std::mem::size_of::<LinkedList>() , 16usize , concat ! ( + "Size of template specialization: " , stringify ! ( LinkedList + ) )); + assert_eq!(::std::mem::align_of::<LinkedList>() , 8usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + LinkedList ) )); +} diff --git a/tests/expectations/tests/issue-372.rs b/tests/expectations/tests/issue-372.rs index 8a115924..687ae25f 100644 --- a/tests/expectations/tests/issue-372.rs +++ b/tests/expectations/tests/issue-372.rs @@ -101,4 +101,15 @@ pub mod root { impl Default for F { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } + #[test] + fn __bindgen_test_layout_C_instantiation() { + assert_eq!(::std::mem::size_of::<[u64; 33usize]>() , 264usize , concat + ! ( + "Size of template specialization: " , stringify ! ( + [u64; 33usize] ) )); + assert_eq!(::std::mem::align_of::<[u64; 33usize]>() , 8usize , concat + ! ( + "Alignment of template specialization: " , stringify ! ( + [u64; 33usize] ) )); + } } diff --git a/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs b/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs index 11d60e04..1a783f7d 100644 --- a/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs +++ b/tests/expectations/tests/issue-569-non-type-template-params-causing-layout-test-failures.rs @@ -32,7 +32,7 @@ impl Default for JS_AutoIdVector { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_JS_Base_instantiation_2() { +fn __bindgen_test_layout_JS_Base_instantiation() { assert_eq!(::std::mem::size_of::<JS_Base>() , 1usize , concat ! ( "Size of template specialization: " , stringify ! ( JS_Base ) )); diff --git a/tests/expectations/tests/issue-573-layout-test-failures.rs b/tests/expectations/tests/issue-573-layout-test-failures.rs index f82b902d..7d87aabe 100644 --- a/tests/expectations/tests/issue-573-layout-test-failures.rs +++ b/tests/expectations/tests/issue-573-layout-test-failures.rs @@ -28,3 +28,11 @@ fn bindgen_test_layout_AutoIdVector() { impl Default for AutoIdVector { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } +#[test] +fn __bindgen_test_layout_Outer_instantiation() { + assert_eq!(::std::mem::size_of::<Outer>() , 1usize , concat ! ( + "Size of template specialization: " , stringify ! ( Outer ) )); + assert_eq!(::std::mem::align_of::<Outer>() , 1usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( Outer + ) )); +} diff --git a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs index 610c0c83..a895434d 100644 --- a/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs +++ b/tests/expectations/tests/issue-574-assertion-failure-in-codegen.rs @@ -36,3 +36,11 @@ extern "C" { #[link_name = "AutoIdVector"] pub static mut AutoIdVector: _bindgen_ty_1; } +#[test] +fn __bindgen_test_layout_a_instantiation() { + assert_eq!(::std::mem::size_of::<a>() , 1usize , concat ! ( + "Size of template specialization: " , stringify ! ( a ) )); + assert_eq!(::std::mem::align_of::<a>() , 1usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( a ) + )); +} diff --git a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs index b7fa68a3..c0933df3 100644 --- a/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs +++ b/tests/expectations/tests/issue-584-stylo-template-analysis-panic.rs @@ -79,3 +79,11 @@ extern "C" { #[link_name = "_Z25Servo_Element_GetSnapshotv"] pub fn Servo_Element_GetSnapshot() -> A; } +#[test] +fn __bindgen_test_layout_f_instantiation() { + assert_eq!(::std::mem::size_of::<f>() , 1usize , concat ! ( + "Size of template specialization: " , stringify ! ( f ) )); + assert_eq!(::std::mem::align_of::<f>() , 1usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( f ) + )); +} diff --git a/tests/expectations/tests/issue-674-1.rs b/tests/expectations/tests/issue-674-1.rs index 01257c23..e8b81dd3 100644 --- a/tests/expectations/tests/issue-674-1.rs +++ b/tests/expectations/tests/issue-674-1.rs @@ -43,4 +43,13 @@ pub mod root { impl Clone for CapturingContentInfo { fn clone(&self) -> Self { *self } } + #[test] + fn __bindgen_test_layout_Maybe_instantiation() { + assert_eq!(::std::mem::size_of::<u8>() , 1usize , concat ! ( + "Size of template specialization: " , stringify ! ( u8 ) + )); + assert_eq!(::std::mem::align_of::<u8>() , 1usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( u8 + ) )); + } } diff --git a/tests/expectations/tests/issue-674-2.rs b/tests/expectations/tests/issue-674-2.rs index 819eff05..d7b0bb1c 100644 --- a/tests/expectations/tests/issue-674-2.rs +++ b/tests/expectations/tests/issue-674-2.rs @@ -66,4 +66,24 @@ pub mod root { pub struct StaticRefPtr { pub _address: u8, } + #[test] + fn __bindgen_test_layout_Rooted_instantiation() { + assert_eq!(::std::mem::size_of::<u8>() , 1usize , concat ! ( + "Size of template specialization: " , stringify ! ( u8 ) + )); + assert_eq!(::std::mem::align_of::<u8>() , 1usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( u8 + ) )); + } + #[test] + fn __bindgen_test_layout_StaticRefPtr_instantiation() { + assert_eq!(::std::mem::size_of::<root::StaticRefPtr>() , 1usize , + concat ! ( + "Size of template specialization: " , stringify ! ( + root::StaticRefPtr ) )); + assert_eq!(::std::mem::align_of::<root::StaticRefPtr>() , 1usize , + concat ! ( + "Alignment of template specialization: " , stringify ! ( + root::StaticRefPtr ) )); + } } diff --git a/tests/expectations/tests/issue-674-3.rs b/tests/expectations/tests/issue-674-3.rs index 6e915a18..8fd06b76 100644 --- a/tests/expectations/tests/issue-674-3.rs +++ b/tests/expectations/tests/issue-674-3.rs @@ -57,4 +57,13 @@ pub mod root { impl Clone for nsCSSValue { fn clone(&self) -> Self { *self } } + #[test] + fn __bindgen_test_layout_nsRefPtrHashtable_instantiation() { + assert_eq!(::std::mem::size_of::<u8>() , 1usize , concat ! ( + "Size of template specialization: " , stringify ! ( u8 ) + )); + assert_eq!(::std::mem::align_of::<u8>() , 1usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( u8 + ) )); + } } diff --git a/tests/expectations/tests/issue-691-template-parameter-virtual.rs b/tests/expectations/tests/issue-691-template-parameter-virtual.rs index b0bcb541..de43c036 100644 --- a/tests/expectations/tests/issue-691-template-parameter-virtual.rs +++ b/tests/expectations/tests/issue-691-template-parameter-virtual.rs @@ -51,7 +51,7 @@ impl Default for ServoElementSnapshotTable { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_Set_instantiation_1() { +fn __bindgen_test_layout_Set_instantiation() { assert_eq!(::std::mem::size_of::<Set>() , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( Set ) )); assert_eq!(::std::mem::align_of::<Set>() , 4usize , concat ! ( diff --git a/tests/expectations/tests/libclang-3.8/issue-769-bad-instantiation-test.rs b/tests/expectations/tests/libclang-3.8/issue-769-bad-instantiation-test.rs new file mode 100644 index 00000000..848e649f --- /dev/null +++ b/tests/expectations/tests/libclang-3.8/issue-769-bad-instantiation-test.rs @@ -0,0 +1,42 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub mod root { + #[allow(unused_imports)] + use self::super::root; + #[repr(C)] + #[derive(Debug, Copy, Clone)] + pub struct Rooted<T> { + pub member: T, + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>, + } + impl <T> Default for Rooted<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } + } + #[test] + fn __bindgen_test_layout_Rooted_instantiation() { + assert_eq!(::std::mem::size_of::<root::Rooted<::std::os::raw::c_int>>() + , 4usize , concat ! ( + "Size of template specialization: " , stringify ! ( + root::Rooted<::std::os::raw::c_int> ) )); + assert_eq!(::std::mem::align_of::<root::Rooted<::std::os::raw::c_int>>() + , 4usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + root::Rooted<::std::os::raw::c_int> ) )); + } + #[test] + fn __bindgen_test_layout_Rooted_instantiation_1() { + assert_eq!(::std::mem::size_of::<root::Rooted<::std::os::raw::c_int>>() + , 4usize , concat ! ( + "Size of template specialization: " , stringify ! ( + root::Rooted<::std::os::raw::c_int> ) )); + assert_eq!(::std::mem::align_of::<root::Rooted<::std::os::raw::c_int>>() + , 4usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + root::Rooted<::std::os::raw::c_int> ) )); + } +} diff --git a/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs index e7e9572f..6ca0d2d2 100644 --- a/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs +++ b/tests/expectations/tests/libclang-3.8/partial-specialization-and-inheritance.rs @@ -14,15 +14,6 @@ pub struct Base { pub struct Derived { pub b: bool, } -#[test] -fn __bindgen_test_layout__bindgen_ty_id_21_instantiation_1() { - assert_eq!(::std::mem::size_of::<[u32; 2usize]>() , 8usize , concat ! ( - "Size of template specialization: " , stringify ! ( - [u32; 2usize] ) )); - assert_eq!(::std::mem::align_of::<[u32; 2usize]>() , 4usize , concat ! ( - "Alignment of template specialization: " , stringify ! ( - [u32; 2usize] ) )); -} #[repr(C)] #[derive(Debug, Default, Copy)] pub struct Usage { @@ -54,3 +45,12 @@ impl Usage { __bindgen_tmp } } +#[test] +fn __bindgen_test_layout__bindgen_ty_id_21_instantiation() { + assert_eq!(::std::mem::size_of::<[u32; 2usize]>() , 8usize , concat ! ( + "Size of template specialization: " , stringify ! ( + [u32; 2usize] ) )); + assert_eq!(::std::mem::align_of::<[u32; 2usize]>() , 4usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + [u32; 2usize] ) )); +} diff --git a/tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs b/tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs new file mode 100644 index 00000000..848e649f --- /dev/null +++ b/tests/expectations/tests/libclang-3.9/issue-769-bad-instantiation-test.rs @@ -0,0 +1,42 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub mod root { + #[allow(unused_imports)] + use self::super::root; + #[repr(C)] + #[derive(Debug, Copy, Clone)] + pub struct Rooted<T> { + pub member: T, + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>, + } + impl <T> Default for Rooted<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } + } + #[test] + fn __bindgen_test_layout_Rooted_instantiation() { + assert_eq!(::std::mem::size_of::<root::Rooted<::std::os::raw::c_int>>() + , 4usize , concat ! ( + "Size of template specialization: " , stringify ! ( + root::Rooted<::std::os::raw::c_int> ) )); + assert_eq!(::std::mem::align_of::<root::Rooted<::std::os::raw::c_int>>() + , 4usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + root::Rooted<::std::os::raw::c_int> ) )); + } + #[test] + fn __bindgen_test_layout_Rooted_instantiation_1() { + assert_eq!(::std::mem::size_of::<root::Rooted<::std::os::raw::c_int>>() + , 4usize , concat ! ( + "Size of template specialization: " , stringify ! ( + root::Rooted<::std::os::raw::c_int> ) )); + assert_eq!(::std::mem::align_of::<root::Rooted<::std::os::raw::c_int>>() + , 4usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + root::Rooted<::std::os::raw::c_int> ) )); + } +} diff --git a/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs index ec399304..c0251371 100644 --- a/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs +++ b/tests/expectations/tests/libclang-3.9/partial-specialization-and-inheritance.rs @@ -14,15 +14,6 @@ pub struct Base { pub struct Derived { pub b: bool, } -#[test] -fn __bindgen_test_layout__bindgen_ty_id_20_instantiation_1() { - assert_eq!(::std::mem::size_of::<[u32; 2usize]>() , 8usize , concat ! ( - "Size of template specialization: " , stringify ! ( - [u32; 2usize] ) )); - assert_eq!(::std::mem::align_of::<[u32; 2usize]>() , 4usize , concat ! ( - "Alignment of template specialization: " , stringify ! ( - [u32; 2usize] ) )); -} #[repr(C)] #[derive(Debug, Default, Copy)] pub struct Usage { @@ -42,3 +33,12 @@ fn bindgen_test_layout_Usage() { impl Clone for Usage { fn clone(&self) -> Self { *self } } +#[test] +fn __bindgen_test_layout__bindgen_ty_id_20_instantiation() { + assert_eq!(::std::mem::size_of::<[u32; 2usize]>() , 8usize , concat ! ( + "Size of template specialization: " , stringify ! ( + [u32; 2usize] ) )); + assert_eq!(::std::mem::align_of::<[u32; 2usize]>() , 4usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + [u32; 2usize] ) )); +} diff --git a/tests/expectations/tests/libclang-4/issue-769-bad-instantiation-test.rs b/tests/expectations/tests/libclang-4/issue-769-bad-instantiation-test.rs new file mode 100644 index 00000000..f797cdff --- /dev/null +++ b/tests/expectations/tests/libclang-4/issue-769-bad-instantiation-test.rs @@ -0,0 +1,43 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + +#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)] +pub mod root { + #[allow(unused_imports)] + use self::super::root; + #[repr(C)] + #[derive(Debug, Copy, Clone)] + pub struct Rooted<T> { + pub member: T, + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>, + } + impl <T> Default for Rooted<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } + } + pub type AutoValueVector_Alias = ::std::os::raw::c_int; + #[test] + fn __bindgen_test_layout_Rooted_instantiation() { + assert_eq!(::std::mem::size_of::<root::Rooted<::std::os::raw::c_int>>() + , 4usize , concat ! ( + "Size of template specialization: " , stringify ! ( + root::Rooted<::std::os::raw::c_int> ) )); + assert_eq!(::std::mem::align_of::<root::Rooted<::std::os::raw::c_int>>() + , 4usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + root::Rooted<::std::os::raw::c_int> ) )); + } + #[test] + fn __bindgen_test_layout_Rooted_instantiation_1() { + assert_eq!(::std::mem::size_of::<root::Rooted<root::AutoValueVector_Alias>>() + , 4usize , concat ! ( + "Size of template specialization: " , stringify ! ( + root::Rooted<root::AutoValueVector_Alias> ) )); + assert_eq!(::std::mem::align_of::<root::Rooted<root::AutoValueVector_Alias>>() + , 4usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + root::Rooted<root::AutoValueVector_Alias> ) )); + } +} diff --git a/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs b/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs index ec399304..c0251371 100644 --- a/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs +++ b/tests/expectations/tests/libclang-4/partial-specialization-and-inheritance.rs @@ -14,15 +14,6 @@ pub struct Base { pub struct Derived { pub b: bool, } -#[test] -fn __bindgen_test_layout__bindgen_ty_id_20_instantiation_1() { - assert_eq!(::std::mem::size_of::<[u32; 2usize]>() , 8usize , concat ! ( - "Size of template specialization: " , stringify ! ( - [u32; 2usize] ) )); - assert_eq!(::std::mem::align_of::<[u32; 2usize]>() , 4usize , concat ! ( - "Alignment of template specialization: " , stringify ! ( - [u32; 2usize] ) )); -} #[repr(C)] #[derive(Debug, Default, Copy)] pub struct Usage { @@ -42,3 +33,12 @@ fn bindgen_test_layout_Usage() { impl Clone for Usage { fn clone(&self) -> Self { *self } } +#[test] +fn __bindgen_test_layout__bindgen_ty_id_20_instantiation() { + assert_eq!(::std::mem::size_of::<[u32; 2usize]>() , 8usize , concat ! ( + "Size of template specialization: " , stringify ! ( + [u32; 2usize] ) )); + assert_eq!(::std::mem::align_of::<[u32; 2usize]>() , 4usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + [u32; 2usize] ) )); +} diff --git a/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs b/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs index e88178cf..19e2a0dd 100644 --- a/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs +++ b/tests/expectations/tests/libclang-4/type_alias_template_specialized.rs @@ -29,3 +29,14 @@ impl Default for Rooted { } /// <div rustbindgen replaces="MaybeWrapped"></div> pub type MaybeWrapped<a> = a; +#[test] +fn __bindgen_test_layout_MaybeWrapped_instantiation() { + assert_eq!(::std::mem::size_of::<MaybeWrapped<::std::os::raw::c_int>>() , + 4usize , concat ! ( + "Size of template specialization: " , stringify ! ( + MaybeWrapped<::std::os::raw::c_int> ) )); + assert_eq!(::std::mem::align_of::<MaybeWrapped<::std::os::raw::c_int>>() , + 4usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + MaybeWrapped<::std::os::raw::c_int> ) )); +} diff --git a/tests/expectations/tests/nested_vtable.rs b/tests/expectations/tests/nested_vtable.rs index dae737d4..470fee41 100644 --- a/tests/expectations/tests/nested_vtable.rs +++ b/tests/expectations/tests/nested_vtable.rs @@ -24,6 +24,11 @@ impl Clone for nsISupports { impl Default for nsISupports { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } +extern "C" { + #[link_name = "_ZN11nsISupports14QueryInterfaceEv"] + pub fn nsISupports_QueryInterface(this: *mut ::std::os::raw::c_void) + -> *mut nsISupports; +} #[repr(C)] #[derive(Debug, Copy)] pub struct nsIRunnable { diff --git a/tests/expectations/tests/non-type-params.rs b/tests/expectations/tests/non-type-params.rs index c7ac4e85..34864993 100644 --- a/tests/expectations/tests/non-type-params.rs +++ b/tests/expectations/tests/non-type-params.rs @@ -38,7 +38,7 @@ impl Default for UsesArray { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } #[test] -fn __bindgen_test_layout_Array_instantiation_1() { +fn __bindgen_test_layout_Array_instantiation() { assert_eq!(::std::mem::size_of::<[u32; 4usize]>() , 16usize , concat ! ( "Size of template specialization: " , stringify ! ( [u32; 4usize] ) )); @@ -46,3 +46,21 @@ fn __bindgen_test_layout_Array_instantiation_1() { "Alignment of template specialization: " , stringify ! ( [u32; 4usize] ) )); } +#[test] +fn __bindgen_test_layout_Array_instantiation_1() { + assert_eq!(::std::mem::size_of::<[u8; 16usize]>() , 16usize , concat ! ( + "Size of template specialization: " , stringify ! ( + [u8; 16usize] ) )); + assert_eq!(::std::mem::align_of::<[u8; 16usize]>() , 1usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + [u8; 16usize] ) )); +} +#[test] +fn __bindgen_test_layout_Array_instantiation_2() { + assert_eq!(::std::mem::size_of::<[u8; 8usize]>() , 8usize , concat ! ( + "Size of template specialization: " , stringify ! ( + [u8; 8usize] ) )); + assert_eq!(::std::mem::align_of::<[u8; 8usize]>() , 1usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + [u8; 8usize] ) )); +} diff --git a/tests/expectations/tests/opaque_pointer.rs b/tests/expectations/tests/opaque_pointer.rs index 3462f4c3..1222b374 100644 --- a/tests/expectations/tests/opaque_pointer.rs +++ b/tests/expectations/tests/opaque_pointer.rs @@ -67,3 +67,11 @@ impl Clone for WithOpaquePtr { impl Default for WithOpaquePtr { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } +#[test] +fn __bindgen_test_layout_Opaque_instantiation() { + assert_eq!(::std::mem::size_of::<u32>() , 4usize , concat ! ( + "Size of template specialization: " , stringify ! ( u32 ) )); + assert_eq!(::std::mem::align_of::<u32>() , 4usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( u32 ) + )); +} diff --git a/tests/expectations/tests/ref_argument_array.rs b/tests/expectations/tests/ref_argument_array.rs index 25187918..dc1465c3 100644 --- a/tests/expectations/tests/ref_argument_array.rs +++ b/tests/expectations/tests/ref_argument_array.rs @@ -25,3 +25,9 @@ impl Clone for nsID { impl Default for nsID { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } +extern "C" { + #[link_name = "_ZN4nsID16ToProvidedStringERA10_c"] + pub fn nsID_ToProvidedString(this: *mut ::std::os::raw::c_void, + aDest: + *mut [::std::os::raw::c_char; 10usize]); +} diff --git a/tests/expectations/tests/replace_use.rs b/tests/expectations/tests/replace_use.rs index 0c35be56..4d313530 100644 --- a/tests/expectations/tests/replace_use.rs +++ b/tests/expectations/tests/replace_use.rs @@ -35,3 +35,12 @@ impl Clone for Test { impl Default for Test { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } +#[test] +fn __bindgen_test_layout_nsTArray_instantiation() { + assert_eq!(::std::mem::size_of::<nsTArray>() , 4usize , concat ! ( + "Size of template specialization: " , stringify ! ( nsTArray ) + )); + assert_eq!(::std::mem::align_of::<nsTArray>() , 4usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + nsTArray ) )); +} diff --git a/tests/expectations/tests/replaces_double.rs b/tests/expectations/tests/replaces_double.rs index aab511ec..b2670893 100644 --- a/tests/expectations/tests/replaces_double.rs +++ b/tests/expectations/tests/replaces_double.rs @@ -6,6 +6,16 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] +pub struct Wrapper_Wrapped<T> { + pub t: T, + pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>, +} +impl <T> Default for Wrapper_Wrapped<T> { + fn default() -> Self { unsafe { ::std::mem::zeroed() } } +} +pub type Wrapper_Type<T> = Wrapper_Wrapped<T>; +#[repr(C)] +#[derive(Debug, Copy, Clone)] pub struct Rooted<T> { pub ptr: Rooted_MaybeWrapped<T>, pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>, diff --git a/tests/expectations/tests/size_t_template.rs b/tests/expectations/tests/size_t_template.rs index 937a8c72..47e75edb 100644 --- a/tests/expectations/tests/size_t_template.rs +++ b/tests/expectations/tests/size_t_template.rs @@ -23,3 +23,12 @@ fn bindgen_test_layout_C() { impl Default for C { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } +#[test] +fn __bindgen_test_layout_Array_instantiation() { + assert_eq!(::std::mem::size_of::<[u32; 3usize]>() , 12usize , concat ! ( + "Size of template specialization: " , stringify ! ( + [u32; 3usize] ) )); + assert_eq!(::std::mem::align_of::<[u32; 3usize]>() , 4usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + [u32; 3usize] ) )); +} diff --git a/tests/expectations/tests/template-with-var.rs b/tests/expectations/tests/template-with-var.rs new file mode 100644 index 00000000..0b0a8cb6 --- /dev/null +++ b/tests/expectations/tests/template-with-var.rs @@ -0,0 +1,11 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)] + + +#[repr(C)] +#[derive(Debug, Default, Copy, Clone)] +pub struct TemplateWithVar { + pub _address: u8, +} diff --git a/tests/expectations/tests/template.rs b/tests/expectations/tests/template.rs index 5eed8c47..e666ee38 100644 --- a/tests/expectations/tests/template.rs +++ b/tests/expectations/tests/template.rs @@ -239,13 +239,8 @@ pub struct ReplacedWithoutDestructorFwd<T> { impl <T> Default for ReplacedWithoutDestructorFwd<T> { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } -#[repr(C)] -#[derive(Debug, Default, Copy, Clone)] -pub struct TemplateWithVar { - pub _address: u8, -} #[test] -fn __bindgen_test_layout_Foo_instantiation_1() { +fn __bindgen_test_layout_Foo_instantiation() { assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int>>() , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( @@ -256,7 +251,7 @@ fn __bindgen_test_layout_Foo_instantiation_1() { Foo<::std::os::raw::c_int> ) )); } #[test] -fn __bindgen_test_layout_Foo_instantiation_2() { +fn __bindgen_test_layout_Foo_instantiation_1() { assert_eq!(::std::mem::size_of::<Foo<::std::os::raw::c_int>>() , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( @@ -267,7 +262,18 @@ fn __bindgen_test_layout_Foo_instantiation_2() { Foo<::std::os::raw::c_int> ) )); } #[test] -fn __bindgen_test_layout_Rooted_instantiation_3() { +fn __bindgen_test_layout_Rooted_instantiation() { + assert_eq!(::std::mem::size_of::<Rooted<*mut ::std::os::raw::c_void>>() , + 24usize , concat ! ( + "Size of template specialization: " , stringify ! ( + Rooted<*mut ::std::os::raw::c_void> ) )); + assert_eq!(::std::mem::align_of::<Rooted<*mut ::std::os::raw::c_void>>() , + 8usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( + Rooted<*mut ::std::os::raw::c_void> ) )); +} +#[test] +fn __bindgen_test_layout_Rooted_instantiation_1() { assert_eq!(::std::mem::size_of::<Rooted<*mut ::std::os::raw::c_void>>() , 24usize , concat ! ( "Size of template specialization: " , stringify ! ( @@ -278,7 +284,7 @@ fn __bindgen_test_layout_Rooted_instantiation_3() { Rooted<*mut ::std::os::raw::c_void> ) )); } #[test] -fn __bindgen_test_layout_WithDtor_instantiation_4() { +fn __bindgen_test_layout_WithDtor_instantiation() { assert_eq!(::std::mem::size_of::<WithDtor<::std::os::raw::c_int>>() , 4usize , concat ! ( "Size of template specialization: " , stringify ! ( @@ -288,3 +294,11 @@ fn __bindgen_test_layout_WithDtor_instantiation_4() { "Alignment of template specialization: " , stringify ! ( WithDtor<::std::os::raw::c_int> ) )); } +#[test] +fn __bindgen_test_layout_Opaque_instantiation() { + assert_eq!(::std::mem::size_of::<u32>() , 4usize , concat ! ( + "Size of template specialization: " , stringify ! ( u32 ) )); + assert_eq!(::std::mem::align_of::<u32>() , 4usize , concat ! ( + "Alignment of template specialization: " , stringify ! ( u32 ) + )); +} diff --git a/tests/expectations/tests/typeref.rs b/tests/expectations/tests/typeref.rs index b5be5557..b3b75594 100644 --- a/tests/expectations/tests/typeref.rs +++ b/tests/expectations/tests/typeref.rs @@ -123,3 +123,14 @@ impl Clone for Bar { impl Default for Bar { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } +#[test] +fn __bindgen_test_layout_mozilla_StyleShapeSource_instantiation() { + assert_eq!(::std::mem::size_of::<mozilla_StyleShapeSource>() , 8usize , + concat ! ( + "Size of template specialization: " , stringify ! ( + mozilla_StyleShapeSource ) )); + assert_eq!(::std::mem::align_of::<mozilla_StyleShapeSource>() , 8usize , + concat ! ( + "Alignment of template specialization: " , stringify ! ( + mozilla_StyleShapeSource ) )); +} diff --git a/tests/expectations/tests/virtual_dtor.rs b/tests/expectations/tests/virtual_dtor.rs index 9a6ee13e..8d6d9dcd 100644 --- a/tests/expectations/tests/virtual_dtor.rs +++ b/tests/expectations/tests/virtual_dtor.rs @@ -21,3 +21,7 @@ fn bindgen_test_layout_nsSlots() { impl Default for nsSlots { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } +extern "C" { + #[link_name = "_ZN7nsSlotsD0Ev"] + pub fn nsSlots_nsSlots_destructor(this: *mut nsSlots); +} diff --git a/tests/expectations/tests/virtual_overloaded.rs b/tests/expectations/tests/virtual_overloaded.rs index a0489685..90f9d928 100644 --- a/tests/expectations/tests/virtual_overloaded.rs +++ b/tests/expectations/tests/virtual_overloaded.rs @@ -24,3 +24,13 @@ impl Clone for C { impl Default for C { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } +extern "C" { + #[link_name = "_ZN1C8do_thingEc"] + pub fn C_do_thing(this: *mut ::std::os::raw::c_void, + arg1: ::std::os::raw::c_char); +} +extern "C" { + #[link_name = "_ZN1C8do_thingEi"] + pub fn C_do_thing1(this: *mut ::std::os::raw::c_void, + arg1: ::std::os::raw::c_int); +} diff --git a/tests/expectations/tests/vtable_recursive_sig.rs b/tests/expectations/tests/vtable_recursive_sig.rs index 9a8b5be6..f112e0cc 100644 --- a/tests/expectations/tests/vtable_recursive_sig.rs +++ b/tests/expectations/tests/vtable_recursive_sig.rs @@ -42,3 +42,7 @@ impl Clone for Base { impl Default for Base { fn default() -> Self { unsafe { ::std::mem::zeroed() } } } +extern "C" { + #[link_name = "_ZN4Base9AsDerivedEv"] + pub fn Base_AsDerived(this: *mut ::std::os::raw::c_void) -> *mut Derived; +} diff --git a/tests/headers/class_nested.hpp b/tests/headers/class_nested.hpp index ccf2f895..208bc4be 100644 --- a/tests/headers/class_nested.hpp +++ b/tests/headers/class_nested.hpp @@ -31,6 +31,6 @@ class Templated { class Templated_inner { public: T* member_ptr; - void get() {} + void get(); }; }; diff --git a/tests/headers/enum_and_vtable_mangling.hpp b/tests/headers/enum_and_vtable_mangling.hpp index 3abd6a29..4c7f4d2b 100644 --- a/tests/headers/enum_and_vtable_mangling.hpp +++ b/tests/headers/enum_and_vtable_mangling.hpp @@ -7,5 +7,5 @@ enum { class C { int i; public: - virtual void match() { }; + virtual void match(); }; diff --git a/tests/headers/issue-769-bad-instantiation-test.hpp b/tests/headers/issue-769-bad-instantiation-test.hpp new file mode 100644 index 00000000..1be89a66 --- /dev/null +++ b/tests/headers/issue-769-bad-instantiation-test.hpp @@ -0,0 +1,11 @@ +// bindgen-flags: --enable-cxx-namespaces --whitelist-type Rooted + +template <typename T> +class Rooted { + T member; +}; + +class AutoValueVector : Rooted<int> { + using Alias = int; + using RootedAlias = Rooted<Alias>; +}; diff --git a/tests/headers/template-with-var.hpp b/tests/headers/template-with-var.hpp new file mode 100644 index 00000000..88f60d21 --- /dev/null +++ b/tests/headers/template-with-var.hpp @@ -0,0 +1,7 @@ +template<typename T> +class TemplateWithVar { + // We shouldn't generate bindings for this because there are potentially + // many instantiations of this variable, but we can't know which ones exist + // or don't. + static T var = 0; +}; diff --git a/tests/headers/template.hpp b/tests/headers/template.hpp index c13643c3..29a0792b 100644 --- a/tests/headers/template.hpp +++ b/tests/headers/template.hpp @@ -137,8 +137,3 @@ class ReplacedWithDestructorDeclaredAfter { T* buff; ~ReplacedWithDestructorDeclaredAfter() {}; }; - -template<typename T> -class TemplateWithVar { - static T var = 0; -}; diff --git a/tests/headers/virtual_overloaded.hpp b/tests/headers/virtual_overloaded.hpp index 8aea8a19..f5ba5ff2 100644 --- a/tests/headers/virtual_overloaded.hpp +++ b/tests/headers/virtual_overloaded.hpp @@ -1,5 +1,5 @@ class C { public: - virtual void do_thing(char) { }; - virtual void do_thing(int) { }; + virtual void do_thing(char); + virtual void do_thing(int); }; diff --git a/tests/headers/vtable_recursive_sig.hpp b/tests/headers/vtable_recursive_sig.hpp index 8729be00..8a073864 100644 --- a/tests/headers/vtable_recursive_sig.hpp +++ b/tests/headers/vtable_recursive_sig.hpp @@ -3,9 +3,9 @@ class Derived; class Base { public: - virtual Derived* AsDerived() { return nullptr; } + virtual Derived* AsDerived(); }; class Derived final : public Base { - virtual Derived* AsDerived() override { return this; } + virtual Derived* AsDerived() override; }; |