Skip to content

Commit

Permalink
Consider that enums are always movable/destroyable.
Browse files Browse the repository at this point in the history
The other root cause behind bug #1170 was that C++ enums did not
get move constructors nor destructors generated (they don't need them!)
- but their absence was being used as evidence that any outer type
containing such a field was also not movable.

For example,

  struct C {
    enum D {} some_enum_field;
  };

C would not be considered movable, and therefore could not exist
in a C++ vector.

This change arranges to ensure that enums are always considered
movable or destroyable in this analysis.
  • Loading branch information
adetaylor committed Nov 3, 2022
1 parent 4eab29a commit 29296ee
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 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,16 @@ 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

0 comments on commit 29296ee

Please sign in to comment.