Bug 358732

Summary: qstring-uneeded-heap-allocations: fixit changes QString to QLatin1String even if a QString function (sprintf, arg...) on that object
Product: [Developer tools] clazy Reporter: NooN <oo.o+kde>
Component: generalAssignee: Sergio Martins <smartins>
Status: RESOLVED FIXED    
Severity: normal CC: smartins
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Debian testing   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: testcase for QString with sprintf

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