-
Notifications
You must be signed in to change notification settings - Fork 593
Avoid use-after-return caused by double move #11485
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,8 +70,9 @@ class Result final { | |
/// Value copy constructor. | ||
/* implicit */ Result(const T& val) : value_(val), hasValue_(true) {} | ||
|
||
/// Value move constructor. | ||
/* implicit */ Result(T&& val) : value_(std::move(val)), hasValue_(true) {} | ||
/// Value forwarding constructor. | ||
/* implicit */ Result(T&& val) | ||
: value_(std::forward<T>(val)), hasValue_(true) {} | ||
Comment on lines
-73
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I misread what was going on here originally. This isn't a template function (though it is a member of a template class), so this really is an rvalue reference. I think that the original code is probably correct; std::forward is for arguments to template functions (https://en.cppreference.com/w/cpp/utility/forward.html). |
||
|
||
/// Result move constructor. | ||
/* implicit */ Result(Result&& rhs) noexcept : hasValue_(rhs.hasValue_) { | ||
|
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.
Can you add a test that wouldve caught the previous bad behavior.
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.
Sure. Where are the tests for this type?
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.
Can you try adding to this file: https://github.com/pytorch/executorch/blob/2dedc9e0e39047269b7762652b593c5c53883168/runtime/core/test/error_handling_test.cpp