Skip to content

ir: Don't assume template instantiation argument with vtable implies vtable #692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 8, 2017
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
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ name = "bindgen"
readme = "README.md"
repository = "https://github.com/servo/rust-bindgen"
documentation = "https://docs.rs/bindgen"
version = "0.24.0"
version = "0.24.1"
build = "build.rs"

exclude = [
Expand Down
3 changes: 1 addition & 2 deletions src/ir/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,7 @@ impl TemplateInstantiation {

/// Does this instantiation have a vtable?
pub fn has_vtable(&self, ctx: &BindgenContext) -> bool {
ctx.resolve_type(self.definition).has_vtable(ctx) ||
self.args.iter().any(|arg| ctx.resolve_type(*arg).has_vtable(ctx))
ctx.resolve_type(self.definition).has_vtable(ctx)
}

/// Does this instantiation have a destructor?
Expand Down
60 changes: 60 additions & 0 deletions tests/expectations/tests/issue-691-template-parameter-virtual.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/* automatically generated by rust-bindgen */


#![allow(non_snake_case)]


#[repr(C)]
pub struct VirtualMethods__bindgen_vtable(::std::os::raw::c_void);
#[repr(C)]
#[derive(Debug, Copy)]
pub struct VirtualMethods {
pub vtable_: *const VirtualMethods__bindgen_vtable,
}
#[test]
fn bindgen_test_layout_VirtualMethods() {
assert_eq!(::std::mem::size_of::<VirtualMethods>() , 8usize , concat ! (
"Size of: " , stringify ! ( VirtualMethods ) ));
assert_eq! (::std::mem::align_of::<VirtualMethods>() , 8usize , concat ! (
"Alignment of " , stringify ! ( VirtualMethods ) ));
}
impl Clone for VirtualMethods {
fn clone(&self) -> Self { *self }
}
impl Default for VirtualMethods {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct Set {
pub bar: ::std::os::raw::c_int,
}
#[repr(C)]
#[derive(Debug, Copy)]
pub struct ServoElementSnapshotTable {
pub _base: Set,
}
#[test]
fn bindgen_test_layout_ServoElementSnapshotTable() {
assert_eq!(::std::mem::size_of::<ServoElementSnapshotTable>() , 4usize ,
concat ! (
"Size of: " , stringify ! ( ServoElementSnapshotTable ) ));
assert_eq! (::std::mem::align_of::<ServoElementSnapshotTable>() , 4usize ,
concat ! (
"Alignment of " , stringify ! ( ServoElementSnapshotTable )
));
}
impl Clone for ServoElementSnapshotTable {
fn clone(&self) -> Self { *self }
}
impl Default for ServoElementSnapshotTable {
fn default() -> Self { unsafe { ::std::mem::zeroed() } }
}
#[test]
fn __bindgen_test_layout_Set_instantiation_13() {
assert_eq!(::std::mem::size_of::<Set>() , 4usize , concat ! (
"Size of template specialization: " , stringify ! ( Set ) ));
assert_eq!(::std::mem::align_of::<Set>() , 4usize , concat ! (
"Alignment of template specialization: " , stringify ! ( Set )
));
}
12 changes: 12 additions & 0 deletions tests/headers/issue-691-template-parameter-virtual.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class VirtualMethods {
virtual void foo();
};

template<typename K>
class Set {
int bar;
};

class ServoElementSnapshotTable
: public Set<VirtualMethods>
{};