diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2016-12-15 18:02:49 +0100 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2016-12-15 18:02:49 +0100 |
commit | 1129431b00cb3ab76dce0ab8b2956d319d939f3a (patch) | |
tree | b4c6e649f43f50d692ad2b203ce31c5eb784175e | |
parent | 59987f142bbd97e44437532a640eb66c4d3a3e52 (diff) |
ir: Don't parse constructors twice.
-rw-r--r-- | libbindgen/src/ir/function.rs | 7 | ||||
-rw-r--r-- | libbindgen/tests/expectations/tests/constructor-tp.rs | 37 | ||||
-rw-r--r-- | libbindgen/tests/headers/constructor-tp.hpp | 19 |
3 files changed, 62 insertions, 1 deletions
diff --git a/libbindgen/src/ir/function.rs b/libbindgen/src/ir/function.rs index 76576dbd..1b930ac3 100644 --- a/libbindgen/src/ir/function.rs +++ b/libbindgen/src/ir/function.rs @@ -186,8 +186,13 @@ impl FunctionSig { }; let is_method = cursor.kind() == CXCursor_CXXMethod; + let is_constructor = cursor.kind() == CXCursor_Constructor; + if is_constructor && cursor.lexical_parent() != cursor.semantic_parent() { + // Only parse constructors once. + return Err(ParseError::Continue); + } - if is_method || cursor.kind() == CXCursor_Constructor { + if is_method || is_constructor { let is_const = is_method && cursor.method_is_const(); let is_virtual = is_method && cursor.method_is_virtual(); let is_static = is_method && cursor.method_is_static(); diff --git a/libbindgen/tests/expectations/tests/constructor-tp.rs b/libbindgen/tests/expectations/tests/constructor-tp.rs new file mode 100644 index 00000000..50220489 --- /dev/null +++ b/libbindgen/tests/expectations/tests/constructor-tp.rs @@ -0,0 +1,37 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct Foo<T> { + pub _address: u8, + pub _phantom_0: ::std::marker::PhantomData<T>, +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct Bar { + pub _address: u8, +} +#[test] +fn bindgen_test_layout_Bar() { + assert_eq!(::std::mem::size_of::<Bar>() , 1usize); + assert_eq!(::std::mem::align_of::<Bar>() , 1usize); +} +extern "C" { + #[link_name = "_ZN3BarC1Ev"] + pub fn Bar_Bar(this: *mut Bar); +} +impl Clone for Bar { + fn clone(&self) -> Self { *self } +} +impl Bar { + #[inline] + pub unsafe fn new() -> Self { + let mut __bindgen_tmp = ::std::mem::uninitialized(); + Bar_Bar(&mut __bindgen_tmp); + __bindgen_tmp + } +} diff --git a/libbindgen/tests/headers/constructor-tp.hpp b/libbindgen/tests/headers/constructor-tp.hpp new file mode 100644 index 00000000..7a420413 --- /dev/null +++ b/libbindgen/tests/headers/constructor-tp.hpp @@ -0,0 +1,19 @@ + +template<typename T> +class Foo { +public: + Foo(); +}; + +class Bar { +public: + Bar(); +}; + +template<typename T> +Foo<T>::Foo() { +} + +inline +Bar::Bar() { +} |