-
Notifications
You must be signed in to change notification settings - Fork 247
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
Fix object usage after move in make_delegate_with_shared_state #1253
Conversation
The function make_delegate_with_shared_state (from strings/base_coroutine_foundation.h) uses on object after it was moved. 'd' is moved using std::move and then it's passed to get_abi. The usage of 'd' after it was moved it undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
I'm not a C++ Language Lawyer, but I believe the problem statement to be incorrect.
That's not what
As I understand it this means that when Even if it had been moved already, the following isn't true, either:
C++ doesn't have "destructive moves". An object that has been moved from must remain in a valid (even if unspecified) state. Subsequent use is thus well defined; the behavior may be unexpected, still. But, unless my interpretation is wrong, we haven't moved yet, so this is moot. While I don't have an issue with the proposed changes1, it would be helpful for clients—especially those dealing with an issue in their code—to know, whether this change is fixing a genuine bug in the C++/WinRT library code. Can we get a confirmation on this? Footnotes
|
@tim-weis thanks for your comment. Your explanation about std::move and the fact that everything is actually well defined is correct. Sorry for my inaccuracy there. Regarding the possibility for an actual bug and your comment about not being able to move 'd' out of the function due to the overload resolution:
|
@yuvaln-s1 The first point is technically correct, but not an issue in practice. As for the second point, I'm probably not understanding things. As far as I can see, |
I doubt the change makes any practical difference, but merely clarifies. Tim, if you find a regression I'm happy to roll it back or you can offer a fix. |
@tim-weis I understand your point about my first point. Here's the relevant std::pair ctor: |
@yuvaln-s1 Thank you, that's the part I was missing. This does indeed allow passing a mix of lvalue and rvalue references, and still have the rvalue references participate in move-construction (verified here; Clang agrees, too). @kennykerr The primary concern was that this PR (and its title) will eventually make it into the release notes of a future release. If there was no defect then the release notes shouldn't claim that something were fixed. I was asking for confirmation on whether there was or wasn't a defect. |
The function make_delegate_with_shared_state (from strings/base_coroutine_foundation.h) uses on object after it was moved. 'd' is moved using std::move and then it's passed to get_abi. The usage of 'd' after it was moved it undefined.