Bug 405850

Summary: connect-3arg-lambda should not warn in main()
Product: [Developer tools] clazy Reporter: David Faure <faure>
Component: generalAssignee: Sergio Martins <smartins>
Status: REPORTED ---    
Severity: normal CC: smartins
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

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?