eProsima / Fast-DDS-Gen

Fast-DDS IDL code generator tool. Looking for commercial support? Contact info@eprosima.com
Apache License 2.0
77 stars 59 forks source link

Simplify unions to never throw #207

Closed mikegratton closed 9 months ago

mikegratton commented 1 year ago

Simplify union types to never throw. Changing the discriminator always succeeds, and accessing a non-active member is legal.

For example, these changes make the following legal

SomeUnionType foo;
foo._d(kCaseBar); // Select another member "bar"
foo.bar().push_back(4); // Then mutate that member
JLBuenoLopez commented 9 months ago

@mikegratton

Regretfully, the proposed implementation contained in this PR is against the specification. According to the IDL to C++11 language mapping section 6.14.2:

The _d discriminator modifier can only be used to set the discriminant to a value within the same union member.

Consequently, I am going to close this PR.