Bug 376737 - clazy-qstring-ref false positive with QVariant
Summary: clazy-qstring-ref false positive with QVariant
Status: RESOLVED FIXED
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: 2017-02-20 21:54 UTC by Elvis Angelaccio
Modified: 2017-03-20 11:24 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Elvis Angelaccio 2017-02-20 21:54:55 UTC
Consider the following line of code:

m_currentArchiveEntry->setProperty("size", line.mid(7).trimmed());

Using midRef() here would not compile (QVariant does not have a constructor that accepts QStringRef objects), yet clazy shows a warning for this line.
Comment 1 Sergio Martins 2017-02-20 23:08:37 UTC
Git commit 17db6590f46d7459868bf54df2ff54ec64e05acd by Sergio Martins.
Committed on 20/02/2017 at 23:08.
Pushed by smartins into branch '1.1'.

qstring-ref: Add a failling unit-test for bug 376737

A  +10   -0    tests/qstring-ref/bug376737.cpp     [License: UNKNOWN]  *
A  +0    -0    tests/qstring-ref/bug376737.cpp.expected
M  +4    -0    tests/qstring-ref/config.json

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


https://commits.kde.org/clazy/17db6590f46d7459868bf54df2ff54ec64e05acd
Comment 2 Sergio Martins 2017-03-04 14:07:08 UTC
Git commit e6931ef2554c5b67e042bd5d1ed03a4bd7e4a19d by Sergio Martins.
Committed on 04/03/2017 at 14:05.
Pushed by smartins into branch '1.1'.

qstring-ref: Don't warn when a QStringRef wouldn't compile

For example when there's an implicit converstion to QVariant

M  +46   -3    src/checks/level0/qstringref.cpp
M  +1    -0    src/checks/level0/qstringref.h
M  +1    -2    tests/qstring-ref/config.json

https://commits.kde.org/clazy/e6931ef2554c5b67e042bd5d1ed03a4bd7e4a19d
Comment 3 Elvis Angelaccio 2017-03-05 18:54:13 UTC
Hi Sergio, I rebuilt clazy with this commit but I'm still getting compilation errors after enabling the fixit. Is code like this supposed to compile?

    const QString attributes = line.midRef(13).trimmed();

(where midRef() was automatically added by the fixit)
Comment 4 Sergio Martins 2017-03-06 21:05:42 UTC
Git commit 68e5be34fc69a9f029d82dfd74beda2244e32701 by Sergio Martins.
Committed on 06/03/2017 at 21:04.
Pushed by smartins into branch '1.1'.

Fix tests not reporting failure

If a unit-test failed to compile it wouldn't report failure.
Now it's evident that qstring-ref has a bug

M  +1    -1    tests/run_tests.py

https://commits.kde.org/clazy/68e5be34fc69a9f029d82dfd74beda2244e32701
Comment 5 Sergio Martins 2017-03-17 18:59:43 UTC
Git commit cc5c8a31449506fb3ca0ccb8066270ad472e473e by Sergio Martins.
Committed on 17/03/2017 at 07:48.
Pushed by smartins into branch '1.1'.

qstring-ref: Fix cases where QStringRef wouldn't compile

trimmed() must be treated like left() and right() because it
also has an "overload" that returns QStringRef

M  +2    -2    src/checks/level0/qstringref.cpp
M  +1    -0    tests/qstring-ref/bug376737.cpp
M  +0    -1    tests/qstring-ref/main.cpp.expected

https://commits.kde.org/clazy/cc5c8a31449506fb3ca0ccb8066270ad472e473e
Comment 6 Elvis Angelaccio 2017-03-19 22:29:30 UTC
I think there are still some issues:

error: no member named 'trimmedRef' in 'QString'; did you mean 'trimmed'?
            if (!m_tempComment.trimmedRef().isEmpty()) {

where trimmedRef() was added by the fix-missing-qstringref fixit:

-            if (!m_comment.trimmed().isEmpty()) {
+            if (!m_comment.trimmedRef().isEmpty()) {
Comment 7 Sergio Martins 2017-03-20 11:24:13 UTC
Git commit a29aac041e1b6a9ad8ed83da9d66254ba8676c33 by Sergio Martins.
Committed on 20/03/2017 at 11:23.
Pushed by smartins into branch '1.1'.

qstring-ref: There's no QString::trimmedRef() method

M  +1    -1    src/checks/level0/qstringref.cpp
M  +4    -0    tests/qstring-ref/bug376737.cpp

https://commits.kde.org/clazy/a29aac041e1b6a9ad8ed83da9d66254ba8676c33