[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [clazy] /: qstring-uneeded-heap-allocations: Fix wrong usage of QL1S
From: Sergio Martins <smartins () kde ! org>
Date: 2016-01-31 19:01:03
Message-ID: E1aPxF9-0002Un-7D () scm ! kde ! org
[Download RAW message or body]
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.
BUG: 358732
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
diff --git a/checks/qstringuneededheapallocations.cpp \
b/checks/qstringuneededheapallocations.cpp index 3012486..8a61804 100644
--- a/checks/qstringuneededheapallocations.cpp
+++ b/checks/qstringuneededheapallocations.cpp
@@ -220,7 +220,7 @@ void QStringUneededHeapAllocations::VisitCtor(Stmt *stm)
// This is the case of QString("foo"), replace QString
//llvm::errs() << "case1\n";
const bool literalIsEmpty = lt->getLength() == 0;
- if (literalIsEmpty)
+ if (literalIsEmpty && \
HierarchyUtils::getFirstParentOfType<MemberExpr>(m_parentMap, \
ctorExpr) == nullptr)
fixits = fixItReplaceWordWithWord(ctorExpr, \
"QLatin1String", "QString", CharPtrAllocations); else if \
(!ctorExpr->getLocStart().isMacroID())
fixits = fixItReplaceWordWithWord(ctorExpr, \
"QStringLiteral", "QString", CharPtrAllocations);
diff --git a/tests/qstring-uneeded-heap-allocations/main.cpp \
b/tests/qstring-uneeded-heap-allocations/main.cpp index 755117a..2ac959a 100644
--- a/tests/qstring-uneeded-heap-allocations/main.cpp
+++ b/tests/qstring-uneeded-heap-allocations/main.cpp
@@ -210,3 +210,10 @@ void testEmpty()
{
QStringList list = QStringList() << "foo" << "";
}
+
+
+void test_bug358732()
+{
+ QString("foo").sprintf("0x%02X", 0x1E); // Warn and use QSL
+ QString("").sprintf("0x%02X", 0x1E); // Warn and use QSL
+}
diff --git a/tests/qstring-uneeded-heap-allocations/main.cpp.expected \
b/tests/qstring-uneeded-heap-allocations/main.cpp.expected index b98b6b6..75cd084 \
100644
--- a/tests/qstring-uneeded-heap-allocations/main.cpp.expected
+++ b/tests/qstring-uneeded-heap-allocations/main.cpp.expected
@@ -65,3 +65,5 @@ qstring-uneeded-heap-allocations/main.cpp:201:25: warning: Don't \
use QLatin1Stri qstring-uneeded-heap-allocations/main.cpp:201:11: warning: \
QString(QLatin1String) being called [-Wclazy-qstring-uneeded-heap-allocations] \
qstring-uneeded-heap-allocations/main.cpp:211:41: warning: QString(const char*) being \
called [-Wclazy-qstring-uneeded-heap-allocations] \
qstring-uneeded-heap-allocations/main.cpp:211:50: warning: QString(const char*) being \
called [-Wclazy-qstring-uneeded-heap-allocations] \
+qstring-uneeded-heap-allocations/main.cpp:217:5: warning: QString(const char*) being \
called [-Wclazy-qstring-uneeded-heap-allocations] \
+qstring-uneeded-heap-allocations/main.cpp:218:5: warning: QString(const char*) being \
called [-Wclazy-qstring-uneeded-heap-allocations]
diff --git a/tests/qstring-uneeded-heap-allocations/main.cpp_fixed.cpp.expected \
b/tests/qstring-uneeded-heap-allocations/main.cpp_fixed.cpp.expected index \
a02c4dc..650af3e 100644
--- a/tests/qstring-uneeded-heap-allocations/main.cpp_fixed.cpp.expected
+++ b/tests/qstring-uneeded-heap-allocations/main.cpp_fixed.cpp.expected
@@ -210,3 +210,10 @@ void testEmpty()
{
QStringList list = QStringList() << QStringLiteral("foo") << QLatin1String("");
}
+
+
+void test_bug358732()
+{
+ QStringLiteral("foo").sprintf("0x%02X", 0x1E); // Warn and use QSL
+ QStringLiteral("").sprintf("0x%02X", 0x1E); // Warn and use QSL
+}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic