Skip to content

Commit 721d920

Browse files
committed
codegen: Do the same workaround we do for template parameters with typename on aliases for decltypes we can't resolve.
1 parent 4025495 commit 721d920

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

libbindgen/src/codegen/mod.rs

+24
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,30 @@ impl CodeGenerator for Type {
516516
inner_item.to_rust_ty(ctx)
517517
};
518518

519+
{
520+
// FIXME(emilio): This is a workaround to avoid generating
521+
// incorrect type aliases because of types that we haven't
522+
// been able to resolve (because, eg, they depend on a
523+
// template parameter).
524+
//
525+
// It's kind of a shame not generating them even when they
526+
// could be referenced, but we already do the same for items
527+
// with invalid template parameters, and at least this way
528+
// they can be replaced, instead of generating plain invalid
529+
// code.
530+
let inner_canon_type =
531+
inner_item.expect_type().canonical_type(ctx);
532+
if inner_canon_type.is_named() &&
533+
inner_canon_type.name().map_or(false, |name| {
534+
name.contains("decltype ") ||
535+
name.contains("decltype(")
536+
}) {
537+
warn!("Item contained `decltype`d type, skipping: \
538+
{:?}, {:?}", item, inner_item);
539+
return;
540+
}
541+
}
542+
519543
let rust_name = ctx.rust_ident(&name);
520544
let mut typedef = aster::AstBuilder::new().item().pub_();
521545

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
#[repr(C)]
8+
#[derive(Debug, Copy, Clone)]
9+
pub struct std_allocator_traits<_Alloc> {
10+
pub _address: u8,
11+
pub _phantom_0: ::std::marker::PhantomData<_Alloc>,
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// bindgen-flags: -- -std=c++11
2+
3+
namespace std {
4+
template<typename _Alloc> struct allocator_traits {
5+
typedef decltype ( _S_size_type_helper ( ( _Alloc * ) 0 ) ) __size_type;
6+
};
7+
}

0 commit comments

Comments
 (0)