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

Add nodiscard attribute to Status and StatusOr #1193

Merged
merged 2 commits into from
Dec 18, 2022

Conversation

PragmaTwice
Copy link
Member

@PragmaTwice PragmaTwice commented Dec 18, 2022

We make Status and StatusOr [[nodiscard]] in this PR, which means, you will get a compile warning if you do not handle the return value of a call to a function that returns Status or StatusOr, e.g.

Status DoSomething(int x);

DoSomething(0); // warning: cannot discard the return value

GET_OR_RET(DoSomething(0)); // fine if the current context is in a function that returns Status

if(auto s = DoSomething(0); !s.IsOK()) return s; // fine, same as above

if(auto s = DoSomething(0); !s.IsOK()) LOG(ERROR) << "got error: " << s.Msg(); // fine

auto s [[maybe_unused]] = DoSomething(0); // fine if you really want to discard the error (can explain in code review)

We will eventually make it a compiler error instead of a warning.

@PragmaTwice PragmaTwice marked this pull request as ready for review December 18, 2022 14:43
@PragmaTwice PragmaTwice merged commit 7ab8a19 into apache:unstable Dec 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants