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

Mark iox container operations which return bool as [[nodiscard]] #2277

Open
pbarone-latai opened this issue Apr 24, 2024 · 1 comment · May be fixed by #2280
Open

Mark iox container operations which return bool as [[nodiscard]] #2277

pbarone-latai opened this issue Apr 24, 2024 · 1 comment · May be fixed by #2280
Labels
refactoring Refactor code without adding features

Comments

@pbarone-latai
Copy link
Contributor

Brief feature description

Marking any operation in iox containers which may fail and return bool as [[nodiscard]]

Detailed information

The idea here is pretty straightforward. Taking iox::vector for example, the API for push back returns bool as compared to void of std::vector::push_back.

/// @brief appends the given element at the end of the vector
/// @param[in] value to append to the vector
/// @return true if successful, false if vector already full
bool push_back(const T& value) noexcept;

Marking this code as [[nodiscard]] will raise compiler warnings in the event that a user is pushing back blindly onto an iox::vector and not handling the case where it fails. If the user has performed size checks at the beginning of a loop, they can simply use ...

std::ignore = my_iox_vector.push_back(value);

If the iceoryx team is aligned with this approach, I can put up a PR to add the nodiscards

pbarone-latai added a commit to pbarone-latai/iceoryx that referenced this issue Apr 24, 2024
pbarone-latai added a commit to pbarone-latai/iceoryx that referenced this issue Apr 24, 2024
@elBoberido
Copy link
Member

@pbarone-latai we do not have objections but you might need to add quite a lot of IOX_DISCARD_RESULT across the codebase

@mossmaurice mossmaurice added the refactoring Refactor code without adding features label Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Refactor code without adding features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants