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

Re-delete bitfield's copy-assignment operator #47

Merged
merged 3 commits into from
Jul 11, 2022

Conversation

Pokechu22
Copy link
Contributor

Now, the move-assignment operator is provided so that unions can be assigned to with the CGX defaults.

See #46 (comment).

@Pokechu22
Copy link
Contributor Author

Note that this approach doesn't help with getting rid of the explicit copy constructors in RenderState.h in the main Dolphin repo, as they're used with const references.

@Pokechu22 Pokechu22 requested a review from neobrain April 22, 2022 23:59
Copy link
Member

@neobrain neobrain left a comment

Choose a reason for hiding this comment

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

Cool that the suggestion works so seamlessly!

I don't like this workaround in general, but considering it's just the hwtests repository, it's an acceptable trade-off. I wouldn't recommend porting this approach to Dolphin itself, so I'm relieved it doesn't trivially apply there :)

// code expects that this class is trivially copyable.
BitField& operator=(const BitField&) = delete;
// The move-assignment operator is still supplied so that unions can be
// assigned to. This still copies the full storage value, but that's the
Copy link
Member

@neobrain neobrain Apr 23, 2022

Choose a reason for hiding this comment

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

Can you make this comment work in isolation (giving a reference to the copy assignment operator if needed)? Currently, it assumes the reader just finished reading the docstring of the copy-assignment operator. If that's not the case, "This still copies the full storage value" is confusing in that it doesn't highlight that this surprising behavior is a trap to watch out for.

// The move-assignment operator is still supplied so that unions can be
// assigned to. This still copies the full storage value, but that's the
// desired behavior when assigning to unions, so there's no issue with that.
// Note that this is still functions as a copy-assignment operator; the other
Copy link
Member

Choose a reason for hiding this comment

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

the other bitfield is not modified

Isn't it very much modified?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, I misread this comment. I suggest saying "right-hand operand" instead, as there's potential confusion with the other BitFields grouped in the current union.

This reverts commit 9b7be93.  Note that this reversion means code no longer compiles properly.  (Also note that BitField.h is still modified from the version used in Dolphin, to remove references to Inline.h.)
This allows assigning unions from CGXDefault, but still prevents the bad behavior of copying all bits when assigning one individual BitField to another.
Before, writing e.g. `CGXDefault<int>();` would compile successfully (with a warning), but would fail on linking.  Now, it fails when compiling.
@Pokechu22 Pokechu22 force-pushed the bitfield-no-copy-assignment branch from 5c524b9 to 53c1707 Compare April 23, 2022 18:18
@Pokechu22 Pokechu22 merged commit ca5f8a9 into dolphin-emu:master Jul 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants