-
Notifications
You must be signed in to change notification settings - Fork 5.5k
C.65 example code is wrong #1892
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
Comments
The way I read it the whole point of that example is to show what a bad implementation would look like. However I do think that meaning is difficult to arrive at so clarity could be improved. I wonder if the example is really adding anything. The example above that appears to be the "good" example so I'm not sure another good example would help. That said, the "this line is redundant" comment is a bit confusing as it seems to contradict the rule. |
The example specifically says it's showing how to do it without a test, so adding a test to it would break the example. And the rest of the item specifically says you should have the test, so I agree this is a "don't do it this way" example. You need to read the whole item, not just the final example. It should be clarified to avoid that misunderstanding. |
In my opinion, the class Foo's data members are standard-library container types (incl. |
OK, I have understood that C.65 the final example is a "don't do it this way" example. However, it is too misleading for readers. I think the final example needs to be clearly instructed that this is a "don't do it this way" example. |
see also #1649 |
The wording of this one is a little confusing. The text under 'Reason' implies that The last example is just showing a way to get There is a disussion about self move at: https://ericniebler.com/2017/03/31/post-conditions-on-self-move/ |
Editors call: We will look to see if we can make this clearer. |
Editors call: We will update the example to say that this is an example of code that would break without the test. |
C.65 Link: C.65: Make move assignment safe for self-assignment
If someone move-assigns an object to itself, line
delete ptr;
deletes boththis->ptr
andother.ptr
(i.e.,temp
) since*this
andother
are the same object. Finally,*this
is no longer a valid object.In my opinion, the move assignment operator must have a self-assignment test. The correct example code is as follows:
The text was updated successfully, but these errors were encountered: