Skip to content

Commit

Permalink
Merge pull request #1423 from google/fix-concrete-typedef-dep
Browse files Browse the repository at this point in the history
Fix concrete typedef dep
  • Loading branch information
adetaylor authored Jan 8, 2025
2 parents 597d6de + d770c8b commit 0ec7b78
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
5 changes: 4 additions & 1 deletion engine/src/conversion/analysis/type_converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,10 @@ impl<'a> TypeConverter<'a> {
}
let (new_tn, api) = self.get_templated_typename(&Type::Path(typ))?;
extra_apis.extend(api.into_iter());
deps.remove(&tn);
// Although it's tempting to remove the dep on the original type,
// this means we wouldn't spot cases where the original type can't
// be represented in C++, e.g. because it has an unused template parameter.
// So we keep the original dep too.
typ = new_tn.to_type_path();
deps.insert(new_tn);
}
Expand Down
2 changes: 1 addition & 1 deletion engine/src/conversion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl<'a> BridgeConverter<'a> {
Self::dump_apis("parsing", &apis);
// Inside parse_results, we now have a list of APIs.
// We now enter various analysis phases.
// Next, convert any typedefs.
// First, convert any typedefs.
// "Convert" means replacing bindgen-style type targets
// (e.g. root::std::unique_ptr) with cxx-style targets (e.g. UniquePtr).
let apis = convert_typedef_targets(self.config, apis);
Expand Down
27 changes: 27 additions & 0 deletions integration-tests/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12403,6 +12403,33 @@ fn test_override_typedef_fn() {
run_test("", hdr, quote! {}, &["Foo"], &[]);
}

#[test]
fn test_double_template_w_default() {
let hdr = indoc! {"
class Widget {};
template <class T>
class RefPtr {
private:
T* m_ptr;
};
class FakeAlloc {};
template <typename T, typename A=FakeAlloc>
class Holder {
A alloc;
};
typedef Holder<RefPtr<Widget>> WidgetRefHolder;
class Problem {
public:
WidgetRefHolder& getWidgets();
};
"};
run_test("", hdr, quote! {}, &["Problem"], &[]);
}

// Yet to test:
// - Ifdef
// - Out param pointers
Expand Down

0 comments on commit 0ec7b78

Please sign in to comment.