TartanLlama / expected

C++11/14/17 std::expected with functional-style extensions

Home Page:https://tl.tartanllama.xyz

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`tl::make_unexpected()` should be `[[nodiscard]]`

azais-corentin opened this issue · comments

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.