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

    <tr>
        <th>Summary</th>
        <td>
            Incorrect -Wunused-lambda-capture
        </td>
    </tr>

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

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

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

<pre>
    The following code causes -Wunused-lambda-capture on Clang 14.
https://godbolt.org/z/nna4q3jxo

``` C++
#include <algorithm>
#include <memory>
#include <vector>

class Foo
{
public:
        void reset() {}
};

template <class T>
class Bar
{
public:
        using const_iterator = typename std::vector<T>::const_iterator;

        void reset()
        {
                std::for_each(
                                _v.begin(),
                                _v.end(),
                                /// Changing any one of the following does not cause -Wunused-lambda-capture
                                /// [ this] to [ = ], [ & ]
                                /// toReference(v).reset to this->toReference(v).reset()
                                /// (auto& v) to (T& v)
                                /// Removing member function: Foo& toReference(const_iterator it) const
                                [ this ](auto& v){ toReference(v).reset(); }
                );
        }

private:
        Foo& toReference(const_iterator it) const
        {
                return toReference(*it);
        }

        Foo& toReference(const T& object) const
        {
                if constexpr (std::is_pointer<decltype(object.get())>::value)
                {
                        return *object.get();
                }
                else
                {
                        return object.get();
                }
        }

        std::vector<T> _v;
};

int main()
{
        Bar<std::unique_ptr<Foo>> myBar;
        myBar.reset();
        return 0;
}

```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydVU2PozgQ_TVwsRKB-QgcOHQn09JeRy3NMTJQSdwyNmMMM9lfP2WTkJBO0rMrudPYVX71qvzKLlV9LN4PQHZKCPWLyz2pVA2kYn0HHVn86CV-1AvBmrJmi4q1ptdAlCRrwdA5jJdesPGCl4MxbedFLx59w7FXdamEWSq9x9m_-Ccli39GH7_V6H76TYNxkLVHX-0Yl2nEZSV65OFFayb2SnNzaLzo2z17A43Sxwf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