diff options
Diffstat (limited to 'src/checks/level2/qstring-allocations.cpp')
-rw-r--r-- | src/checks/level2/qstring-allocations.cpp | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/src/checks/level2/qstring-allocations.cpp b/src/checks/level2/qstring-allocations.cpp index 5f391f8b..34c0baf1 100644 --- a/src/checks/level2/qstring-allocations.cpp +++ b/src/checks/level2/qstring-allocations.cpp @@ -251,7 +251,7 @@ void QStringAllocations::VisitCtor(Stmt *stm) } } - emitWarning(clazy::getLocStart(stm), msg, fixits); + maybeEmitWarning(clazy::getLocStart(stm), msg, fixits); } else { vector<FixItHint> fixits; if (clazy::hasChildren(ctorExpr)) { @@ -293,7 +293,7 @@ void QStringAllocations::VisitCtor(Stmt *stm) } } - emitWarning(clazy::getLocStart(stm), msg, fixits); + maybeEmitWarning(clazy::getLocStart(stm), msg, fixits); } } @@ -302,7 +302,7 @@ vector<FixItHint> QStringAllocations::fixItReplaceWordWithWord(clang::Stmt *begi StringLiteral *lt = stringLiteralForCall(begin); if (replacee == "QLatin1String") { if (lt && !Utils::isAscii(lt)) { - emitWarning(clazy::getLocStart(lt), "Don't use QLatin1String with non-latin1 literals"); + maybeEmitWarning(clazy::getLocStart(lt), "Don't use QLatin1String with non-latin1 literals"); return {}; } } @@ -517,7 +517,7 @@ void QStringAllocations::VisitOperatorCall(Stmt *stm) } string msg = string("QString(const char*) being called"); - emitWarning(clazy::getLocStart(stm), msg, fixits); + maybeEmitWarning(clazy::getLocStart(stm), msg, fixits); } void QStringAllocations::VisitFromLatin1OrUtf8(Stmt *stmt) @@ -552,7 +552,7 @@ void QStringAllocations::VisitFromLatin1OrUtf8(Stmt *stmt) if (!ternaries.empty()) { auto ternary = ternaries[0]; if (Utils::ternaryOperatorIsOfStringLiteral(ternary)) { - emitWarning(clazy::getLocStart(stmt), string("QString::fromLatin1() being passed a literal")); + maybeEmitWarning(clazy::getLocStart(stmt), string("QString::fromLatin1() being passed a literal")); } return; @@ -566,9 +566,9 @@ void QStringAllocations::VisitFromLatin1OrUtf8(Stmt *stmt) } if (clazy::name(functionDecl) == "fromLatin1") { - emitWarning(clazy::getLocStart(stmt), string("QString::fromLatin1() being passed a literal"), fixits); + maybeEmitWarning(clazy::getLocStart(stmt), string("QString::fromLatin1() being passed a literal"), fixits); } else { - emitWarning(clazy::getLocStart(stmt), string("QString::fromUtf8() being passed a literal"), fixits); + maybeEmitWarning(clazy::getLocStart(stmt), string("QString::fromUtf8() being passed a literal"), fixits); } } @@ -594,5 +594,10 @@ void QStringAllocations::VisitAssignOperatorQLatin1String(Stmt *stmt) : fixItReplaceWordWithWordInTernary(ternary); } - emitWarning(clazy::getLocStart(stmt), string("QString::operator=(QLatin1String(\"literal\")"), fixits); + maybeEmitWarning(clazy::getLocStart(stmt), string("QString::operator=(QLatin1String(\"literal\")"), fixits); +} + +void QStringAllocations::maybeEmitWarning(SourceLocation loc, string error, const std::vector<FixItHint> &fixits) +{ + emitWarning(loc, error, fixits); } |