Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++: Fix code generation for union field types that are constructed with allocators #325

Closed
wants to merge 9 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Jan 16, 2024

  • Added in_place_index_t to nunavut support library; adds the resource in c++14, references std::in_place_index_t in c++17 builds
  • Added initialization constructors to union composite type classes, takes a nunavut::support::in_place_index_t that specifies the alternative type to hold
  • Initialization expression for union_value member of union composite types is now generated, with appropriate parameters, in copy and move constructors with allocators
  • Replaced alternative index hardcoding in C++14 union VariantType internal logic with IndexOf property

@ghost ghost marked this pull request as draft January 19, 2024 22:28
VariantType(nunavut::support::in_place_index_t<I> i, Args&&... args) :
Base{std::in_place_index_t<I>{}, std::forward<Args>(args)...}
{
(void)i; // avoid unused param warning
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can just omit i in the constructor.

Copy link
Member

@thirtytwobits thirtytwobits left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Just need to add tests.

Copy link

sonarcloud bot commented Jan 20, 2024

@ghost ghost marked this pull request as ready for review January 20, 2024 02:10
src/nunavut/lang/cpp/support/utility.j2 Show resolved Hide resolved
src/nunavut/lang/cpp/support/utility.j2 Show resolved Hide resolved
rhs: str = ""
leading_args: typing.List[str] = []
trailing_args: typing.List[str] = []
if needs_variant_init_args(composite_subtype):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false branch not covered in python test

if language.get_option("ctor_convention") == ConstructorConvention.UsesLeadingAllocator.value:
leading_args.extend(["std::allocator_arg", "allocator"])
else:
trailing_args.append("allocator")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not covered in python test


if needs_vla_init_args(instance, special_method):
constructor_args = language.get_option("variable_array_type_constructor_args")
if isinstance(constructor_args, str) and len(constructor_args) > 0:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false branch not covered in python test.


return value_initializer
@template_language_test(__name__)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this filter not coverend in python tests.

}

/**
* Verify that the variant value can be fetched only at the alternative index for the type being held
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a test that actually passes an allocator through to a variant type constructor.

@thirtytwobits
Copy link
Member

Closing as abandoned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants