diff options
author | Lucie GĂ©rard <lucie.gerard@qt.io> | 2021-09-29 12:08:27 +0200 |
---|---|---|
committer | Sergio Martins <smartins@kde.org> | 2021-10-13 21:59:35 +0000 |
commit | 5cc42e7c22013410470b05c424449d917e6ef1d1 (patch) | |
tree | 01e1d8768297d56de31bcc30251b22ae0b627ccc | |
parent | c93909bf3ca9b9e1bb665ca0e5e33d7f3f2002bb (diff) |
Fix Bug 442729 related to qt6-qlatin1stringchar-to-u fixit
QLatin1String should be replaced with u""_qs instead of u"".
QLatin1String cannot take a u""_qs as argument, or be constructed from it.
Also QLatin1Char cannot be constructed from a u''.
Consequently a fix can only be provided if a QString or QChar trace
has been found.
When a QLatin1Char/String call is found, the type of the parents
or checked in search for a QString or QChar type. In case of looking
for left over QLatin1Char/String calls nested in a
QLatin1Char/String call whose fix is not supported,
the type is looked for on the fly while scanning the
children within the outer QLatin1Char/String call.
-rw-r--r-- | src/checks/manuallevel/qt6-qlatin1stringchar-to-u.cpp | 125 | ||||
-rw-r--r-- | src/checks/manuallevel/qt6-qlatin1stringchar-to-u.h | 8 | ||||
-rw-r--r-- | tests/qt6-qlatin1stringchar-to-u/main.cpp | 14 | ||||
-rw-r--r-- | tests/qt6-qlatin1stringchar-to-u/main.cpp.expected | 110 | ||||
-rw-r--r-- | tests/qt6-qlatin1stringchar-to-u/main.cpp.fixed.expected | 46 |
5 files changed, 210 insertions, 93 deletions
diff --git a/src/checks/manuallevel/qt6-qlatin1stringchar-to-u.cpp b/src/checks/manuallevel/qt6-qlatin1stringchar-to-u.cpp index a67cffc5..957ab40a 100644 --- a/src/checks/manuallevel/qt6-qlatin1stringchar-to-u.cpp +++ b/src/checks/manuallevel/qt6-qlatin1stringchar-to-u.cpp @@ -66,6 +66,61 @@ static bool isQLatin1StringDecl(CXXConstructorDecl *decl) return false; } +bool Qt6QLatin1StringCharToU::foundQCharOrQString(Stmt* stmt) +{ + std::string type; + + CXXOperatorCallExpr* opp = dyn_cast<CXXOperatorCallExpr>(stmt); + CXXConstructExpr* constr = dyn_cast<CXXConstructExpr>(stmt); + CXXMemberCallExpr* memb = dyn_cast<CXXMemberCallExpr>(stmt); + InitListExpr* init = dyn_cast<InitListExpr>(stmt); + CXXFunctionalCastExpr* func = dyn_cast<CXXFunctionalCastExpr>(stmt); + DeclRefExpr* decl = dyn_cast<DeclRefExpr>(stmt); + + if (init) { + type = init->getType().getAsString(); + } else if (opp) { + type = opp->getType().getAsString(); + } else if (constr) { + type = constr->getType().getAsString(); + } else if (decl) { + type = decl->getType().getAsString(); + } else if (func) { + type = func->getType().getAsString(); + }else if (memb) { + Stmt *child = clazy::childAt(stmt, 0); + while (child) { + if (foundQCharOrQString(child)) + return true; + child = clazy::childAt(child, 0); + } + } + + StringRef ttype = type; + if (ttype.contains("class QString") || + ttype.contains("class QChar")) + return true; + return false; + +} + +bool Qt6QLatin1StringCharToU::relatedToQStringOrQChar(Stmt* stmt, const ClazyContext *const context) +{ + if(!stmt) + return false; + + while (stmt) { + + if (foundQCharOrQString(stmt)) + return true; + + stmt = clazy::parent(context->parentMap, stmt); + + } + + return false; +} + /* * To be interesting, the CXXContructExpr: * 1/ must be of class QLatin1String @@ -85,20 +140,33 @@ bool Qt6QLatin1StringCharToU::isInterestingCtorCall(CXXConstructExpr *ctorExpr, if (!parent_stmt) return false; bool oneFunctionalCast = false; - // A given QLatin1Char call will have two ctorExpr passing the isQLatin1CharDecl - // To avoid creating multiple fixit in case of nested QLatin1String calls - // it is important to only test the one right after a CXXFunctionalCastExpr with QLatin1String name + // A given QLatin1Char/String call will have two ctorExpr passing the isQLatin1CharDecl/StringDecl + // To avoid creating multiple fixit in case of nested QLatin1Char/String calls + // it is important to only test the one right after a CXXFunctionalCastExpr with QLatin1Char/String name if (isa<CXXFunctionalCastExpr>(parent_stmt)) { CXXFunctionalCastExpr* parent = dyn_cast<CXXFunctionalCastExpr>(parent_stmt); if (parent->getConversionFunction()->getNameAsString() != "QLatin1Char" && parent->getConversionFunction()->getNameAsString() != "QLatin1String") { return false; } else { + + // need to check that this call is related to a QString or a QChar + if (check_parent) + m_QStringOrQChar_fix = relatedToQStringOrQChar(parent_stmt, context); + // in case of looking for left over, we don't do it here, because might go past the QLatin1Char/String we are nested in + // and replace the one within + // QString toto = QLatin1String ( something_not_supported ? QLatin1String("should not be corrected") : "toto" ) + // the inside one should not be corrected because the outside QLatin1String is staying. + if (parent->getConversionFunction()->getNameAsString() == "QLatin1Char") + m_QChar = true; + else + m_QChar = false; + oneFunctionalCast = true; } } - // Not checking the parent when looking for left over QLatin1String call nested in a QLatin1String call not supporting fixit + // Not checking the parent when looking for left over QLatin1String call nested in a QLatin1String whose fix is not supported if (!check_parent) return oneFunctionalCast; @@ -113,6 +181,7 @@ bool Qt6QLatin1StringCharToU::isInterestingCtorCall(CXXConstructExpr *ctorExpr, NamedDecl *ndecl = parent->getConversionFunction(); if (ndecl) { if (ndecl->getNameAsString() == "QLatin1Char" || ndecl->getNameAsString() == "QLatin1String") { + if (parent_stmt->getBeginLoc().isMacroID()) { auto parent_stmt_begin = parent_stmt->getBeginLoc(); auto parent_stmt_end = parent_stmt->getEndLoc(); @@ -125,6 +194,7 @@ bool Qt6QLatin1StringCharToU::isInterestingCtorCall(CXXConstructExpr *ctorExpr, return oneFunctionalCast; } } + return false; } } @@ -151,10 +221,10 @@ void Qt6QLatin1StringCharToU::VisitStmt(clang::Stmt *stmt) auto ctorExpr = dyn_cast<CXXConstructExpr>(stmt); if (!ctorExpr) return; + m_QStringOrQChar_fix = false; if (!isInterestingCtorCall(ctorExpr, m_context, true)) return; - vector<FixItHint> fixits; string message; @@ -165,6 +235,11 @@ void Qt6QLatin1StringCharToU::VisitStmt(clang::Stmt *stmt) return; } } + if (!m_QStringOrQChar_fix) { + message = "QLatin1Char or QLatin1String is being called (fix it not supported)"; + emitWarning(clazy::getLocStart(stmt), message, fixits); + return; + } checkCTorExpr(stmt, true); } @@ -178,8 +253,8 @@ bool Qt6QLatin1StringCharToU::checkCTorExpr(clang::Stmt *stmt, bool check_parent vector<FixItHint> fixits; string message; - // parents are not check when looking inside a QLatin1Char that does not support fixes - // extra paratheses might be needed for the inner QLatin1Char fix + // parents are not checked when looking inside a QLatin1Char/String that does not support fixes + // extra paratheses might be needed for the inner QLatin1Char/String fix bool extra_parentheses = !check_parents; bool noFix = false; @@ -206,6 +281,7 @@ bool Qt6QLatin1StringCharToU::checkCTorExpr(clang::Stmt *stmt, bool check_parent return true; } + std::string replacement = buildReplacement(stmt, noFix, extra_parentheses); if (!noFix) { fixits.push_back(FixItHint::CreateReplacement(stmt->getSourceRange(), replacement)); @@ -218,23 +294,41 @@ bool Qt6QLatin1StringCharToU::checkCTorExpr(clang::Stmt *stmt, bool check_parent emitWarning(warningLocation, message, fixits); if (noFix) { - lookForLeftOver(stmt); + m_QChar_noFix = m_QChar; // because QLatin1Char with QLatin1Char whose fix is unsupported should be corrected + // unlike QLatin1String + lookForLeftOver(stmt,m_QChar); } return true; } -void Qt6QLatin1StringCharToU::lookForLeftOver(clang::Stmt *stmt, bool keep_looking) +void Qt6QLatin1StringCharToU::lookForLeftOver(clang::Stmt *stmt, bool found_QString_QChar) { Stmt *current_stmt = stmt; + bool keep_looking = true; + // remebering the QString or QChar trace from the other sibbling in case of CXXMemberCallExpr + // in order to catch QLatin1String("notcaught") in the following exemple + // s1 = QLatin1String(s2df.contains(QLatin1String("notcaught"))? QLatin1String("dontfix1") : QLatin1String("dontfix2")); + bool remember = false; + if(isa<CXXMemberCallExpr>(current_stmt)) + remember = true; for (auto it = current_stmt->child_begin() ; it !=current_stmt->child_end() ; it++) { - Stmt *child = *it; - // if QLatin1Char is found, stop looking into children of current child - // the QLatin1Char calls present there, if any, will be caught - keep_looking = !checkCTorExpr(child, false); + + // here need to make sure a QChar or QString type is present between the first current_stmt and the one we are testing + // should not check the parents because we might go past the QLatin1String or QLatin1Char whose fix was not supported + if (!found_QString_QChar) + found_QString_QChar = foundQCharOrQString(child); + + // if no QString or QChar signature as been found, no point to check for QLatin1String or QLatin1Char to correct. + if (found_QString_QChar) + keep_looking = !checkCTorExpr(child, false);// if QLatin1Char/String is found, stop looking into children of current child + // the QLatin1Char/String calls present there, if any, will be caught if (keep_looking) - lookForLeftOver(child, keep_looking); + lookForLeftOver(child, found_QString_QChar); + + if (!remember) + found_QString_QChar = m_QChar_noFix; } } @@ -280,6 +374,7 @@ std::string Qt6QLatin1StringCharToU::buildReplacement(clang::Stmt *stmt, bool &n replacement += "u\""; replacement += child_stringliteral->getString(); replacement += "\""; + replacement += "_qs"; } else if (child_charliteral) { replacement += "u\'"; if (child_charliteral->getValue() == 92 || child_charliteral->getValue() == 39) @@ -295,7 +390,7 @@ std::string Qt6QLatin1StringCharToU::buildReplacement(clang::Stmt *stmt, bool &n replacement += child_declRefExp->getNameInfo().getAsString(); replacement += " ? "; } else { - // not supporting those cases + //not supporting those cases noFix = true; return {}; } diff --git a/src/checks/manuallevel/qt6-qlatin1stringchar-to-u.h b/src/checks/manuallevel/qt6-qlatin1stringchar-to-u.h index 54bd933d..8a418add 100644 --- a/src/checks/manuallevel/qt6-qlatin1stringchar-to-u.h +++ b/src/checks/manuallevel/qt6-qlatin1stringchar-to-u.h @@ -59,11 +59,17 @@ private: std::vector<clang::SourceLocation> m_emittedWarningsInMacro; bool warningAlreadyEmitted(clang::SourceLocation sploc); bool checkCTorExpr(clang::Stmt *stmt, bool check_parents); - void lookForLeftOver(clang::Stmt *stmt, bool keep_looking = true); + void lookForLeftOver(clang::Stmt *stmt, bool found_QString_QChar = false); std::string buildReplacement(clang::Stmt *stmt, bool &noFix, bool extra = false, bool ancestorIsCondition = false, int ancestorConditionChildNumber = 0); bool isInterestingCtorCall(clang::CXXConstructExpr *ctorExpr, const ClazyContext *const context, bool check_parent = true); + bool relatedToQStringOrQChar(clang::Stmt* stmt, const ClazyContext *const context); + bool foundQCharOrQString(clang::Stmt* stmt); + + bool m_QStringOrQChar_fix = false; + bool m_QChar = false; + bool m_QChar_noFix = false; }; diff --git a/tests/qt6-qlatin1stringchar-to-u/main.cpp b/tests/qt6-qlatin1stringchar-to-u/main.cpp index b82d9260..50dafbe8 100644 --- a/tests/qt6-qlatin1stringchar-to-u/main.cpp +++ b/tests/qt6-qlatin1stringchar-to-u/main.cpp @@ -37,6 +37,8 @@ void receivingQLatin1Char(QLatin1Char s1) {} void receivingQString(QString s1) {} void receivingQLatin1String(QLatin1String s1) {} +bool return_bool(QString si) {return true;} + #define PREFIXX '*' #define PREFIX "foo" void test() @@ -88,7 +90,7 @@ void test() c1 = QLatin1Char(s.startsWith(QLatin1String(("aa"))) ? QLatin1Char(true ? QLatin1Char('_') : QLatin1Char('_')) : QLatin1Char('_')); c1 = QLatin1Char(s.startsWith(QLatin1Char('/')) ? - QLatin1Char('_') : QLatin1Char(s.startsWith(QLatin1Char('_')) ? '*' : '/')); + QLatin1Char('_') : QLatin1Char(s.startsWith(QLatin1Char('_')) ? QLatin1Char('*') : QLatin1Char('/'))); // Support fixit for the QLatin1Char("_") calls in the above cases QString s1 = QLatin1String("str"); @@ -117,10 +119,14 @@ void test() // The outer QLatin1String fix is not supported, but the inside ones are. s1 = QLatin1String(s.startsWith(QLatin1String("fixme")) ? "foo" : "bar");// s1 = QLatin1String(s.startsWith(QLatin1Char('/')) ? - QLatin1String(true ? QLatin1String("fixme") : QLatin1String("fixme")) : QLatin1String("fixme")); + QLatin1String(true ? QLatin1String("dontfixme") : QLatin1String("dontfixme")) : QLatin1String("dontfixme")); s1 = QLatin1String(s.startsWith(QLatin1Char('/')) ? - QLatin1Literal("fixme") : QLatin1String(s.startsWith(QLatin1String("fixme")) ? "foo" : "bar")); - // Support fixit for the QLatin1Literal("fixme") calls in the above cases + QLatin1String("foo") : QLatin1String(s.startsWith(QLatin1String("fixme")) ? "foo" : "bar")); + + QString s2df = "dfg"; + s1 = QLatin1String(s.startsWith(QLatin1Char('/')) ? QLatin1String("dontfix1") : QLatin1String("dontfix2")); + s1 = QLatin1String(return_bool(QLatin1String("fixme"))? QLatin1String("dontfix1") : QLatin1String("dontfix2")); + s1 = QLatin1String(s2df.contains(QLatin1String("caught"))? QLatin1String("dontfix1") : QLatin1String("dontfix2")); } diff --git a/tests/qt6-qlatin1stringchar-to-u/main.cpp.expected b/tests/qt6-qlatin1stringchar-to-u/main.cpp.expected index 93d53bc6..d2669536 100644 --- a/tests/qt6-qlatin1stringchar-to-u/main.cpp.expected +++ b/tests/qt6-qlatin1stringchar-to-u/main.cpp.expected @@ -5,62 +5,66 @@ qt6-qlatin1stringchar-to-u/main.cpp:24:44: warning: QLatin1Char or QLatin1String qt6-qlatin1stringchar-to-u/main.cpp:25:44: warning: QLatin1Char or QLatin1String is being called in macro MY_STRING_CONSTANT_TEST. Please replace with `u` call manually. [-Wclazy-qt6-qlatin1stringchar-to-u] qt6-qlatin1stringchar-to-u/main.cpp:28:30: warning: QLatin1Char or QLatin1String is being called in macro MY_OTHER_CONSTANT. Please replace with `u` call manually. [-Wclazy-qt6-qlatin1stringchar-to-u] qt6-qlatin1stringchar-to-u/main.cpp:32:40: warning: QLatin1Char or QLatin1String is being called in macro MY_OTHER_CONSTANT. Please replace with `u` call manually. [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:44:16: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:48:27: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:50:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:52:29: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:53:21: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:55:20: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:58:24: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:58:42: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:59:16: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:62:16: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:64:27: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:67:39: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:69:18: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:72:20: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:74:26: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:76:24: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:78:29: warning: QLatin1Char or QLatin1String is being called (fix it not supported because of macro) [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:80:17: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:81:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:84:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:84:35: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:87:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:87:35: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:88:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:88:35: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:89:28: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:89:86: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:46:16: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:50:27: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:52:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:54:29: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:55:21: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:57:20: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:60:24: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:60:42: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:61:16: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:64:16: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:66:27: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:69:39: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:71:18: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:74:20: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:76:26: warning: QLatin1Char or QLatin1String is being called (fix it not supported) [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:78:24: warning: QLatin1Char or QLatin1String is being called (fix it not supported) [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:80:29: warning: QLatin1Char or QLatin1String is being called (fix it not supported because of macro) [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:82:17: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:83:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:86:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:86:35: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:89:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:89:35: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] qt6-qlatin1stringchar-to-u/main.cpp:90:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] qt6-qlatin1stringchar-to-u/main.cpp:90:35: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] qt6-qlatin1stringchar-to-u/main.cpp:91:28: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:91:47: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:91:72: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:94:18: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:95:18: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:96:11: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:97:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:98:15: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:100:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:102:23: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:103:29: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:105:27: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:107:19: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:108:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:112:18: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:113:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:114:33: warning: QLatin1Char or QLatin1String is being called (fix it not supported because of macro) [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:91:86: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:92:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:92:35: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:93:28: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:93:47: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:93:72: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:93:92: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:93:111: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:96:18: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:97:18: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:98:11: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:99:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:100:15: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:102:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:104:23: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:105:29: warning: QLatin1Char or QLatin1String is being called (fix it not supported) [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:107:27: warning: QLatin1Char or QLatin1String is being called (fix it not supported) [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:109:19: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:110:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:114:18: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] qt6-qlatin1stringchar-to-u/main.cpp:115:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:115:37: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:118:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:118:37: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:119:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:119:37: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:120:28: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:120:100: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:116:33: warning: QLatin1Char or QLatin1String is being called (fix it not supported because of macro) [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:117:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:117:37: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:120:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:120:37: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] qt6-qlatin1stringchar-to-u/main.cpp:121:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] qt6-qlatin1stringchar-to-u/main.cpp:121:37: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:122:28: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:122:54: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] -qt6-qlatin1stringchar-to-u/main.cpp:122:81: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:123:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:123:37: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:124:78: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:127:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:127:37: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:128:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:128:36: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:129:10: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] +qt6-qlatin1stringchar-to-u/main.cpp:129:38: warning: QLatin1Char or QLatin1String is being called [-Wclazy-qt6-qlatin1stringchar-to-u] diff --git a/tests/qt6-qlatin1stringchar-to-u/main.cpp.fixed.expected b/tests/qt6-qlatin1stringchar-to-u/main.cpp.fixed.expected index e2cd1e68..543dac68 100644 --- a/tests/qt6-qlatin1stringchar-to-u/main.cpp.fixed.expected +++ b/tests/qt6-qlatin1stringchar-to-u/main.cpp.fixed.expected @@ -37,6 +37,8 @@ void receivingQLatin1Char(QLatin1Char s1) {} void receivingQString(QString s1) {} void receivingQLatin1String(QLatin1String s1) {} +bool return_bool(QString si) {return true;} + #define PREFIXX '*' #define PREFIX "foo" void test() @@ -71,9 +73,9 @@ void test() receivingQChar(u'/'); - receivingQLatin1Char(u'/'); + receivingQLatin1Char(QLatin1Char('/')); - QLatin1Char toto = u'/'; + QLatin1Char toto = QLatin1Char('/'); QChar char_with_macro = QLatin1Char(PREFIXX); // should not be fixed @@ -81,31 +83,31 @@ void test() c1 = true ? (true ? u'*' : u'/') : u'*'; // nested QLatin1String should not be picked explicitly - c1 = QLatin1Char(s.startsWith(u"sd") ? '/' : '*');// fix not supported (bool under CXXMemberCallExpr) + c1 = QLatin1Char(s.startsWith(u"sd"_qs) ? '/' : '*');// fix not supported (bool under CXXMemberCallExpr) // The outer QLatin1Char fix is not supported, but the inside ones are. c1 = QLatin1Char(s.startsWith(u'_') ? '*' : '/'); - c1 = QLatin1Char(s.startsWith(u"aa") ? + c1 = QLatin1Char(s.startsWith(u"aa"_qs) ? (true ? u'_' : u'_') : u'_'); c1 = QLatin1Char(s.startsWith(u'/') ? - u'_' : QLatin1Char(s.startsWith(u'_') ? '*' : '/')); + u'_' : QLatin1Char(s.startsWith(u'_') ? u'*' : u'/')); // Support fixit for the QLatin1Char("_") calls in the above cases - QString s1 = u"str"; - s2 = QString(u"s2"); - s1 += u"str"; - s1 = true ? u"foo" : u"bar"; - s1.append(u"appending"); + QString s1 = u"str"_qs; + s2 = QString(u"s2"_qs); + s1 += u"str"_qs; + s1 = true ? u"foo"_qs : u"bar"_qs; + s1.append(u"appending"_qs); - s1 = myBool ? (true ? u"foo" : u"bar") : u"bar"; + s1 = myBool ? (true ? u"foo"_qs : u"bar"_qs) : u"bar"_qs; - receivingQString( u"str"); - receivingQLatin1String( u"latin"); + receivingQString( u"str"_qs); + receivingQLatin1String( QLatin1String("latin")); - QLatin1String totoo = u"toto"; + QLatin1String totoo = QLatin1String("toto"); - QString sss = u"str"; - s1 = true ? (true ? u"foo" : u"bar") : u"bar"; + QString sss = u"str"_qs; + s1 = true ? (true ? u"foo"_qs : u"bar"_qs) : u"bar"_qs; // nested QLatin1String should not be picked explicitly const char* myChar = "foo"; @@ -115,12 +117,16 @@ void test() s1 = QLatin1String(s.startsWith(u'/') ? "foo" : "bar");// fix not supported (bool under CXXMemberCallExpr) // The outer QLatin1String fix is not supported, but the inside ones are. - s1 = QLatin1String(s.startsWith(u"fixme") ? "foo" : "bar");// + s1 = QLatin1String(s.startsWith(u"fixme"_qs) ? "foo" : "bar");// s1 = QLatin1String(s.startsWith(u'/') ? - (true ? u"fixme" : u"fixme") : u"fixme"); + QLatin1String(true ? QLatin1String("dontfixme") : QLatin1String("dontfixme")) : QLatin1String("dontfixme")); s1 = QLatin1String(s.startsWith(u'/') ? - u"fixme" : QLatin1String(s.startsWith(u"fixme") ? "foo" : "bar")); - // Support fixit for the QLatin1Literal("fixme") calls in the above cases + QLatin1String("foo") : QLatin1String(s.startsWith(u"fixme"_qs) ? "foo" : "bar")); + + QString s2df = "dfg"; + s1 = QLatin1String(s.startsWith(u'/') ? QLatin1String("dontfix1") : QLatin1String("dontfix2")); + s1 = QLatin1String(return_bool(u"fixme"_qs)? QLatin1String("dontfix1") : QLatin1String("dontfix2")); + s1 = QLatin1String(s2df.contains(u"caught"_qs)? QLatin1String("dontfix1") : QLatin1String("dontfix2")); } |