<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/130656>130656</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Mark std::expected as [[nodiscard]]
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          2LoS
      </td>
    </tr>
</table>

<pre>
    I think it may be problematic to discard the result of a function that uses `std::expected` for error handling. It is the equivalent of enclosing an exception-throwing function call in a try-catch block, where any caught exception is just ignored.

```cpp
try {
 func();
}
catch(...) {}
```

The language allows it to happen without any ceremony. It should, of course, be possible to write the ceremony explicitly.

```cpp
(void)func();
```

The way to make this happen is marking `std::expected` as nodiscard. For example, *[Microsoft STL](https://github.com/microsoft/STL/pull/5174)* and *martinmoene/expected-lite* have already done it. Also libc++ has fixed its tests to support the case in which `std::expected` be marked as nodiscard, even if its own library has not marked it yet.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx8lN-umzgQxp_GuRkFgQn5c8FFskeRKrVX7QsM9gS7MTZrDyG8_cqcpkers13JAmHG3zfzm5ExJdt7olY0F9G8bXBiE2Irv4bvmy7opf0CbKy_g2UYcIGOYIyhczQgWwUcQNukMGpgQxApTY4h3ADhNnnFNnhggwxTogRiXybWoj6L-kzPkRSTFvsSbiECxRgiGPTaWd8X8IXBplWU_p7sAx35VZi8ciFZ3wN6oKeiMZts2cQw593ftgqdA-sBgeOyVcjKQOeCugv5F8yGIgH6BRROveEPpez6c0oMtvchki5Eec5rX74vNY6iPHNcQBwuojyvhkIehTyJOm-Iw5soz6ufkMeiKIQ8rbHr_m-dd9kfhsCh7yfsCdC5MKdMmgMYHEfyMFs2YeL3VCnSEPyywkkmTE7nWsINVJhiovyR-xNSsp2jrDJHy7RSfB0Geo7OKstu-e_ShDw-gtVCnj5V9jn3GZdsM-A9u9j0StsmGDDec0P-1HRM4MOv4SngmkfgicPo1jKEPIvm8s2qGFK4MXz_8VU0b0IeDfOYspi8CnntLZupK1QYhLwOr2ghrzleXsfJOSGvTXXY5SLkGdDrrD1gZOuHQJ6EvL6y2jrLlKMMPnI3IqFeQAdPYLmAs0sBnO2UkBchL2Awwc0-SYPlBEwpPwOkaRxD5HfomCjP4GysMn8k0dEKi_S_mGQM9Mgsb6tBmH12jxiX1doHfh2zDAtxsdFtrU_1CTfUVoddta_r02m3Ma066bLS3YG6ekeyU7t6Tx1WZXnoNB4atbGtLGVT1lVZnaq62hVNXeNxXx-7g6z2VXcQu5IGtK5w7jEUIfYbm9JEbVWX-2a_cdiRS-sdIqWnGda_Qsp8pcQ2H9p2U5_ErnQ2cfqQYcuO2m8Y7_CJTcaxXkuXDyjNW5acomv_ZxKy-q_XdozhJ6k8E2tOScjrr6QfrfwnAAD__yrCnl8">