Bug 405850 - connect-3arg-lambda should not warn in main()
Summary: connect-3arg-lambda should not warn in main()
Status: REPORTED
Alias: None
Product: clazy
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: Sergio Martins
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-25 08:41 UTC by David Faure
Modified: 2019-03-25 22:37 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Faure 2019-03-25 08:41:34 UTC
SUMMARY
connect-3arg-lambda warns about possible issues with the lifetime of captured variables (by reference). This leads to false positives when not going back to the event loop (e.g. unittests using job.exec()) or in main() where there's no lifetime issues.

This bug report is about main().

STEPS TO REPRODUCE
Run clazy on any akonadi unittest which uses QTEST_AKONADIMAIN(MyObject)
or do this directly:

    int result = 0; \
        QTimer::singleShot(0, [argc, argv, &result]() { \
            TestObject tc; \
            result = QTest::qExec(&tc, argc, argv); \
            qApp->quit(); \
        }); \
        app.exec(); \

OBSERVED RESULT

    Explanation for clazy-connect-3arg-lambda
    ./tests/auto/sugarcrmresource/test_sugarcrmresource.cpp
        line 585: QTEST_AKONADIMAIN(TestSugarCRMResource)
        => Pass a context object as 2nd singleShot parameter


EXPECTED RESULT

    No warning in main()
    or more generally, no warning when followed by a call to .exec() but that seems a little bit too black magic, possibly?