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

    <tr>
        <th>Summary</th>
        <td>
            clang tidy: False positive for "unchecked-optional-access" when returning std::tuple containing std::optional
        </td>
    </tr>

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

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

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

<pre>
    Hello,

I am using clang-tidy 15.0.7 and I have this code:
https://godbolt.org/z/ea56j3ndz

on `func2` call I get "unchecked-optional-access" altough the value is checked.

```
struct Timeouts
{
    long x;
    long y;
};

void func2(const Timeouts& timeouts)
{
    // do smth with timeouts
};

std::tuple<bool, std::optional<Timeouts>> func()
{
    return std::make_tuple(true, std::nullopt);
};

int main()
{
    const auto [b, timeouts] = func();
    if (timeouts.has_value())
    {
 func2(*timeouts); // bugprone-unchecked-optional-access
 }
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVF2PozoM_TXhxSoKZsiUBx5m2kV33u_7KoAL2Q1JRZzOnf31V0A_V1uthEI-HJ_jYzs6BNM7okoU76LYJzry4KeK9efo2SeN776qf8haL3An5F7It3X8AD1CDMb10Frt-g2b7guyIpXpK2jXwQcM-kTAgwnQ-o5Efr45MB_DvMJaYN37rvGWUz_1AutfAmvShfqRu-7XPZx3IJQ8RNeiUBJabS18QE8MAjG6dqD2J3Ubf2TjnbYb3bYUgkAEbdnHfgAeCE7aRoKZ0Gqf3kMIJc_fsgw8xZbhXzOSjxzONq_v6wQAwHrXw38i_33r67olXve3-TKevOlgDQO3rXfhDgEV8HVe_gFwVQw6D2HkAT4ND7cbTwADd7PW-RvHoyWR7xrvrcAdXA8umol8d6WSfxP5t4WnwO2fyUzEcXI3N6P-Sd9XENzyFOkBxEVr_ZFnV8_FMY5h1MY9xVwF05E9iOK9mRGu8Rd7EPn-nvN9YswBZlpn43TQ4ftSDGfTC9qi8hXxkieBb_eJyd8vmWhif5y8o83zClw9zbFeg36stqSr8q7MS51QlamyQLktlEyGKs9emoZk84LyoIotNZhJjapQZUdKla-JqVBiLkuUWZYpKdMs04SS5IGyAlWpxYukURubWnsa5w5LTAiRKqW2ZZZY3ZANS98jLj0sEOcnYKpm-00T-yBepDWBw80DG7ZULeYwt7zI36DWNhAcfTBsTgQHP_21Kz8HcucSmp-Qxyqd88zaPJ5cnCRxstVvb4jhITZp60eB9cz0_NscJ_-DWhZYL4EHgfUS-_8BAAD__9JZeQw">