Bug 485675 - lambda-in-connect does not honor receiver context
Summary: lambda-in-connect does not honor receiver context
Status: RESOLVED FIXED
Alias: None
Product: clazy
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: David Faure
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-04-17 12:25 UTC by Milian Wolff
Modified: 2024-04-28 11:46 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
patch to show failure in unit test (2.27 KB, patch)
2024-04-17 12:25 UTC, Milian Wolff
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Milian Wolff 2024-04-17 12:25:51 UTC
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
Comment 1 Bug Janitor Service 2024-04-17 13:50:36 UTC
A possibly relevant merge request was started @ https://invent.kde.org/sdk/clazy/-/merge_requests/135
Comment 2 David Faure 2024-04-28 11:46:32 UTC
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