Debian Codegraph @

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

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 = u'*';
47 QChar c11 = u'*'; // remove the check
48
49 QString s = "aaa";
50 bool b = s.startsWith(u'/');
51
52 s += u'.';
53
54 QString appPrefix = s + u'\\';
55 appPrefix = s + u'\'';
56
57 if (s.at(1) == u'*')
58 b = true;
59
60 QChar quotes[] = { u'"', u'"' };
61 QChar c2 = true ? u'*' : u'/';
62
63 bool myBool = true;
64 QChar c3 = myBool ? (true ? u'*' : u'/') : u'/';
65
66 int i = s.lastIndexOf(u'*');
67
68 const QString sc = "sc";
69 QString s2 = QDir::cleanPath(sc + u'*');
70
71 s2.insert(1, u'*');
72
73
74 receivingQChar(u'/');
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 = u'/';
83 c1 = true ? (true ? u'*' : u'/') : u'*';
84 // nested QLatin1String should not be picked explicitly
85
86 c1 = QLatin1Char(s.startsWith(u"sd"_qs) ? '/' : '*');// 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(u'_') ? '*' : '/');
90 c1 = QLatin1Char(s.startsWith(u"aa"_qs) ?
91 (true ? u'_' : u'_') : u'_');
92 c1 = QLatin1Char(s.startsWith(u'/') ?
93 u'_' : QLatin1Char(s.startsWith(u'_') ? u'*' : u'/'));
94 // Support fixit for the QLatin1Char("_") calls in the above cases
95
96 QString s1 = u"str"_qs;
97 s2 = QString(u"s2"_qs);
98 s1 += u"str"_qs;
99 s1 = true ? u"foo"_qs : u"bar"_qs;
100 s1.append(u"appending"_qs);
101
102 s1 = myBool ? (true ? u"foo"_qs : u"bar"_qs) : u"bar"_qs;
103
104 receivingQString( u"str"_qs);
105 receivingQLatin1String( QLatin1String("latin"));
106
107 QLatin1String totoo = QLatin1String("toto");
108
109 QString sss = u"str"_qs;
110 s1 = true ? (true ? u"foo"_qs : u"bar"_qs) : u"bar"_qs;
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(u'/') ? "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(u"fixme"_qs) ? "foo" : "bar");//
121 s1 = QLatin1String(s.startsWith(u'/') ?
122 QLatin1String(true ? QLatin1String("dontfixme") : QLatin1String("dontfixme")) : QLatin1String("dontfixme"));
123 s1 = QLatin1String(s.startsWith(u'/') ?
124 QLatin1String("foo") : QLatin1String(s.startsWith(u"fixme"_qs) ? "foo" : "bar"));
125
126 QString s2df = "dfg";
127 s1 = QLatin1String(s.startsWith(u'/') ? QLatin1String("dontfix1") : QLatin1String("dontfix2"));
128 s1 = QLatin1String(return_bool(u"fixme"_qs)? QLatin1String("dontfix1") : QLatin1String("dontfix2"));
129 s1 = QLatin1String(s2df.contains(u"caught"_qs)? QLatin1String("dontfix1") : QLatin1String("dontfix2"));
130
131 }
132