Undefined/redefined C macro keeps old value
Input C/C++ Header
#define A 1
#define B 2
#undef A
#define A 2
#undef B
#define B 1
Bindgen Invocation
bindgen::Builder::default()
.header("input.h")
.generate()
.unwrap()
Actual Results
/* automatically generated by rust-bindgen 0.69.2 */
pub const A: u32 = 1;
pub const B: u32 = 2;
Expected Results
/* automatically generated by rust-bindgen 0.69.2 */
pub const A: u32 = 2;
pub const B: u32 = 1;
Is it? It's hard to say what version of a redefined macro should be generated IMO... But yeah, I guess the latest one seems reasonable. My bindgen/ir/var.rs is what handles this, see previously_defined.
I think bindgen should generate whatever later code (i.e. C code including the header) would see. In other words, it can also happen that nothing should be generated, e.g. for:
#define A 1
#undef A
I would expect no A constant in the output.
If there is a use case for people needing something else (e.g. always generate A, or an "intermediate" version of A), then I guess bindgen could potentially offer the feature of providing all of them under versioned names (A_<n>, or A_<line> or similar).