Bug 358732 - qstring-uneeded-heap-allocations: fixit changes QString to QLatin1String even if a QString function (sprintf, arg...) on that object
Summary: qstring-uneeded-heap-allocations: fixit changes QString to QLatin1String even...
Status: RESOLVED FIXED
Alias: None
Product: clazy
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: Debian testing Linux
: NOR normal
Target Milestone: ---
Assignee: Sergio Martins
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-29 13:00 UTC by NooN
Modified: 2016-01-31 19:01 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
testcase for QString with sprintf (414 bytes, application/x-7z-compressed)
2016-01-29 13:00 UTC, NooN
Details

Note You need to log in before you can comment on or make changes to this bug.
Description NooN 2016-01-29 13:00:10 UTC
Created attachment 96901 [details]
testcase for QString with sprintf

If a QString is created and a function of that object get's called ist must not be converted to a QLatin1String.
That class has only a minimal set of functions and for example arg or sprintf is not supported.

testcase_qstring.cpp:21:5: warning: QString(const char*) being called [-Wclazy-qstring-uneeded-heap-allocations]
    QString("").sprintf("0x%02X", 0x1E);

If the (automatic) fixit get applied there is than a no member error.

testcase_with_fixit.cpp:21:23: error: no member named 'sprintf' in 'QLatin1String'
    QLatin1String("").sprintf("0x%02X", 0x1E);
Comment 1 Sergio Martins 2016-01-31 19:01:04 UTC
Git commit 2d119b58204d2357ed418077e3780afa8415ed6a by Sergio Martins.
Committed on 31/01/2016 at 18:59.
Pushed by smartins into branch 'master'.

qstring-uneeded-heap-allocations: Fix wrong usage of QL1S

QString("").sprintf() can't be replaced with QL1S, only QSL.

M  +1    -1    checks/qstringuneededheapallocations.cpp
M  +7    -0    tests/qstring-uneeded-heap-allocations/main.cpp
M  +2    -0    tests/qstring-uneeded-heap-allocations/main.cpp.expected
M  +7    -0    tests/qstring-uneeded-heap-allocations/main.cpp_fixed.cpp.expected

http://commits.kde.org/clazy/2d119b58204d2357ed418077e3780afa8415ed6a