Created attachment 168616 [details] patch to show failure in unit test SUMMARY lambda-in-connect seems smart enough to figure out if the sender is in the same stack frame as a capture, but does not take the receiver context into account STEPS TO REPRODUCE See attached patch OBSERVED RESULT ``` QObject o2; QObject::connect(&o2, &QObject::destroyed, [&m]() { m; }); // OK, o2 is on the stack QObject *o3; QObject::connect(o3, &QObject::destroyed, o3, [&o3] { o3; }); // OK, the captured variable is on the 3rd parameter too. It will get destroyed // this fails: QObject::connect(o3, &QObject::destroyed, &o2, [&m]() { m; }); // OK, o2 is on the stack ``` EXPECTED RESULT failure for constructs such as the last one, where `m` is on the stack and gets destroyed after `o2`. SOFTWARE/OS VERSIONS latest clazy master against clang 17.0.6 ADDITIONAL INFORMATION
A possibly relevant merge request was started @ https://invent.kde.org/sdk/clazy/-/merge_requests/135
Git commit b66a84677a7aa33f26b9de4306b5c6af6679c230 by David Faure. Committed on 28/04/2024 at 11:37. Pushed by dfaure into branch 'master'. Fix false positive from lambda-in-connect when the receiver is on the stack M +3 -1 src/checkbase.h M +6 -0 src/checks/level0/lambda-in-connect.cpp M +7 -2 tests/lambda-in-connect/main.cpp M +1 -1 tests/lambda-in-connect/main.cpp.expected https://invent.kde.org/sdk/clazy/-/commit/b66a84677a7aa33f26b9de4306b5c6af6679c230