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

    <tr>
        <th>Summary</th>
        <td>
            clang-tidy `bugprone-exception-escape` on handling tl::expected or tl::optional
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang-tidy
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          vrodedanya
      </td>
    </tr>
</table>

<pre>
    Clang-tidy marks [tl::optional::value()](https://github.com/TartanLlama/optional) with a `[bugprone-exception-escape](https://clang.llvm.org/extra/clang-tidy/checks/bugprone/exception-escape.html)` but doesn't do so when using the standard std::optional. Here are example functions to illustrate the issue:

```c++
int fillIfEmptyOrRetValue(tl::optional<int>& val) noexcept // marked as bugprone-exception-escape
{
    if (val.has_value())
    {
 return val.value();
    }
    val = 0;
    return 0;
}

int fillIfEmptyOrRetValue(std::optional<int>& val) noexcept
{
    if (val.has_value())
    {
        return val.value();
    }
    val = 0;
    return 0;
}
```

The function utilizing the standard std::optional does not trigger the bugprone-exception-escape warning, while the version with tl::optional does. This behavior seems inconsistent, given that tl::optional::value() cannot throw if has_value() has already confirmed the presence of a value. Consequently, I am forced to wrap val.value() in a try-catch block to suppress the clang-tidy warning, which seems unnecessary. 

Is there a way to configure clang-tidy to recognize tl::optional::value() as an exception-safe function for the purposes of this check? This adjustment would be great, since the current workaround complicates the code without providing any safety benefits. I already found this parameter `FunctionsThatShouldNotThrow`, but it doesn't work for me (probably I use it wrong):
```
CheckOptions:
  - {
      key: bugprone-exception-escape.FunctionsThatShouldNotThrow,
      value: "tl::optional::value",
    }
```

I am using clang-tidy from clangd version 17.0.3.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VsFu4zYQ_Rr6MrAgU7ZsH3xInDUaoOgCbdBrMZJGEjcUqZIjO9qvL0g5sZM02R66gZCE0nD45r3HI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