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.65 Self-move - require only valid but unspecified #1938

Closed
wants to merge 16 commits into from

Conversation

bgloyer
Copy link
Contributor

@bgloyer bgloyer commented Jul 17, 2022

Cleaned up C.65: Make move assignment safe for self-assignment
based on the discussions in #1892 #1649 #1606.

// ...
~X() { delete owning_ptr; }
private:
T* owning_ptr; // bad (See R.20) but used in the example because
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I couldn't think of a simple example that required a manual move-assignment that didn't go against something in the guidelines

};

Foo& Foo::operator=(Foo&& a) noexcept // OK, but there is a cost
X& X::operator=(X&& a) noexcept
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Used 'X' instead of 'Foo' to match C.64

@cubbimew
Copy link
Member

This seems more radical than #1606:

As I recall, response to #1606 stalled because there was a draft paper on that topic.

@bgloyer
Copy link
Contributor Author

bgloyer commented Jul 23, 2022

Can we use 'valid-but-uspecified' until it is offically settled? I don't think it is practical to have the rule stronger than what the stl types do. Any type with an stl memeber that uses the rule of zero or = default would violate this rule. Or maybe have two rules, one that says 'valid-but-unspecified' and a stronger one for 'nop'? Then developers could choose which is appropriate for them? Setting 'valid-but-uspecified' as a minimum is important so that a type will work with swap.

@MikeGitb
Copy link

I like the Idea to stick with the stl behavior for now, but would love to see more data about the need for stronger rules. Has anyone had anekdotal or regular encounters with a self-move outside of self swap (where you don't care about the value)? What were the consequences for this?

@hsutter
Copy link
Contributor

hsutter commented Aug 8, 2022

Editors call: This would invert the guidance and we agree with the current guidance -- self-move should be a no-op.

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.

4 participants