Debian Codegraph @

tests/auto/linguist/lupdate/testdata/good/parsecpp_attributes/main.cpp

raw
1 // Copyright (C) 2025 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 #include <QObject>
5
6 // ============================================================================
7 // CLASS ATTRIBUTES - Basic Cases
8 // ============================================================================
9
10 // Test 1: Basic attribute (original QTBUG-140686 bug report)
11 class [[maybe_unused]] AttributeTest1 : public QObject
12 {
13 Q_OBJECT
14 public:
15 void foo() { tr("AttributeTest1: basic attribute"); }
16 };
17
18 // Test 2: Multiple attributes
19 class [[deprecated]] [[nodiscard]] AttributeTest2 : public QObject
20 {
21 Q_OBJECT
22 public:
23 void foo() { tr("AttributeTest2: multiple attributes"); }
24 };
25
26 // Test 3: Attribute with string argument
27 class [[deprecated("Use NewClass instead")]] AttributeTest3 : public QObject
28 {
29 Q_OBJECT
30 public:
31 void foo() { tr("AttributeTest3: string argument"); }
32 };
33
34 // ============================================================================
35 // CLASS ATTRIBUTES - Edge Cases with Nested Brackets
36 // ============================================================================
37
38 // Test 4: Attribute with string containing brackets
39 class [[deprecated("Use Array[5] instead")]] AttributeTest4 : public QObject
40 {
41 Q_OBJECT
42 public:
43 void foo() { tr("AttributeTest4: brackets in string"); }
44 };
45
46 // Test 5: Attribute with nested brackets in string
47 class [[deprecated("Use Container[items[0]] instead")]] AttributeTest5 : public QObject
48 {
49 Q_OBJECT
50 public:
51 void foo() { tr("AttributeTest5: nested brackets in string"); }
52 };
53
54 // Test 6: Attribute with double closing brackets [[]] in string
55 class [[deprecated("Old [[syntax]] is bad")]] AttributeTest6 : public QObject
56 {
57 Q_OBJECT
58 public:
59 void foo() { tr("AttributeTest6: double brackets in string"); }
60 };
61
62 // Test 7: String with single closing bracket character
63 class [[deprecated("]")]] AttributeTest7 : public QObject
64 {
65 Q_OBJECT
66 public:
67 void foo() { tr("AttributeTest7: single bracket character"); }
68 };
69
70 // Test 8: Attribute with escaped quotes and brackets
71 class [[deprecated("Use \"NewClass[2]\" instead")]] AttributeTest8 : public QObject
72 {
73 Q_OBJECT
74 public:
75 void foo() { tr("AttributeTest8: escaped quotes with brackets"); }
76 };
77
78 // ============================================================================
79 // CLASS ATTRIBUTES - Raw String Literals
80 // ============================================================================
81
82 // Test 9: Attribute with raw string literal
83 class [[deprecated(R"(Use "Array[5]" instead)")]] AttributeTest9 : public QObject
84 {
85 Q_OBJECT
86 public:
87 void foo() { tr("AttributeTest9: raw string literal"); }
88 };
89
90 // Test 10: Raw string with brackets and double brackets
91 class [[deprecated(R"(Use "Array[5]" instead of [[old]]))")]] AttributeTest10 : public QObject
92 {
93 Q_OBJECT
94 public:
95 void foo() { tr("AttributeTest10: raw string with complex content"); }
96 };
97
98 // Test 11: Maximum complexity raw string
99 class [[deprecated(R"delim(
100 Use Container[items[indices[0]]] with "quotes" and [[double brackets]]
101 See: Documentation[[section[5]]]
102 )delim")]] AttributeTest11 : public QObject
103 {
104 Q_OBJECT
105 public:
106 void foo() { tr("AttributeTest11: maximum complexity"); }
107 };
108
109 // ============================================================================
110 // CLASS ATTRIBUTES - Special Cases
111 // ============================================================================
112
113 // Test 12: Attribute with namespace
114 class [[gnu::aligned(16)]] AttributeTest12 : public QObject
115 {
116 Q_OBJECT
117 public:
118 void foo() { tr("AttributeTest12: namespace attribute"); }
119 };
120
121 // Test 13: Attribute with function call argument
122 class [[gnu::aligned(sizeof(int))]] AttributeTest13 : public QObject
123 {
124 Q_OBJECT
125 public:
126 void foo() { tr("AttributeTest13: function argument"); }
127 };
128
129 // Test 14: Multi-line attribute
130 class [[deprecated("This is deprecated")]] AttributeTest14 : public QObject
131 {
132 Q_OBJECT
133 public:
134 void foo() { tr("AttributeTest14: multiline attribute"); }
135 };
136
137 // Test 15: Multi-line attribute with complex nested structures
138 class [[deprecated("This class uses [[old]] syntax. "
139 "Use Array[n] instead. "
140 "See \"Documentation[Page5]\" for details.")]] AttributeTest15 : public QObject
141 {
142 Q_OBJECT
143 public:
144 void foo() { tr("AttributeTest15: multiline with nested syntax"); }
145 };
146
147 // Test 16: Three consecutive attributes
148 class [[nodiscard]] [[deprecated("[obsolete]")]] [[maybe_unused]] AttributeTest16 : public QObject
149 {
150 Q_OBJECT
151 public:
152 void foo() { tr("AttributeTest16: three consecutive attributes"); }
153 };
154
155 // Test 17: Attribute with escape sequences
156 class [[deprecated("Line1\nLine2\t[Bracket]\r\n\"Quote\"")]] AttributeTest17 : public QObject
157 {
158 Q_OBJECT
159 public:
160 void foo() { tr("AttributeTest17: escape sequences"); }
161 };
162
163 // Test 18: Attribute with backslash escape sequences
164 class [[deprecated("Line1\nLine2\t[Tab]")]] AttributeTest18 : public QObject
165 {
166 Q_OBJECT
167 public:
168 void foo() { tr("AttributeTest18: backslash escapes"); }
169 };
170
171 // ============================================================================
172 // CLASS ATTRIBUTES - Templates
173 // ============================================================================
174
175 // Test 19: Template class with attribute
176 template <typename T>
177 class [[deprecated]] AttributeTest19 : public QObject
178 {
179 Q_OBJECT
180 public:
181 void foo() { tr("AttributeTest19: template with attribute"); }
182 };
183
184 // Test 20: Template class with multiple type parameters
185 template <typename T, int N>
186 class [[deprecated]] AttributeTest20 : public QObject
187 {
188 Q_OBJECT
189 public:
190 void foo() { tr("AttributeTest20: template multiple params"); }
191 };
192
193 // ============================================================================
194 // NAMESPACE ATTRIBUTES
195 // ============================================================================
196
197 // Test 21: Namespace with attribute
198 namespace [[deprecated]] AttributeNamespace {
199 class AttributeTest21 : public QObject
200 {
201 Q_OBJECT
202 public:
203 void foo() { tr("AttributeTest21: namespace attribute"); }
204 };
205 } // namespace AttributeNamespace
206
207 // Test 22: Namespace with attribute containing attributed class
208 namespace [[deprecated]] AttributeNamespace2 {
209 class [[maybe_unused]] AttributeTest22 : public QObject
210 {
211 Q_OBJECT
212 public:
213 void foo() { tr("AttributeTest22: attributed class in attributed namespace"); }
214 };
215 } // namespace AttributeNamespace2
216
217 // ============================================================================
218 // FUNCTION ATTRIBUTES - Basic
219 // ============================================================================
220
221 // Test 23: Member function with nodiscard
222 class AttributeTest23 : public QObject
223 {
224 Q_OBJECT
225 public:
226 [[nodiscard]] QString getValue() { return tr("AttributeTest23: function attribute"); }
227 };
228
229 // Test 24: Multiple attributes on function
230 class AttributeTest24 : public QObject
231 {
232 Q_OBJECT
233 public:
234 [[nodiscard]] [[deprecated]] QString getDeprecated()
235 {
236 return tr("AttributeTest24: multiple function attributes");
237 }
238 };
239
240 // Test 25: Multiple attributes on function with string argument
241 class AttributeTest25 : public QObject
242 {
243 Q_OBJECT
244 public:
245 [[nodiscard]] [[deprecated("Use getNewValue")]] QString getOldValue()
246 {
247 return tr("AttributeTest25: function attributes with args");
248 }
249 };
250
251 // ============================================================================
252 // FUNCTION ATTRIBUTES - Constructors and Special Functions
253 // ============================================================================
254
255 // Test 26: Constructor with attribute
256 class AttributeTest26 : public QObject
257 {
258 Q_OBJECT
259 public:
260 [[deprecated]] AttributeTest26() { tr("AttributeTest26: deprecated constructor"); }
261 };
262
263 // Test 27: Constructor with attribute and initializer list
264 class AttributeTest27 : public QObject
265 {
266 Q_OBJECT
267 public:
268 [[deprecated]] AttributeTest27() : QObject()
269 {
270 tr("AttributeTest27: constructor with initializer");
271 }
272 };
273
274 // ============================================================================
275 // FUNCTION ATTRIBUTES - Operators
276 // ============================================================================
277
278 // Test 28: Operator overload with attribute
279 class AttributeTest28 : public QObject
280 {
281 Q_OBJECT
282 public:
283 [[nodiscard]] bool operator==(const AttributeTest28 &) const
284 {
285 tr("AttributeTest28: operator with attribute");
286 return true;
287 }
288 };
289
290 // Test 29: Conversion operator with attribute
291 class AttributeTest29 : public QObject
292 {
293 Q_OBJECT
294 public:
295 [[nodiscard]] operator bool() const
296 {
297 tr("AttributeTest29: conversion operator");
298 return true;
299 }
300 };
301
302 // ============================================================================
303 // FUNCTION ATTRIBUTES - Static and Virtual
304 // ============================================================================
305
306 // Test 30: Static member function
307 class AttributeTest30 : public QObject
308 {
309 Q_OBJECT
310 public:
311 [[nodiscard]] static QString getStatic()
312 {
313 return tr("AttributeTest30: static function attribute");
314 }
315 };
316
317 // Test 31: Virtual function with attribute
318 class AttributeTest31 : public QObject
319 {
320 Q_OBJECT
321 public:
322 [[nodiscard]] virtual QString getVirtual()
323 {
324 return tr("AttributeTest31: virtual function attribute");
325 }
326 };
327
328 // ============================================================================
329 // REGRESSION TEST
330 // ============================================================================
331
332 // Test 32: Original QTBUG-140686 bug report
333 // The exact case from the bug report
334 class [[maybe_unused]] OriginalBugTest : public QObject
335 {
336 Q_OBJECT
337 public:
338 OriginalBugTest() { setObjectName(tr("OriginalBugTest: the reported bug")); }
339 };