Skip to content

Commit 4461d93

Browse files
committed
Fix u16 enum repr.
A previous change assumed we could always treat u16 as char16_t, since it appeared only to be used to represent char16_t. It turns out it's also used for the representation of 16-bit-wide enums, so we need to keep track of the distinction between these two types as they travel through autocxx-bindgen. Relates to google/autocxx#1214
1 parent a7aabe9 commit 4461d93

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

bindgen/codegen/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3941,9 +3941,7 @@ impl TryToRustTy for Type {
39413941
IntKind::I8 => Ok(quote! { i8 }.into()),
39423942
IntKind::U8 => Ok(quote! { u8 }.into()),
39433943
IntKind::I16 => Ok(quote! { i16 }.into()),
3944-
IntKind::U16 if ctx.options().use_distinct_char16_t => {
3945-
Ok(quote! { c_char16_t }.into())
3946-
}
3944+
IntKind::Char16 => Ok(quote! { c_char16_t }.into()),
39473945
IntKind::U16 => Ok(quote! { u16 }.into()),
39483946
IntKind::I32 => Ok(quote! { i32 }.into()),
39493947
IntKind::U32 => Ok(quote! { u32 }.into()),

bindgen/ir/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,6 +1947,7 @@ If you encounter an error missing from this list, please file an issue or a PR!"
19471947
CXType_Short => TypeKind::Int(IntKind::Short),
19481948
CXType_UShort => TypeKind::Int(IntKind::UShort),
19491949
CXType_WChar => TypeKind::Int(IntKind::WChar),
1950+
CXType_Char16 if self.options().use_distinct_char16_t => TypeKind::Int(IntKind::Char16),
19501951
CXType_Char16 => TypeKind::Int(IntKind::U16),
19511952
CXType_Char32 => TypeKind::Int(IntKind::U32),
19521953
CXType_Long => TypeKind::Int(IntKind::Long),

bindgen/ir/int.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,12 @@ pub enum IntKind {
5454
/// A 16-bit signed integer.
5555
I16,
5656

57-
/// Either a `char16_t` or a `wchar_t`.
57+
/// A 16-bit integer, used only for enum size representation.
5858
U16,
5959

60+
/// Either a `char16_t` or a `wchar_t`.
61+
Char16,
62+
6063
/// A 32-bit signed integer.
6164
I32,
6265

@@ -93,7 +96,7 @@ impl IntKind {
9396
// TODO(emilio): wchar_t can in theory be signed, but we have no way
9497
// to know whether it is or not right now (unlike char, there's no
9598
// WChar_S / WChar_U).
96-
Bool | UChar | UShort | UInt | ULong | ULongLong | U8 | U16 |
99+
Bool | UChar | UShort | UInt | ULong | ULongLong | U8 | U16 | Char16 |
97100
WChar | U32 | U64 | U128 => false,
98101

99102
SChar | Short | Int | Long | LongLong | I8 | I16 | I32 | I64 |
@@ -112,7 +115,7 @@ impl IntKind {
112115
use self::IntKind::*;
113116
Some(match *self {
114117
Bool | UChar | SChar | U8 | I8 | Char { .. } => 1,
115-
U16 | I16 => 2,
118+
U16 | I16 | Char16 => 2,
116119
U32 | I32 => 4,
117120
U64 | I64 => 8,
118121
I128 | U128 => 16,

0 commit comments

Comments
 (0)