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
don't emit #[repr(align(0))] for empty unions #1595
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1078,8 +1078,13 @@ impl CompInfo { | |
return None; | ||
} | ||
|
||
if self.kind == CompKind::Union && self.fields().len() == 0 { | ||
return None; | ||
} | ||
|
||
let mut max_size = 0; | ||
let mut max_align = 0; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead, we should probably return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. returning header_issue_493_1_0_hpp There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds good, thanks :) |
||
// Don't allow align(0) | ||
let mut max_align = 1; | ||
for field in self.fields() { | ||
let field_layout = field.layout(ctx); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* automatically generated by rust-bindgen */ | ||
|
||
#![allow( | ||
dead_code, | ||
non_snake_case, | ||
non_camel_case_types, | ||
non_upper_case_globals | ||
)] | ||
|
||
#[repr(C)] | ||
#[derive(Copy, Clone)] | ||
pub union a__bindgen_ty_1 { | ||
pub _address: u8, | ||
} | ||
impl Default for a__bindgen_ty_1 { | ||
fn default() -> Self { | ||
unsafe { ::std::mem::zeroed() } | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// bindgen-flags: --opaque-type "*" | ||
|
||
template <int> class a { | ||
union {}; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: No need for
self.kind == CompKind::Union
, since we early-return for struts before.Also,
self.fields().is_empty()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed