Bug 403201

Summary: Detect passing the wrong parent for members
Product: [Developer tools] clazy Reporter: kpopv <koen.poppe>
Component: generalAssignee: Sergio Martins <smartins>
Status: REPORTED ---    
Severity: wishlist CC: smartins
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Minimal example

Description kpopv 2019-01-14 08:20:49 UTC
Created attachment 117455 [details]
Minimal example

SUMMARY
QObject members can be constructed with this as parent so that they get cleaned up as part of the memory management of QObject trees. On construction of a QObject derived class, the passed in parent should be passed on to the superclass while this should be used as parent of all QObject derived members. 

It is not uncommon to see parent passed incorrectly to members, it would be nice if clazy could detect this.

STEPS TO REPRODUCE
1. Open the attached project and run it. It is expected to crash.

OBSERVED RESULT
1. m_c is destructed before m_b because m_c's parent is set incorrectly to a instead of b (during construction of b). This causes ~B to call a method on an already destroyed m_c, thus crashing the application.

EXPECTED RESULT
1. m_c(new C(this)) instead of m_c(new C(parent))

SOFTWARE/OS VERSIONS
Windows: 7
Qt Version: 5.9
Comment 1 Sergio Martins 2019-04-25 16:07:32 UTC
Could make sense.

If there's too many false-positives we can always disable it by default