Skip to content

Commit 0bde8f9

Browse files
authored
Merge pull request #992 from google/abstract-detection-prob
Fix problem with methods beginning with their class name
2 parents bdfd45e + 6d36e79 commit 0bde8f9

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

engine/src/conversion/analysis/fun/mod.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,9 @@ impl<'a> FnAnalyzer<'a> {
915915
params = params.into_iter().skip(1).collect();
916916
param_details.remove(0);
917917
MethodKind::MakeUnique
918-
} else if let Some(constructor_suffix) = rust_name.strip_prefix(nested_type_ident) {
918+
} else if let Some(constructor_suffix) =
919+
constructor_with_suffix(&rust_name, nested_type_ident)
920+
{
919921
// It's a constructor. bindgen generates
920922
// fn Type(this: *mut Type, ...args)
921923
// We want
@@ -1968,6 +1970,19 @@ impl<'a> FnAnalyzer<'a> {
19681970
}
19691971
}
19701972

1973+
/// Attempts to determine whether this function name is a constructor, and if so,
1974+
/// returns the suffix.
1975+
fn constructor_with_suffix<'a>(rust_name: &'a str, nested_type_ident: &str) -> Option<&'a str> {
1976+
let suffix = rust_name.strip_prefix(nested_type_ident);
1977+
suffix.and_then(|suffix| {
1978+
if suffix.is_empty() || suffix.parse::<u32>().is_ok() {
1979+
Some(suffix)
1980+
} else {
1981+
None
1982+
}
1983+
})
1984+
}
1985+
19711986
fn error_context_for_method(self_ty: &QualifiedName, rust_name: &str) -> ErrorContext {
19721987
ErrorContext::new_for_method(self_ty.get_final_ident(), make_ident(rust_name))
19731988
}

engine/src/conversion/convert_error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub enum ConvertError {
101101
MethodOfNonAllowlistedType,
102102
#[error("This type is templated, so we can't generate bindings. We will instead generate bindings for each instantiation.")]
103103
MethodOfGenericType,
104-
#[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.")]
104+
#[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.")]
105105
DuplicateItemsFoundInParsing,
106106
#[error(
107107
"bindgen generated a move or copy constructor with an unexpected number of parameters."

integration-tests/tests/integration_test.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8703,6 +8703,17 @@ fn test_abstract_private() {
87038703
run_test("", hdr, rs, &["A"], &[]);
87048704
}
87058705

8706+
#[test]
8707+
fn test_abstract_issue_979() {
8708+
let hdr = indoc! {"
8709+
class Test {
8710+
virtual void TestBody() = 0;
8711+
};
8712+
"};
8713+
let rs = quote! {};
8714+
run_test("", hdr, rs, &["Test"], &[]);
8715+
}
8716+
87068717
#[test]
87078718
fn test_class_having_protected_method() {
87088719
let hdr = indoc! {"

0 commit comments

Comments
 (0)