Skip to content

Ignore builtin template when parsing #594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -993,7 +993,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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be more appropriate to return an opaque type here, rather than continue on to who-knows-what that we know isn't quite right.

};
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>;
}