Skip to content

Commit 6a4b164

Browse files
committed
codegen: ignore aliases for decltypes we can't resolve.
We do the same for template parameters with `typename` on aliases. This is not great, but it's better than generating invalid code.
1 parent 54aba18 commit 6a4b164

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
@@ -515,6 +515,30 @@ impl CodeGenerator for Type {
515515
inner_item.to_rust_ty(ctx)
516516
};
517517

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

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)