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

    <tr>
        <th>Summary</th>
        <td>
            clang-tidy bugprone-unchecked-optional-access assumes unstable function results when it's impossible
        </td>
    </tr>

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

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

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

<pre>
    It will complain in code like 

```
#include <optional>
#include <string>

class FontInfo
{
public:
    FontInfo() = default;

    const std::optional<std::string> &getName() const { return name; };

private:
    std::optional<std::string> name;

};

int main(int argc, char **)
{
    FontInfo fi;
    printf("HAS NAME %s\n", fi.getName() ? fi.getName()->c_str() : "[none]");
}
```


because it has the rule that consecutive calls to the same function might return different values, but that's simply not possible given how the two getName calls are one after the other and they are just returning a const & to a member in a const method, no?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNVE2T4iAQ_TXJpUsrEo3xkIMfa-0cdi77A7YI6STMELCAaPnvt8GoMztzWItCoJvXrx_dqU1zrV48XKRSIMxwUlxqoCFMg6DkO0KSHZJsO81FNo3bluVSCzWSa5LvzclLo7lK8h_fmZ23UndPY5yF4s7B0Wj_olszWda72-I01kqKJJ98gX4PT1YmbEOwB2iw5aPySb77CBychdHOg_NNgMi3T377x9mDFCSs6NC_8gEn7NttIgMW_Wg16GDLd3R0-CfYycoz9_iJ6X-GnUA_ifwFX2oPAz0MMQtLbjuRsD2InlvivY1j8494H9WCVj4Qwznx1b6NebKf29_wuv0VBFi5ZLWnICyAt3L-WY8kP345nFEK4g9l8_DZQri_2mmjMVkdItjmmQ6l9m0hfZhrFHx0CNJDzx34HsGOCmnBfXwUFKOXZwTBlSK7iS6OOEE7ahHEhkF2vb-_WyPbFi2ScGeuRnQhu3r0ETBhawdOUt1fQRsPJ-OcrClaRxE09OYS0f3FwJT4FJZbBEoReOvRRh9DkwWum7C7Roe30d1Z0HMDv9cUKwJtDgMONd2hdrubBvS9aQJDbUjwFKtFURR5tszzLG2qvNnkG5566RVW1Du6m3nZXCmd7mSJzowE6FG8YzO7l92MC4HUY9Rn44AORgrDQ4YPsSw66h8Hl54yljdJSJFJiXS0quq9P7lQuuxIo5O-H-s5fS5oo9T5_jcjDm8oCOEoKVpQ-rgqV4ss7au8YHzJ1uu6FE3JsrLgJdZFUQteFCWWRap4jcpVVDpUMxovECFiMR1SWbGMsUUW53KVzdslK_m6FGLTCLFYsWSZIXWImgcec2O71FaREinjyKik8-5pJDFkpxFjOMLnI8luK--aDo1LY-gqUv8LIkKTQQ">