summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ir/var.rs12
-rw-r--r--tests/expectations/tests/macro-redef.rs9
-rw-r--r--tests/headers/macro-redef.h5
3 files changed, 21 insertions, 5 deletions
diff --git a/src/ir/var.rs b/src/ir/var.rs
index 0e7df618..1c7b2028 100644
--- a/src/ir/var.rs
+++ b/src/ir/var.rs
@@ -87,17 +87,19 @@ impl ClangSubItemParser for Var {
assert!(!id.is_empty(), "Empty macro name?");
- if ctx.parsed_macro(&id) {
- let name = String::from_utf8(id).unwrap();
- warn!("Duplicated macro definition: {}", name);
- return Err(ParseError::Continue);
- }
+ let previously_defined = ctx.parsed_macro(&id);
// NB: It's important to "note" the macro even if the result is
// not an integer, otherwise we might loose other kind of
// derived macros.
ctx.note_parsed_macro(id.clone(), value.clone());
+ if previously_defined {
+ let name = String::from_utf8(id).unwrap();
+ warn!("Duplicated macro definition: {}", name);
+ return Err(ParseError::Continue);
+ }
+
// NOTE: Unwrapping, here and above, is safe, because the
// identifier of a token comes straight from clang, and we
// enforce utf8 there, so we should have already panicked at
diff --git a/tests/expectations/tests/macro-redef.rs b/tests/expectations/tests/macro-redef.rs
new file mode 100644
index 00000000..881a44ae
--- /dev/null
+++ b/tests/expectations/tests/macro-redef.rs
@@ -0,0 +1,9 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(non_snake_case)]
+
+
+pub const FOO: ::std::os::raw::c_uint = 4;
+pub const BAR: ::std::os::raw::c_uint = 5;
+pub const BAZ: ::std::os::raw::c_uint = 6;
diff --git a/tests/headers/macro-redef.h b/tests/headers/macro-redef.h
new file mode 100644
index 00000000..0180d2ab
--- /dev/null
+++ b/tests/headers/macro-redef.h
@@ -0,0 +1,5 @@
+#define FOO 4
+#define BAR (1 + FOO)
+#undef FOO
+#define FOO 5
+#define BAZ (1 + FOO)