diff options
-rw-r--r-- | libbindgen/Cargo.toml | 2 | ||||
-rw-r--r-- | libbindgen/src/ir/comp.rs | 6 | ||||
-rw-r--r-- | libbindgen/src/ir/function.rs | 5 | ||||
-rw-r--r-- | libbindgen/src/ir/ty.rs | 7 | ||||
-rw-r--r-- | libbindgen/src/ir/var.rs | 11 | ||||
-rw-r--r-- | libbindgen/tests/expectations/tests/auto.rs | 12 | ||||
-rw-r--r-- | libbindgen/tests/headers/auto.hpp | 17 |
7 files changed, 49 insertions, 11 deletions
diff --git a/libbindgen/Cargo.toml b/libbindgen/Cargo.toml index e6e9a5db..dfaba98b 100644 --- a/libbindgen/Cargo.toml +++ b/libbindgen/Cargo.toml @@ -12,7 +12,7 @@ license = "BSD-3-Clause" name = "libbindgen" readme = "README.md" repository = "https://github.com/servo/rust-bindgen" -version = "0.1.4" +version = "0.1.5" workspace = ".." [dev-dependencies] diff --git a/libbindgen/src/ir/comp.rs b/libbindgen/src/ir/comp.rs index 1c69e618..ea3850cc 100644 --- a/libbindgen/src/ir/comp.rs +++ b/libbindgen/src/ir/comp.rs @@ -748,9 +748,9 @@ impl CompInfo { return CXChildVisit_Continue; } - let item = Item::parse(cur, Some(potential_id), ctx) - .expect("VarDecl"); - ci.inner_vars.push(item); + if let Ok(item) = Item::parse(cur, Some(potential_id), ctx) { + ci.inner_vars.push(item); + } } // Intentionally not handled CXCursor_CXXAccessSpecifier | diff --git a/libbindgen/src/ir/function.rs b/libbindgen/src/ir/function.rs index 7aed3d7e..88ab861d 100644 --- a/libbindgen/src/ir/function.rs +++ b/libbindgen/src/ir/function.rs @@ -134,6 +134,11 @@ impl FunctionSig { use clang_sys::*; debug!("FunctionSig::from_ty {:?} {:?}", ty, cursor); + // Skip function templates + if cursor.kind() == CXCursor_FunctionTemplate { + return Err(ParseError::Continue); + } + // Don't parse operatorxx functions in C++ let spelling = cursor.spelling(); if spelling.starts_with("operator") { diff --git a/libbindgen/src/ir/ty.rs b/libbindgen/src/ir/ty.rs index b04afeb6..6859b753 100644 --- a/libbindgen/src/ir/ty.rs +++ b/libbindgen/src/ir/ty.rs @@ -776,8 +776,11 @@ impl Type { } } CXType_Auto => { - // We don't want to blow the stack. - assert!(canonical_ty != *ty, "Couldn't find deduced type"); + if canonical_ty == *ty { + debug!("Couldn't find deduced type: {:?}", ty); + return Err(ParseError::Continue); + } + return Self::from_clang_ty(potential_id, &canonical_ty, location, diff --git a/libbindgen/src/ir/var.rs b/libbindgen/src/ir/var.rs index 518141c6..d9160eca 100644 --- a/libbindgen/src/ir/var.rs +++ b/libbindgen/src/ir/var.rs @@ -186,8 +186,15 @@ impl ClangSubItemParser for Var { // XXX this is redundant, remove! let is_const = ty.is_const(); - let ty = Item::from_ty(&ty, Some(cursor), None, ctx) - .expect("Unable to resolve constant type?"); + let ty = match Item::from_ty(&ty, Some(cursor), None, ctx) { + Ok(ty) => ty, + Err(e) => { + assert_eq!(ty.kind(), CXType_Auto, + "Couldn't resolve constant type, and it \ + wasn't an nondeductible auto type!"); + return Err(e); + } + }; // Note: Ty might not be totally resolved yet, see // tests/headers/inner_const.hpp diff --git a/libbindgen/tests/expectations/tests/auto.rs b/libbindgen/tests/expectations/tests/auto.rs index e35f5ed2..6224e807 100644 --- a/libbindgen/tests/expectations/tests/auto.rs +++ b/libbindgen/tests/expectations/tests/auto.rs @@ -9,7 +9,7 @@ pub struct Foo { pub _address: u8, } -pub const Foo_kBar: bool = true; +pub const Foo_kFoo: bool = true; #[test] fn bindgen_test_layout_Foo() { assert_eq!(::std::mem::size_of::<Foo>() , 1usize); @@ -18,3 +18,13 @@ fn bindgen_test_layout_Foo() { impl Clone for Foo { fn clone(&self) -> Self { *self } } +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct Bar<T> { + pub _address: u8, + pub _phantom_0: ::std::marker::PhantomData<T>, +} +extern "C" { + #[link_name = "_Z5Test2v"] + pub fn Test2() -> ::std::os::raw::c_uint; +} diff --git a/libbindgen/tests/headers/auto.hpp b/libbindgen/tests/headers/auto.hpp index 64025295..b5f6d5f3 100644 --- a/libbindgen/tests/headers/auto.hpp +++ b/libbindgen/tests/headers/auto.hpp @@ -1,6 +1,19 @@ -// bindgen-flags: -- -std=c++11 +// bindgen-flags: -- -std=c++14 // bindgen-unstable class Foo { - static constexpr auto kBar = 2 == 2; + static constexpr auto kFoo = 2 == 2; }; + +template<typename T> +class Bar { + static const constexpr auto kBar = T(1); +}; + +template<typename T> auto Test1() { + return T(1); +} + +auto Test2() { + return Test1<unsigned int>(); +} |