From f25341ab4df08bef4cb52c292e64e1099c668ea9 Mon Sep 17 00:00:00 2001 From: Xidorn Quan Date: Mon, 20 Mar 2017 17:18:34 +1100 Subject: [PATCH] Ignore builtin template when parsing. This should fix #584. --- src/ir/template.rs | 8 ++++++-- src/ir/ty.rs | 5 ++++- tests/expectations/tests/builtin-template.rs | 7 +++++++ tests/headers/builtin-template.hpp | 6 ++++++ 4 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 tests/expectations/tests/builtin-template.rs create mode 100644 tests/headers/builtin-template.hpp diff --git a/src/ir/template.rs b/src/ir/template.rs index 627ac225f8..4022b36644 100644 --- a/src/ir/template.rs +++ b/src/ir/template.rs @@ -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 { use clang_sys::*; let template_args = ty.template_args() @@ -100,6 +100,10 @@ impl TemplateInstantiation { .collect() }); + if ty.declaration().is_builtin() { + return None; + } + let definition = ty.declaration() .specialized() .or_else(|| { @@ -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? diff --git a/src/ir/ty.rs b/src/ir/ty.rs index 594e4c03e4..20d51d3f52 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -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 { diff --git a/tests/expectations/tests/builtin-template.rs b/tests/expectations/tests/builtin-template.rs new file mode 100644 index 0000000000..1215f9dab7 --- /dev/null +++ b/tests/expectations/tests/builtin-template.rs @@ -0,0 +1,7 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +pub type std_make_integer_sequence = T; diff --git a/tests/headers/builtin-template.hpp b/tests/headers/builtin-template.hpp new file mode 100644 index 0000000000..4e64ebc779 --- /dev/null +++ b/tests/headers/builtin-template.hpp @@ -0,0 +1,6 @@ +namespace std { +template +class integer_sequence; +template +using make_integer_sequence = __make_integer_seq; +}