From b1ee9dae53d04992f2edef3264e9fd090ac80a17 Mon Sep 17 00:00:00 2001 From: Alex Badics Date: Wed, 7 Jun 2023 15:47:33 +0200 Subject: [PATCH 1/2] Add test for nested anonymous enums --- integration-tests/tests/integration_test.rs | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/integration-tests/tests/integration_test.rs b/integration-tests/tests/integration_test.rs index 00b7153cb..3c8af67f7 100644 --- a/integration-tests/tests/integration_test.rs +++ b/integration-tests/tests/integration_test.rs @@ -4239,6 +4239,29 @@ fn test_abstract_nested_type() { run_test("", hdr, rs, &["take_A_B", "N::A_B"], &[]); } +#[test] +fn test_nested_unnamed_enum() { + let hdr = indoc! {" + namespace N { + struct A { + enum { + LOW_VAL = 1, + HIGH_VAL = 1000, + }; + }; + } + "}; + run_test_ex( + "", + hdr, + quote! {}, + quote! { generate_ns!("N")}, + None, + None, + None, + ); +} + #[test] fn test_nested_type_constructor() { let hdr = indoc! {" From 718c50d304674ccba7c3a65512868f8280ab9d55 Mon Sep 17 00:00:00 2001 From: Alex Badics Date: Wed, 7 Jun 2023 15:48:16 +0200 Subject: [PATCH 2/2] Crude workaround for nested anonymous enums bug Fixes #1289 --- engine/src/conversion/parse/parse_bindgen.rs | 21 ++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/engine/src/conversion/parse/parse_bindgen.rs b/engine/src/conversion/parse/parse_bindgen.rs index b0205053b..39af9f08c 100644 --- a/engine/src/conversion/parse/parse_bindgen.rs +++ b/engine/src/conversion/parse/parse_bindgen.rs @@ -352,10 +352,23 @@ impl<'a> ParseBindgen<'a> { } Item::Const(const_item) => { let annotations = BindgenSemanticAttributes::new(&const_item.attrs); - self.apis.push(UnanalyzedApi::Const { - name: api_name(ns, const_item.ident.clone(), &annotations), - const_item, - }); + // Bindgen generates const expressions for nested unnamed enums, + // but autcxx will refuse to expand those enums, making these consts + // invalid. + let mut enum_type_name_valid = true; + if let Type::Path(p) = &*const_item.ty { + if let Some(p) = &p.path.segments.last() { + if validate_ident_ok_for_cxx(&p.ident.to_string()).is_err() { + enum_type_name_valid = false; + } + } + } + if enum_type_name_valid { + self.apis.push(UnanalyzedApi::Const { + name: api_name(ns, const_item.ident.clone(), &annotations), + const_item, + }); + } Ok(()) } Item::Type(ity) => {