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

Improve union types deduplication #520

Merged

Conversation

reicheratwork
Copy link
Contributor

Fixes issue #513
Rewrote is_same_type function to (more) correctly deduplicate union types, but only when boost::variant is used, as this does not have access by index
Added unittests to test more constructs in addition to those implemented by Jim Hague in PR #519

@banburybill , could you give this PR a look to see whether this fixes #513 for you?

Fixes issue eclipse-cyclonedds#513
Rewrote is_same_type function to (more) correctly deduplicate union
types, but only when boost::variant is used, as this does not have
access by index
Added unittests to test more constructs in addition to those
implemented by Jim Hague in PR eclipse-cyclonedds#519

Signed-off-by: Martijn Reicher <[email protected]>
@banburybill
Copy link
Contributor

My specific failure case was a union with bounded and unbounded strings. This looks good to me, and the refactoring is great.

I guess it's vulnerable to someone using the templating to replace std::string with a genuine bounded string class. But I think that is probably a very niche usage, and fixing the out-of-the-box problem is far more important.

@reicheratwork
Copy link
Contributor Author

I guess it's vulnerable to someone using the templating to replace std::string with a genuine bounded string class. But I think that is probably a very niche usage, and fixing the out-of-the-box problem is far more important.

That is also being checked for in the following code part:

const bool bstr_unique = (strcmp(gen->bounded_string_format, gen->string_format) != 0),
                  bseq_unique = (strcmp(gen->bounded_sequence_format, gen->sequence_format) != 0);

So in the case when a "normal" string is std::string and a bounded string is something else, the boolean bstr_unique is true and the bounded versions of strings will have their bound values added to the array identifying the type being compared. And therefore will "look like" different type, when compared to the unbounded versions.

The same is checked for when encountering (un)bounded sequences.

@banburybill
Copy link
Contributor

banburybill commented Nov 22, 2024

Ah, I missed that bit. You're way ahead of me. Looks great.

Copy link
Contributor

@eboasson eboasson left a comment

Choose a reason for hiding this comment

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

LGTM 😀 Thank you @reicheratwork !

@eboasson eboasson merged commit c2aaad4 into eclipse-cyclonedds:master Nov 26, 2024
17 of 20 checks passed
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.

Unions fail to compile if they contain multiple strings with different bounds
3 participants