File indexing completed on 2024-05-05 05:41:39

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 = QLatin1Char('*');
0047     QChar c11 = u'*'; // remove the check
0048 
0049     QString s = "aaa";
0050     bool b = s.startsWith(QLatin1Char('/'));
0051 
0052     s += QLatin1Char('.');
0053 
0054     QString appPrefix = s + QLatin1Char('\\');
0055     appPrefix = s + QLatin1Char('\'');
0056 
0057     if (s.at(1) == QLatin1Char('*'))
0058         b = true;
0059 
0060     QChar quotes[] = { QLatin1Char('"'), QLatin1Char('"') };
0061     QChar c2 = QLatin1Char(true ? '*' : '/');
0062 
0063     bool myBool = true;
0064     QChar c3 = QLatin1Char(myBool ? (true ? '*' : '/') : '/');
0065 
0066     int i = s.lastIndexOf(QLatin1Char('*'));
0067 
0068     const QString sc = "sc";
0069     QString s2 = QDir::cleanPath(sc + QLatin1Char('*'));
0070 
0071     s2.insert(1, QLatin1Char('*'));
0072 
0073 
0074     receivingQChar(QLatin1Char('/'));
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 = QLatin1Char(QLatin1Char(QLatin1Char('/')));
0083     c1 = QLatin1Char(true ? QLatin1Char(true ? '*' : '/') : QLatin1Char('*'));
0084     // nested QLatin1String should not be picked explicitly
0085 
0086     c1 = QLatin1Char(s.startsWith(QLatin1String("sd")) ? '/' : '*');// 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(QLatin1Char('_')) ? '*' : '/');
0090     c1 = QLatin1Char(s.startsWith(QLatin1String(("aa"))) ?
0091                            QLatin1Char(true ? QLatin1Char('_') : QLatin1Char('_')) : QLatin1Char('_'));
0092     c1 = QLatin1Char(s.startsWith(QLatin1Char('/')) ?
0093                            QLatin1Char('_') : QLatin1Char(s.startsWith(QLatin1Char('_')) ? QLatin1Char('*') : QLatin1Char('/')));
0094     // Support fixit for the QLatin1Char("_") calls in the above cases
0095 
0096     QString s1 = QLatin1String("str");
0097     s2 = QString(QLatin1String("s2"));
0098     s1 += QLatin1String("str");
0099     s1 = QLatin1String(true ? "foo" : "bar");
0100     s1.append(QLatin1String("appending"));
0101 
0102     s1 = QLatin1String(myBool ? (true ? "foo" : "bar") : "bar");
0103 
0104     receivingQString( QLatin1String("str"));
0105     receivingQLatin1String( QLatin1String("latin"));
0106 
0107     QLatin1String totoo = QLatin1String("toto");
0108 
0109     QString sss = QLatin1String(QLatin1String(QLatin1String("str")));
0110     s1 = QLatin1String(true ? QLatin1String(true ? "foo" : "bar") : QLatin1String("bar"));
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(QLatin1Char('/')) ? "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(QLatin1String("fixme")) ? "foo" : "bar");//
0121     s1 = QLatin1String(s.startsWith(QLatin1Char('/')) ?
0122                            QLatin1String(true ? QLatin1String("dontfixme") : QLatin1String("dontfixme")) : QLatin1String("dontfixme"));
0123     s1 = QLatin1String(s.startsWith(QLatin1Char('/')) ?
0124                            QLatin1String("foo") : QLatin1String(s.startsWith(QLatin1String("fixme")) ? "foo" : "bar"));
0125 
0126     QString s2df = "dfg";
0127     s1 = QLatin1String(s.startsWith(QLatin1Char('/')) ? QLatin1String("dontfix1") : QLatin1String("dontfix2"));
0128     s1 = QLatin1String(return_bool(QLatin1String("fixme"))? QLatin1String("dontfix1") : QLatin1String("dontfix2"));
0129     s1 = QLatin1String(s2df.contains(QLatin1String("caught"))? QLatin1String("dontfix1") : QLatin1String("dontfix2"));
0130 
0131 }
0132