Bug 393039

Summary: Warn about using QStringLiteral for empty strings
Product: [Developer tools] clazy Reporter: Roman <dismine>
Component: generalAssignee: Sergio Martins <smartins>
Status: RESOLVED FIXED    
Severity: wishlist CC: smartins
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:

Description Roman 2018-04-12 11:11:32 UTC
According to this article http://blog.qt.io/blog/2014/06/13/qt-weekly-13-qstringliteral/ it's not recommended to use QStringLiteral for empty strings.

> Do not use QStringLiteral for empty strings.
> Prefer QString() over QStringLiteral("")
> The default constructor for QString is cheaper in terms of both instructions and memory.

QStringLiteral() seems to also works.

Hope this information is still relevant.
Comment 1 Sergio Martins 2018-08-15 20:45:08 UTC
Git commit ca3d44ebbfe588746e662d28b92eb2a78f442303 by Sergio Martins.
Committed on 15/08/2018 at 20:44.
Pushed by smartins into branch 'master'.

Introduce empty-qstringliteral

Suggests to use QString instead of an empty QStringLiteral().

M  +1    -0    Changelog
M  +1    -0    CheckSources.cmake
M  +1    -0    README.md
M  +6    -0    checks.json
A  +6    -0    docs/checks/README-empty-qstringliteral.md
M  +1    -0    readmes.cmake
M  +2    -0    src/Checks.h
A  +63   -0    src/checks/level0/empty-qstringliteral.cpp     [License: LGPL (v2+)]
A  +38   -0    src/checks/level0/empty-qstringliteral.h     [License: LGPL (v2+)]
M  +17   -16   tests/clazy/test_requested_checks.sh.expected
A  +7    -0    tests/empty-qstringliteral/config.json
A  +11   -0    tests/empty-qstringliteral/main.cpp     [License: UNKNOWN]  *
A  +3    -0    tests/empty-qstringliteral/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://commits.kde.org/clazy/ca3d44ebbfe588746e662d28b92eb2a78f442303