Skip to content

Commit

Permalink
Merge pull request #1179 from google/failing-1170-test
Browse files Browse the repository at this point in the history
Fix movability of structs with enum fields
  • Loading branch information
adetaylor authored Nov 3, 2022
2 parents 6cca9b2 + 65dd0e2 commit 59da591
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
10 changes: 3 additions & 7 deletions engine/src/conversion/analysis/deps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,9 @@ impl HasDependencies for Api<FnPrePhase1> {
..
} => Box::new(old_tyname.iter().chain(deps.iter())),
Api::Struct {
analysis:
PodAnalysis {
kind: TypeKind::Pod,
bases,
field_deps,
..
},
analysis: PodAnalysis {
bases, field_deps, ..
},
..
} => Box::new(field_deps.iter().chain(bases.iter())),
Api::Function { analysis, .. } => Box::new(analysis.deps.iter()),
Expand Down
19 changes: 18 additions & 1 deletion engine/src/conversion/analysis/fun/implicit_constructors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ pub(super) fn find_constructors_present(
apis: &ApiVec<FnPrePhase1>,
) -> HashMap<QualifiedName, ItemsFound> {
let (explicits, unknown_types) = find_explicit_items(apis);
let enums: HashSet<QualifiedName> = apis
.iter()
.filter_map(|api| match api {
Api::Enum { name, .. } => Some(name.name.clone()),
_ => None,
})
.collect();

// These contain all the classes we've seen so far with the relevant properties on their
// constructors of each kind. We iterate via [`depth_first`], so analyzing later classes
Expand Down Expand Up @@ -211,7 +218,17 @@ pub(super) fn find_constructors_present(
})
};
let get_items_found = |qn: &QualifiedName| -> Option<ItemsFound> {
if let Some(constructor_details) = known_types().get_constructor_details(qn) {
if enums.contains(qn) {
Some(ItemsFound {
default_constructor: SpecialMemberFound::NotPresent,
destructor: SpecialMemberFound::Implicit,
const_copy_constructor: SpecialMemberFound::Implicit,
non_const_copy_constructor: SpecialMemberFound::NotPresent,
move_constructor: SpecialMemberFound::Implicit,
name: Some(name.clone()),
})
} else if let Some(constructor_details) = known_types().get_constructor_details(qn)
{
Some(known_type_items_found(constructor_details))
} else {
all_items_found.get(qn).cloned()
Expand Down
24 changes: 24 additions & 0 deletions integration-tests/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11285,6 +11285,16 @@ fn test_typedef_to_ns_enum() {
run_generate_all_test(hdr);
}

#[test]
fn test_enum_in_ns() {
let hdr = indoc! {"
namespace a {
enum b {};
} // namespace
"};
run_test("", hdr, quote! {}, &["a::b"], &[]);
}

#[test]
fn test_typedef_unsupported_type_pub() {
let hdr = indoc! {"
Expand Down Expand Up @@ -11701,6 +11711,20 @@ fn test_issue_1143() {
run_test("", hdr, quote! {}, &["mapnik::Map"], &[]);
}

#[test]
fn test_issue_1170() {
let hdr = indoc! {
"#include <vector>
struct a {
enum b {} c;
} Loc;
struct Arch {
std::vector<a> d();
} DeterministicRNG;"
};
run_test("", hdr, quote! {}, &["Arch"], &[]);
}

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

0 comments on commit 59da591

Please sign in to comment.