Debian Codegraph @

tests/qt6-qlatin1stringchar-to-u/main.cpp

raw
1 #include <QtCore/QLatin1Char>
2 #include <QtCore/QChar>
3 #include <QtCore/QString>
4 #include <QtCore/QDir>
5 //static const type var{QLatin1String(value)};
6 #define MY_CONSTANT(type, name, value) \
7 static const type &name() { \
8 static const type var{QLatin1String(QLatin1String(value))}; \
9 return var; \
10 }
11 #define MY_STRING_CONSTANT(name, value) MY_CONSTANT(QString, name, value)
12
13 MY_STRING_CONSTANT(fooProperty, "foo")
14 MY_STRING_CONSTANT(barProperty, "bar") // Don't warn
15 MY_STRING_CONSTANT(bobProperty, QLatin1String(QLatin1String("bob")))
16
17 #define MY_CONSTANT_TEST(type, name, value) \
18 static const type &name() { \
19 static const type var{QString(value)}; \
20 return var; \
21 }
22 #define MY_STRING_CONSTANT_TEST(name, value) MY_CONSTANT_TEST(QString, name, value)
23 MY_STRING_CONSTANT_TEST(bobProperty_test, QLatin1String("bob_test"))
24 MY_STRING_CONSTANT_TEST(bobProperty_test1, QLatin1String(QLatin1String("bob_test1")))
25 MY_STRING_CONSTANT_TEST(bobProperty_test2, QLatin1Char(false ? (true ? '*' : '/') : '/'))
26 #define MY_OTHER_CONSTANT(QString, name, value) \
27 static const QString &name() { \
28 static const QString var{QLatin1String(QLatin1String(value))}; \
29 return var; \
30 }
31
32 MY_OTHER_CONSTANT(QString, other_test, QLatin1String("otherbob"))
33
34 void receivingQChar(QChar s1) {}
35 void receivingQLatin1Char(QLatin1Char s1) {}
36
37 void receivingQString(QString s1) {}
38 void receivingQLatin1String(QLatin1String s1) {}
39
40 bool return_bool(QString si) {return true;}
41
42 #define PREFIXX '*'
43 #define PREFIX "foo"
44 void test()
45 {
46 QChar c1 = QLatin1Char('*');
47 QChar c11 = u'*'; // remove the check
48
49 QString s = "aaa";
50 bool b = s.startsWith(QLatin1Char('/'));
51
52 s += QLatin1Char('.');
53
54 QString appPrefix = s + QLatin1Char('\\');
55 appPrefix = s + QLatin1Char('\'');
56
57 if (s.at(1) == QLatin1Char('*'))
58 b = true;
59
60 QChar quotes[] = { QLatin1Char('"'), QLatin1Char('"') };
61 QChar c2 = QLatin1Char(true ? '*' : '/');
62
63 bool myBool = true;
64 QChar c3 = QLatin1Char(myBool ? (true ? '*' : '/') : '/');
65
66 int i = s.lastIndexOf(QLatin1Char('*'));
67
68 const QString sc = "sc";
69 QString s2 = QDir::cleanPath(sc + QLatin1Char('*'));
70
71 s2.insert(1, QLatin1Char('*'));
72
73
74 receivingQChar(QLatin1Char('/'));
75
76 receivingQLatin1Char(QLatin1Char('/'));
77
78 QLatin1Char toto = QLatin1Char('/');
79
80 QChar char_with_macro = QLatin1Char(PREFIXX); // should not be fixed
81
82 QChar ccc = QLatin1Char(QLatin1Char(QLatin1Char('/')));
83 c1 = QLatin1Char(true ? QLatin1Char(true ? '*' : '/') : QLatin1Char('*'));
84 // nested QLatin1String should not be picked explicitly
85
86 c1 = QLatin1Char(s.startsWith(QLatin1String("sd")) ? '/' : '*');// fix not supported (bool under CXXMemberCallExpr)
87
88 // The outer QLatin1Char fix is not supported, but the inside ones are.
89 c1 = QLatin1Char(s.startsWith(QLatin1Char('_')) ? '*' : '/');
90 c1 = QLatin1Char(s.startsWith(QLatin1String(("aa"))) ?
91 QLatin1Char(true ? QLatin1Char('_') : QLatin1Char('_')) : QLatin1Char('_'));
92 c1 = QLatin1Char(s.startsWith(QLatin1Char('/')) ?
93 QLatin1Char('_') : QLatin1Char(s.startsWith(QLatin1Char('_')) ? QLatin1Char('*') : QLatin1Char('/')));
94 // Support fixit for the QLatin1Char("_") calls in the above cases
95
96 QString s1 = QLatin1String("str");
97 s2 = QString(QLatin1String("s2"));
98 s1 += QLatin1String("str");
99 s1 = QLatin1String(true ? "foo" : "bar");
100 s1.append(QLatin1String("appending"));
101
102 s1 = QLatin1String(myBool ? (true ? "foo" : "bar") : "bar");
103
104 receivingQString( QLatin1String("str"));
105 receivingQLatin1String( QLatin1String("latin"));
106
107 QLatin1String totoo = QLatin1String("toto");
108
109 QString sss = QLatin1String(QLatin1String(QLatin1String("str")));
110 s1 = QLatin1String(true ? QLatin1String(true ? "foo" : "bar") : QLatin1String("bar"));
111 // nested QLatin1String should not be picked explicitly
112
113 const char* myChar = "foo";
114 QString ww = QLatin1String(myChar); // fix not supported
115 s1 = QLatin1String(myBool ? (true ? "foo" : myChar) : "bar"); // fix not supported (because of myChar)
116 QString string_with_macro = QLatin1String(PREFIX "bar"); // fix not supported (macro present)
117 s1 = QLatin1String(s.startsWith(QLatin1Char('/')) ? "foo" : "bar");// fix not supported (bool under CXXMemberCallExpr)
118
119 // The outer QLatin1String fix is not supported, but the inside ones are.
120 s1 = QLatin1String(s.startsWith(QLatin1String("fixme")) ? "foo" : "bar");//
121 s1 = QLatin1String(s.startsWith(QLatin1Char('/')) ?
122 QLatin1String(true ? QLatin1String("dontfixme") : QLatin1String("dontfixme")) : QLatin1String("dontfixme"));
123 s1 = QLatin1String(s.startsWith(QLatin1Char('/')) ?
124 QLatin1String("foo") : QLatin1String(s.startsWith(QLatin1String("fixme")) ? "foo" : "bar"));
125
126 QString s2df = "dfg";
127 s1 = QLatin1String(s.startsWith(QLatin1Char('/')) ? QLatin1String("dontfix1") : QLatin1String("dontfix2"));
128 s1 = QLatin1String(return_bool(QLatin1String("fixme"))? QLatin1String("dontfix1") : QLatin1String("dontfix2"));
129 s1 = QLatin1String(s2df.contains(QLatin1String("caught"))? QLatin1String("dontfix1") : QLatin1String("dontfix2"));
130
131 }
132