Clang calls this unused in a generic lambda that calls a member without this->
PitfallVerified 28 Sep 2026Holds anywhere
Pitfall. The symptom, what causes it, and the fix that was run and seen to work.
Symptom#
In a class template, a generic lambda that captures this and calls a member function draws a warning, although it does use this:
Value const
warning: lambda capture 'this' is not used [-Wunused-lambda-capture]
With warnings treated as errors, or a no-warnings rule, the build fails.
Cause#
Inside the generic lambda of a template, node(n) is a call that depends on the lambda's auto parameter, and clang's unused-capture check does not count the implicit this it goes through. Why clang misses it was not investigated; the call does need the capture.
Fix#
Name the member through this:
return ;
Do not drop the capture: the call needs it.
Evidence#
- dftracer-utils
src/dftracer/utils/duql/evaluator.cpp,TermEval<Record>::operator()(Apple clang, C++20, 2026-09-27): the warning appeared on every instantiation and went away withthis->node(n); the same fix removed it for a generic lambda callingintern_lookupinevent_source.h.