Skip to content

Commit

Permalink
Ignore builtin template when parsing.
Browse files Browse the repository at this point in the history
This should fix rust-lang#584.
  • Loading branch information
upsuper authored and fitzgen committed Apr 4, 2017
1 parent ad01eb2 commit f25341a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/ir/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl TemplateInstantiation {
/// Parse a `TemplateInstantiation` from a clang `Type`.
pub fn from_ty(ty: &clang::Type,
ctx: &mut BindgenContext)
-> TemplateInstantiation {
-> Option<TemplateInstantiation> {
use clang_sys::*;

let template_args = ty.template_args()
Expand All @@ -100,6 +100,10 @@ impl TemplateInstantiation {
.collect()
});

if ty.declaration().is_builtin() {
return None;
}

let definition = ty.declaration()
.specialized()
.or_else(|| {
Expand All @@ -124,7 +128,7 @@ impl TemplateInstantiation {
let template_definition =
Item::from_ty_or_ref(definition.cur_type(), definition, None, ctx);

TemplateInstantiation::new(template_definition, template_args)
Some(TemplateInstantiation::new(template_definition, template_args))
}

/// Does this instantiation have a vtable?
Expand Down
5 changes: 4 additions & 1 deletion src/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,10 @@ impl Type {
(ty.template_args().is_some() &&
ty_kind != CXType_Typedef) {
// This is a template instantiation.
let inst = TemplateInstantiation::from_ty(&ty, ctx);
let inst = match TemplateInstantiation::from_ty(&ty, ctx) {
Some(inst) => inst,
None => return Err(ParseError::Continue),
};
TypeKind::TemplateInstantiation(inst)
} else {
match ty_kind {
Expand Down
7 changes: 7 additions & 0 deletions tests/expectations/tests/builtin-template.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* automatically generated by rust-bindgen */


#![allow(non_snake_case)]


pub type std_make_integer_sequence<T> = T;
6 changes: 6 additions & 0 deletions tests/headers/builtin-template.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace std {
template<class T, T... Ints>
class integer_sequence;
template<class T, T N>
using make_integer_sequence = __make_integer_seq<integer_sequence, T, N>;
}

0 comments on commit f25341a

Please sign in to comment.