Open
Description
The following code causes -Wunused-lambda-capture on Clang 14.
https://godbolt.org/z/nna4q3jxo
#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;
}