#include #include #include #include //static const type var{QLatin1String(value)}; #define MY_CONSTANT(type, name, value) \ static const type &name() { \ static const type var{QLatin1String(QLatin1String(value))}; \ return var; \ } #define MY_STRING_CONSTANT(name, value) MY_CONSTANT(QString, name, value) MY_STRING_CONSTANT(fooProperty, "foo") MY_STRING_CONSTANT(barProperty, "bar") // Don't warn MY_STRING_CONSTANT(bobProperty, QLatin1String(QLatin1String("bob"))) #define MY_CONSTANT_TEST(type, name, value) \ static const type &name() { \ static const type var{QString(value)}; \ return var; \ } #define MY_STRING_CONSTANT_TEST(name, value) MY_CONSTANT_TEST(QString, name, value) MY_STRING_CONSTANT_TEST(bobProperty_test, QLatin1String("bob_test")) MY_STRING_CONSTANT_TEST(bobProperty_test1, QLatin1String(QLatin1String("bob_test1"))) MY_STRING_CONSTANT_TEST(bobProperty_test2, QLatin1Char(false ? (true ? '*' : '/') : '/')) #define MY_OTHER_CONSTANT(QString, name, value) \ static const QString &name() { \ static const QString var{QLatin1String(QLatin1String(value))}; \ return var; \ } MY_OTHER_CONSTANT(QString, other_test, QLatin1String("otherbob")) void receivingQChar(QChar s1) {} 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() { QChar c1 = u'*'; QChar c11 = u'*'; // remove the check QString s = "aaa"; bool b = s.startsWith(u'/'); s += u'.'; QString appPrefix = s + u'\\'; appPrefix = s + u'\''; if (s.at(1) == u'*') b = true; QChar quotes[] = { u'"', u'"' }; QChar c2 = true ? u'*' : u'/'; bool myBool = true; QChar c3 = myBool ? (true ? u'*' : u'/') : u'/'; int i = s.lastIndexOf(u'*'); const QString sc = "sc"; QString s2 = QDir::cleanPath(sc + u'*'); s2.insert(1, u'*'); receivingQChar(u'/'); receivingQLatin1Char(QLatin1Char('/')); QLatin1Char toto = QLatin1Char('/'); QChar char_with_macro = QLatin1Char(PREFIXX); // should not be fixed QChar ccc = u'/'; c1 = true ? (true ? u'*' : u'/') : u'*'; // nested QLatin1String should not be picked explicitly 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"_qs) ? (true ? u'_' : u'_') : u'_'); c1 = 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"_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"_qs : u"bar"_qs) : u"bar"_qs; receivingQString( u"str"_qs); receivingQLatin1String( QLatin1String("latin")); QLatin1String totoo = QLatin1String("toto"); 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"; QString ww = QLatin1String(myChar); // fix not supported s1 = QLatin1String(myBool ? (true ? "foo" : myChar) : "bar"); // fix not supported (because of myChar) QString string_with_macro = QLatin1String(PREFIX "bar"); // fix not supported (macro present) 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"_qs) ? "foo" : "bar");// s1 = QLatin1String(s.startsWith(u'/') ? QLatin1String(true ? QLatin1String("dontfixme") : QLatin1String("dontfixme")) : QLatin1String("dontfixme")); s1 = QLatin1String(s.startsWith(u'/') ? 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")); }