diff --git a/engine/src/conversion/analysis/fun/mod.rs b/engine/src/conversion/analysis/fun/mod.rs index c95138e00..c6daa6dff 100644 --- a/engine/src/conversion/analysis/fun/mod.rs +++ b/engine/src/conversion/analysis/fun/mod.rs @@ -915,7 +915,9 @@ impl<'a> FnAnalyzer<'a> { params = params.into_iter().skip(1).collect(); param_details.remove(0); MethodKind::MakeUnique - } else if let Some(constructor_suffix) = rust_name.strip_prefix(nested_type_ident) { + } else if let Some(constructor_suffix) = + constructor_with_suffix(&rust_name, nested_type_ident) + { // It's a constructor. bindgen generates // fn Type(this: *mut Type, ...args) // We want @@ -1968,6 +1970,19 @@ impl<'a> FnAnalyzer<'a> { } } +/// Attempts to determine whether this function name is a constructor, and if so, +/// returns the suffix. +fn constructor_with_suffix<'a>(rust_name: &'a str, nested_type_ident: &str) -> Option<&'a str> { + let suffix = rust_name.strip_prefix(nested_type_ident); + suffix.and_then(|suffix| { + if suffix.is_empty() || suffix.parse::().is_ok() { + Some(suffix) + } else { + None + } + }) +} + fn error_context_for_method(self_ty: &QualifiedName, rust_name: &str) -> ErrorContext { ErrorContext::new_for_method(self_ty.get_final_ident(), make_ident(rust_name)) } diff --git a/engine/src/conversion/convert_error.rs b/engine/src/conversion/convert_error.rs index 09c01af66..d161b52ff 100644 --- a/engine/src/conversion/convert_error.rs +++ b/engine/src/conversion/convert_error.rs @@ -101,7 +101,7 @@ pub enum ConvertError { MethodOfNonAllowlistedType, #[error("This type is templated, so we can't generate bindings. We will instead generate bindings for each instantiation.")] MethodOfGenericType, - #[error("bindgen generated multiple different APIs (functions/types) with this name. autocxx doesn't know how to diambiguate them, so we won't generate bindings for any of them.")] + #[error("bindgen generated multiple different APIs (functions/types) with this name. autocxx doesn't know how to disambiguate them, so we won't generate bindings for any of them.")] DuplicateItemsFoundInParsing, #[error( "bindgen generated a move or copy constructor with an unexpected number of parameters." diff --git a/integration-tests/tests/integration_test.rs b/integration-tests/tests/integration_test.rs index ca01a4cf9..558de3c56 100644 --- a/integration-tests/tests/integration_test.rs +++ b/integration-tests/tests/integration_test.rs @@ -8703,6 +8703,17 @@ fn test_abstract_private() { run_test("", hdr, rs, &["A"], &[]); } +#[test] +fn test_abstract_issue_979() { + let hdr = indoc! {" + class Test { + virtual void TestBody() = 0; + }; + "}; + let rs = quote! {}; + run_test("", hdr, rs, &["Test"], &[]); +} + #[test] fn test_class_having_protected_method() { let hdr = indoc! {"