Skip to content

codegen: Avoid generating wrong type for enums with unknown representation #1030

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

Merged
merged 1 commit into from
Sep 25, 2017
Merged
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
5 changes: 4 additions & 1 deletion src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2426,7 +2426,10 @@ impl CodeGenerator for Enum {
let repr =
self.repr()
.and_then(|repr| repr.try_to_rust_ty_or_opaque(ctx, &()).ok())
.unwrap_or_else(|| helpers::ast_ty::raw_type(ctx, repr_name));
.unwrap_or_else(|| {
let repr_name = ctx.rust_ident_raw(repr_name);
quote! { #repr_name }
});

let mut builder = EnumBuilder::new(
&name,
Expand Down
12 changes: 12 additions & 0 deletions tests/expectations/tests/issue-1025-unknown-enum-repr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/* automatically generated by rust-bindgen */


#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]


#[repr(C)]
#[derive(Debug, Default, Copy, Clone)]
pub struct a {
pub _address: u8,
}
pub type a__bindgen_ty_1 = i32;
4 changes: 4 additions & 0 deletions tests/headers/issue-1025-unknown-enum-repr.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

template <typename> class a {
enum {};
};