Skip to content

Commit ce5d5c8

Browse files
author
bors-servo
authored
Auto merge of #367 - emilio:auto-redux, r=upsuper
ir: More generic handling of non-deductible auto types. Also, merge auto-related tests in `auto.hpp`. r? @upsuper
2 parents ba1cb0a + f7a328a commit ce5d5c8

File tree

7 files changed

+43
-29
lines changed

7 files changed

+43
-29
lines changed

libbindgen/src/ir/comp.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -748,9 +748,9 @@ impl CompInfo {
748748
return CXChildVisit_Continue;
749749
}
750750

751-
let item = Item::parse(cur, Some(potential_id), ctx)
752-
.expect("VarDecl");
753-
ci.inner_vars.push(item);
751+
if let Ok(item) = Item::parse(cur, Some(potential_id), ctx) {
752+
ci.inner_vars.push(item);
753+
}
754754
}
755755
// Intentionally not handled
756756
CXCursor_CXXAccessSpecifier |

libbindgen/src/ir/ty.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,8 +776,11 @@ impl Type {
776776
}
777777
}
778778
CXType_Auto => {
779-
// We don't want to blow the stack.
780-
assert!(canonical_ty != *ty, "Couldn't find deduced type");
779+
if canonical_ty == *ty {
780+
debug!("Couldn't find deduced type: {:?}", ty);
781+
return Err(ParseError::Continue);
782+
}
783+
781784
return Self::from_clang_ty(potential_id,
782785
&canonical_ty,
783786
location,

libbindgen/src/ir/var.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,15 @@ impl ClangSubItemParser for Var {
186186
// XXX this is redundant, remove!
187187
let is_const = ty.is_const();
188188

189-
let ty = Item::from_ty(&ty, Some(cursor), None, ctx)
190-
.expect("Unable to resolve constant type?");
189+
let ty = match Item::from_ty(&ty, Some(cursor), None, ctx) {
190+
Ok(ty) => ty,
191+
Err(e) => {
192+
assert_eq!(ty.kind(), CXType_Auto,
193+
"Couldn't resolve constant type, and it \
194+
wasn't an nondeductible auto type!");
195+
return Err(e);
196+
}
197+
};
191198

192199
// Note: Ty might not be totally resolved yet, see
193200
// tests/headers/inner_const.hpp

libbindgen/tests/expectations/tests/auto.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
pub struct Foo {
1010
pub _address: u8,
1111
}
12-
pub const Foo_kBar: bool = true;
12+
pub const Foo_kFoo: bool = true;
1313
#[test]
1414
fn bindgen_test_layout_Foo() {
1515
assert_eq!(::std::mem::size_of::<Foo>() , 1usize);
@@ -18,3 +18,13 @@ fn bindgen_test_layout_Foo() {
1818
impl Clone for Foo {
1919
fn clone(&self) -> Self { *self }
2020
}
21+
#[repr(C)]
22+
#[derive(Debug, Copy, Clone)]
23+
pub struct Bar<T> {
24+
pub _address: u8,
25+
pub _phantom_0: ::std::marker::PhantomData<T>,
26+
}
27+
extern "C" {
28+
#[link_name = "_Z5Test2v"]
29+
pub fn Test2() -> ::std::os::raw::c_uint;
30+
}

libbindgen/tests/expectations/tests/template_function_with_auto.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

libbindgen/tests/headers/auto.hpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1-
// bindgen-flags: -- -std=c++11
1+
// bindgen-flags: -- -std=c++14
22
// bindgen-unstable
33

44
class Foo {
5-
static constexpr auto kBar = 2 == 2;
5+
static constexpr auto kFoo = 2 == 2;
66
};
7+
8+
template<typename T>
9+
class Bar {
10+
static const constexpr auto kBar = T(1);
11+
};
12+
13+
template<typename T> auto Test1() {
14+
return T(1);
15+
}
16+
17+
auto Test2() {
18+
return Test1<unsigned int>();
19+
}

libbindgen/tests/headers/template_function_with_auto.hpp

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)