Warning, /sdk/clazy/tests/qt6-qlatin1stringchar-to-u/main.cpp.fixed.expected is written in an unsupported language. File is not indexed.

0001 #include <QtCore/QLatin1Char>
0002 #include <QtCore/QChar>
0003 #include <QtCore/QString>
0004 #include <QtCore/QDir>
0005 //static const type var{QLatin1String(value)};
0006 #define MY_CONSTANT(type, name, value)                \
0007 static const type &name() {                           \
0008     static const type var{QLatin1String(QLatin1String(value))};      \
0009 return var;                                           \
0010 }
0011 #define MY_STRING_CONSTANT(name, value) MY_CONSTANT(QString, name, value)
0012 
0013 MY_STRING_CONSTANT(fooProperty, "foo")
0014 MY_STRING_CONSTANT(barProperty, "bar") // Don't warn
0015 MY_STRING_CONSTANT(bobProperty, QLatin1String(QLatin1String("bob")))
0016 
0017 #define MY_CONSTANT_TEST(type, name, value)                \
0018 static const type &name() {                           \
0019     static const type var{QString(value)};      \
0020 return var;                                           \
0021 }
0022 #define MY_STRING_CONSTANT_TEST(name, value) MY_CONSTANT_TEST(QString, name, value)
0023 MY_STRING_CONSTANT_TEST(bobProperty_test, QLatin1String("bob_test"))
0024 MY_STRING_CONSTANT_TEST(bobProperty_test1, QLatin1String(QLatin1String("bob_test1")))
0025 MY_STRING_CONSTANT_TEST(bobProperty_test2, QLatin1Char(false ? (true ? '*' : '/') : '/'))
0026 #define MY_OTHER_CONSTANT(QString, name, value)                \
0027 static const QString &name() {                           \
0028     static const QString var{QLatin1String(QLatin1String(value))};      \
0029 return var;                                           \
0030 }
0031 
0032 MY_OTHER_CONSTANT(QString, other_test, QLatin1String("otherbob"))
0033 
0034 void receivingQChar(QChar s1) {}
0035 void receivingQLatin1Char(QLatin1Char s1) {}
0036 
0037 void receivingQString(QString s1) {}
0038 void receivingQLatin1String(QLatin1String s1) {}
0039 
0040 bool return_bool(QString si) {return true;}
0041 
0042 #define PREFIXX '*'
0043 #define PREFIX "foo"
0044 void test()
0045 {
0046     QChar c1 = u'*';
0047     QChar c11 = u'*'; // remove the check
0048 
0049     QString s = "aaa";
0050     bool b = s.startsWith(u'/');
0051 
0052     s += u'.';
0053 
0054     QString appPrefix = s + u'\\';
0055     appPrefix = s + u'\'';
0056 
0057     if (s.at(1) == u'*')
0058         b = true;
0059 
0060     QChar quotes[] = { u'"', u'"' };
0061     QChar c2 = true ? u'*' : u'/';
0062 
0063     bool myBool = true;
0064     QChar c3 = myBool ? (true ? u'*' : u'/') : u'/';
0065 
0066     int i = s.lastIndexOf(u'*');
0067 
0068     const QString sc = "sc";
0069     QString s2 = QDir::cleanPath(sc + u'*');
0070 
0071     s2.insert(1, u'*');
0072 
0073 
0074     receivingQChar(u'/');
0075 
0076     receivingQLatin1Char(QLatin1Char('/'));
0077 
0078     QLatin1Char toto = QLatin1Char('/');
0079 
0080     QChar char_with_macro = QLatin1Char(PREFIXX); // should not be fixed
0081 
0082     QChar ccc = u'/';
0083     c1 = true ? (true ? u'*' : u'/') : u'*';
0084     // nested QLatin1String should not be picked explicitly
0085 
0086     c1 = QLatin1Char(s.startsWith(u"sd"_qs) ? '/' : '*');// fix not supported (bool under CXXMemberCallExpr)
0087 
0088     // The outer QLatin1Char fix is not supported, but the inside ones are.
0089     c1 = QLatin1Char(s.startsWith(u'_') ? '*' : '/');
0090     c1 = QLatin1Char(s.startsWith(u"aa"_qs) ?
0091                            (true ? u'_' : u'_') : u'_');
0092     c1 = QLatin1Char(s.startsWith(u'/') ?
0093                            u'_' : QLatin1Char(s.startsWith(u'_') ? u'*' : u'/'));
0094     // Support fixit for the QLatin1Char("_") calls in the above cases
0095 
0096     QString s1 = u"str"_qs;
0097     s2 = QString(u"s2"_qs);
0098     s1 += u"str"_qs;
0099     s1 = true ? u"foo"_qs : u"bar"_qs;
0100     s1.append(u"appending"_qs);
0101 
0102     s1 = myBool ? (true ? u"foo"_qs : u"bar"_qs) : u"bar"_qs;
0103 
0104     receivingQString( u"str"_qs);
0105     receivingQLatin1String( QLatin1String("latin"));
0106 
0107     QLatin1String totoo = QLatin1String("toto");
0108 
0109     QString sss = u"str"_qs;
0110     s1 = true ? (true ? u"foo"_qs : u"bar"_qs) : u"bar"_qs;
0111     // nested QLatin1String should not be picked explicitly
0112 
0113     const char* myChar = "foo";
0114     QString ww = QLatin1String(myChar); // fix not supported
0115     s1 = QLatin1String(myBool ? (true ? "foo" : myChar) : "bar"); // fix not supported (because of myChar)
0116     QString string_with_macro = QLatin1String(PREFIX "bar"); // fix not supported (macro present)
0117     s1 = QLatin1String(s.startsWith(u'/') ? "foo" : "bar");// fix not supported (bool under CXXMemberCallExpr)
0118 
0119     // The outer QLatin1String fix is not supported, but the inside ones are.
0120     s1 = QLatin1String(s.startsWith(u"fixme"_qs) ? "foo" : "bar");//
0121     s1 = QLatin1String(s.startsWith(u'/') ?
0122                            QLatin1String(true ? QLatin1String("dontfixme") : QLatin1String("dontfixme")) : QLatin1String("dontfixme"));
0123     s1 = QLatin1String(s.startsWith(u'/') ?
0124                            QLatin1String("foo") : QLatin1String(s.startsWith(u"fixme"_qs) ? "foo" : "bar"));
0125 
0126     QString s2df = "dfg";
0127     s1 = QLatin1String(s.startsWith(u'/') ? QLatin1String("dontfix1") : QLatin1String("dontfix2"));
0128     s1 = QLatin1String(return_bool(u"fixme"_qs)? QLatin1String("dontfix1") : QLatin1String("dontfix2"));
0129     s1 = QLatin1String(s2df.contains(u"caught"_qs)? QLatin1String("dontfix1") : QLatin1String("dontfix2"));
0130 
0131 }
0132