Bug 389055 - suggest simplification: `$smartpointer.data()->` to `$smartpointer->`
Summary: suggest simplification: `$smartpointer.data()->` to `$smartpointer->`
Status: RESOLVED FIXED
Alias: None
Product: clazy
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR wishlist
Target Milestone: ---
Assignee: Unassigned bugs mailing-list
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-16 14:19 UTC by Milian Wolff
Modified: 2021-07-23 19:34 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 Milian Wolff 2018-01-16 14:19:43 UTC
I've often seen ugly code bases that could be tidied up by applying the following transformation:

`$smartpointer.data()->...` to `$smartpointer->...`

E.g. this is bad:

QScopedPointer<QObject*> myObj(new QObject);
myObj.data()->deleteLater();

This is much nicer:

QScopedPointer<QObject*> myObj(new QObject);
myObj->deleteLater();
Comment 1 Sergio Martins 2018-03-24 12:20:32 UTC
There's some gcc version that doesn't support this, but maybe old enough to ignore
Comment 2 Sergio Martins 2018-08-15 19:00:25 UTC
https://codereview.qt-project.org/#/c/230337/ is an example of gcc 4.8 nagging about missing data()
Comment 3 Sergio Martins 2021-07-23 19:34:01 UTC
Git commit 74686cc8c884dbcfabb12ea7a926e0eec486846d by Sergio Martins, on behalf of Waqar Ahmed.
Committed on 23/07/2021 at 19:33.
Pushed by smartins into branch 'master'.

Add use-arrow-operator

Suggest to use arrow operator with qt smart pointers instead of
.data()->someFunc()

print parent class name in warning

Signed-off-by: Waqar Ahmed <waqar.17a@gmail.com>

M  +1    -0    CheckSources.cmake
M  +1    -0    ClazyTests.cmake
M  +7    -0    checks.json
M  +2    -0    src/Checks.h
A  +90   -0    src/checks/manuallevel/use-arrow-operator.cpp     [License: LGPL (v2+)]
A  +39   -0    src/checks/manuallevel/use-arrow-operator.h     [License: LGPL (v2+)]
A  +8    -0    tests/use-arrow-operator/config.json
A  +20   -0    tests/use-arrow-operator/main.cpp  *
A  +3    -0    tests/use-arrow-operator/main.cpp.expected

The files marked with a * at the end have a non valid license. Please read: https://community.kde.org/Policies/Licensing_Policy and use the headers which are listed at that page.


https://invent.kde.org/sdk/clazy/commit/74686cc8c884dbcfabb12ea7a926e0eec486846d