Issue 203690
Summary [clang-tidy] Check bugprone-unchecked-optional-access triggers a false-positive related to std::reference_wrapper
Labels clang-tidy, false-positive
Assignees
Reporter pkl97
    This code triggers a false-positive result from clang-tidy check bugprone-unchecked-optional-access (see https://godbolt.org/z/PEY3Ebrzj):

```c++
#include <functional>
#include <list>
#include <optional>

struct Group
{
    int m_id;
};

struct KeyBase
{
    std::optional<Group> m_group;
};

struct KeyWrapper
{
 const KeyBase& m_keyBase;
};

using KeyWrappers = std::list<std::reference_wrapper<const KeyWrapper>>;

void check(const KeyWrappers& items)
{
    for (const KeyWrapper& item : items)
    {
 if (item.m_keyBase.m_group.has_value())
        {
            const Group& g = item.m_keyBase.m_group.value(); // <-- false positive
        }
 }
}
```

The issue occurs on the main branch (upcoming clang 23) but is present at least since clang 21.

Could be related to #203686 but I am not sure.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to