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

tl::make_unexpected() should be [[nodiscard]] #124

Open
azais-corentin opened this issue Dec 7, 2022 · 0 comments
Open

tl::make_unexpected() should be [[nodiscard]] #124

azais-corentin opened this issue Dec 7, 2022 · 0 comments

Comments

@azais-corentin
Copy link

azais-corentin commented Dec 7, 2022

As the titles says, the function tl::make_unexpected() should be marked [[nodiscard]].

It would prevent misuse when forgetting to return the unexpected value:

enum class ErrorType{
    kNullParameter
};
struct ResultType{};

tl::expected<ResultType, ErrorType> myFunction(int nonNullParameter)
{
    if(nonNullParameter== 0) {
        tl::make_unexpected(ErrorType::kNullParameter);
    }
    
    return ResultType{};
}

Here I forgot to return the unexpected value and there's no warning whatsoever.

@azais-corentin azais-corentin changed the title tl::make_unexpected should be [[nodiscard]] tl::make_unexpected() should be [[nodiscard]] Dec 7, 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

No branches or pull requests

1 participant