-
Notifications
You must be signed in to change notification settings - Fork 402
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
iox-1750 Add Expects
to cxx::expected::value()
and get_error()
#1754
iox-1750 Add Expects
to cxx::expected::value()
and get_error()
#1754
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1754 +/- ##
=======================================
Coverage 77.37% 77.38%
=======================================
Files 366 366
Lines 14187 14196 +9
Branches 1983 1983
=======================================
+ Hits 10977 10985 +8
Misses 2583 2583
- Partials 627 628 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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.
@mossmaurice the issue itself is based on a false assumption. Accessing a non existing value or error in an expected is defined behavior.
The underlying variant
returns nullptr
in get_type_at_index
which is used in the expected
implementation.
So accessing a non existing value or error is defined as dereferencing a nullptr
.
The question which now remains: should we call the error handler and where. Since this is not a problem of the expected
but the underlying variant
I suggest to adjust the methods there. We could adjust get_type_at_index
so that it does no longer return a nullptr
when the type is not emplaced there but calls the error handler.
What do you think?
I was thinking about this before. Looking at the STL API of In this particular case, in my opinion it's not the task of the Let's say the following would be defined behaviour, which error would returned from
|
2c64a99
to
1b021b6
Compare
f79b662
to
f72002d
Compare
@@ -55,6 +55,7 @@ | |||
- `m_originId` in `mepoo::ChunkHeader` sometimes not set [\#1668](https://github.com/eclipse-iceoryx/iceoryx/issues/1668) | |||
- Removed `cxx::unique_ptr::reset` [\#1655](https://github.com/eclipse-iceoryx/iceoryx/issues/1655) | |||
- CI uses outdated clang-format [\#1736](https://github.com/eclipse-iceoryx/iceoryx/issues/1736) | |||
- Avoid UB when accessing `iox::expected` [\#1750](https://github.com/eclipse-iceoryx/iceoryx/issues/1750) |
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.
This statement is wrong, there is currently no undefined behavior in the expected since the variant
returns a nullptr
in those cases which is well defined.
But an expect call before hand makes sense so that we can forward this to some kind of error handling.
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.
@elfenpiff I don't fully get what you mean. The following is definitely UB and avoided with this PR:
auto sut = expected<Foo, Bar>::create_error(Bar::VALID_ERROR);
auto myValue = sut->memberVariableOfFoo;
Because as you wrote the ìox::variant
will return a nullptr
which cause UB in operator->
.
@@ -239,21 +243,22 @@ class IOX_NO_DISCARD expected<ErrorType> : public FunctionalInterface<expected<E | |||
bool has_error() const noexcept; | |||
|
|||
/// @brief returns a reference to the contained error value, if the expected | |||
/// does not contain an error this is undefined behavior | |||
/// does not contain an error the application terminates |
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.
Isn't this wrong in detail. I would rather state that the error handler will be called and then it does what an error handler does. Please adjust this here and in the other descriptions.
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.
We currently use this wording in most of the classes e.g. iox::optional
, iox::vector
, so I followed along for consistency. But I know what you mean, hence adjusted the wording. The doxygen of the other classes should be adapted with #1032.
Signed-off-by: Simon Hoinkis <[email protected]>
Signed-off-by: Simon Hoinkis <[email protected]>
f72002d
to
d724cbe
Compare
d724cbe
to
4f51307
Compare
…d 'has_error' Signed-off-by: Simon Hoinkis <[email protected]>
…ox::expected' Signed-off-by: Simon Hoinkis <[email protected]>
4f51307
to
434d0ce
Compare
Pre-Review Checklist for the PR Author
iox-123-this-is-a-branch
)iox-#123 commit text
)task-list-completed
)iceoryx_hoofs
are added to./clang-tidy-diff-scans.txt
Notes for Reviewer
Expects
tocxx::expected::value()
andget_error()
Checklist for the PR Reviewer
iceoryx_hoofs
have been added to./clang-tidy-diff-scans.txt
Post-review Checklist for the PR Author
References
cxx::expected
which contains a value or error leads to UB if the contrary is accessed #1750