Bug 480325

Summary: Detaching of QList::last and QList::first
Product: [Developer tools] clazy Reporter: aklitzing
Component: generalAssignee: Unassigned bugs <unassigned-bugs-null>
Status: RESOLVED NOT A BUG    
Severity: normal CC: smartins
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description aklitzing 2024-01-25 15:40:22 UTC
It seems QList::last and QList::first on Qt6 is a false-positive for Wclazy-detaching-member.

We get for this a warning.

QStringList list;
list << "dummy";
list.last().append("hello");

But it won't call any detaching.

    inline T& first() { Q_ASSERT(!isEmpty()); return *begin(); }
    inline const T &first() const noexcept { Q_ASSERT(!isEmpty()); return *begin(); }

    inline T& last() { Q_ASSERT(!isEmpty()); return *(end()-1); }
    inline const T &last() const noexcept { Q_ASSERT(!isEmpty()); return *(end()-1); }