Skip to content

Commit 754d2f4

Browse files
author
bors-servo
authored
Auto merge of #712 - emilio:gcc-enums, r=fitzgen
Add a test for short enums. Closes #711.
2 parents 9bb794b + 62463b1 commit 754d2f4

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* automatically generated by rust-bindgen */
2+
3+
4+
#![allow(non_snake_case)]
5+
6+
7+
#[repr(u8)]
8+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
9+
pub enum one_byte_t { SOME_VALUE = 1, }
10+
#[repr(u16)]
11+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
12+
pub enum two_byte_t { SOME_OTHER_VALUE = 256, }
13+
#[repr(u32)]
14+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
15+
pub enum four_byte_t { SOME_BIGGER_VALUE = 16777216, }

tests/headers/short-enums.hpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// bindgen-flags: -- -std=c++11 -fshort-enums
2+
3+
typedef enum {
4+
SOME_VALUE = 0x1,
5+
} one_byte_t;
6+
7+
static_assert(sizeof(one_byte_t) == 1, "Short enums should work");
8+
9+
typedef enum {
10+
SOME_OTHER_VALUE = 0x100,
11+
} two_byte_t;
12+
13+
static_assert(sizeof(two_byte_t) == 2, "");
14+
15+
typedef enum {
16+
SOME_BIGGER_VALUE = 0x1000000,
17+
} four_byte_t;
18+
19+
static_assert(sizeof(four_byte_t) == 4, "");

0 commit comments

Comments
 (0)