summaryrefslogtreecommitdiff
path: root/libbindgen/src/codegen/mod.rs
diff options
context:
space:
mode:
authorArtem Biryukov <impowski@protonmail.ch>2016-11-16 17:40:06 +0300
committerArtem Biryukov <impowski@protonmail.ch>2016-11-20 11:52:25 +0300
commit515ef38574845b0fbac1bea72269b44bd0642b75 (patch)
tree9e52c25b3dab444fc87f57710ef57edea2a6290d /libbindgen/src/codegen/mod.rs
parent1a8a2ac1c325487be455b434749c0b246f27e242 (diff)
First steps to fix issue #57
Diffstat (limited to 'libbindgen/src/codegen/mod.rs')
-rw-r--r--libbindgen/src/codegen/mod.rs26
1 files changed, 24 insertions, 2 deletions
diff --git a/libbindgen/src/codegen/mod.rs b/libbindgen/src/codegen/mod.rs
index 6c8a36f7..8b54ab00 100644
--- a/libbindgen/src/codegen/mod.rs
+++ b/libbindgen/src/codegen/mod.rs
@@ -656,8 +656,30 @@ impl CodeGenerator for CompInfo {
//
// TODO: Generate layout tests for template specializations, yay!
if self.has_non_type_template_params() ||
- self.is_template_specialization() {
- return;
+ self.is_template_specialization() {
+ let layout = item.kind().expect_type().layout(ctx);
+ let canonical_name = item.canonical_name(ctx);
+
+ if let Some(layout) = layout {
+ let fn_name = format!("bindgen_test_layout_template_{}", canonical_name);
+ let fn_name = ctx.rust_ident_raw(&fn_name);
+ let ident = item.to_rust_ty(ctx);
+ let prefix = ctx.trait_prefix();
+ let size_of_expr = quote_expr!(ctx.ext_cx(),
+ ::$prefix::mem::size_of::<$ident>());
+ let align_of_expr = quote_expr!(ctx.ext_cx(),
+ ::$prefix::mem::align_of::<$ident>());
+ let size = layout.size;
+ let align = layout.align;
+ let item = quote_item!(ctx.ext_cx(),
+ #[test]
+ fn $fn_name() {
+ assert_eq!($size_of_expr, $size);
+ assert_eq!($align_of_expr, $align);
+ }).unwrap();
+ result.push(item);
+ }
+ return;
}
let applicable_template_args = item.applicable_template_args(ctx);