abseil-upgrade-duration-conversions.cpp
23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
// RUN: %check_clang_tidy -std=c++11-or-later %s abseil-upgrade-duration-conversions %t -- -- -I%S/Inputs
// FIXME: Fix the checker to work in C++17 mode.
using int64_t = long long;
#include "absl/time/time.h"
template <typename T> struct ConvertibleTo {
operator T() const;
};
template <typename T>
ConvertibleTo<T> operator+(ConvertibleTo<T>, ConvertibleTo<T>);
template <typename T>
ConvertibleTo<T> operator*(ConvertibleTo<T>, ConvertibleTo<T>);
void arithmeticOperatorBasicPositive() {
absl::Duration d;
d *= ConvertibleTo<int64_t>();
// CHECK-MESSAGES: [[@LINE-1]]:8: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: d *= static_cast<int64_t>(ConvertibleTo<int64_t>());
d /= ConvertibleTo<int64_t>();
// CHECK-MESSAGES: [[@LINE-1]]:8: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: d /= static_cast<int64_t>(ConvertibleTo<int64_t>());
d = ConvertibleTo<int64_t>() * d;
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: d = static_cast<int64_t>(ConvertibleTo<int64_t>()) * d;
d = d * ConvertibleTo<int64_t>();
// CHECK-MESSAGES: [[@LINE-1]]:11: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: d = d * static_cast<int64_t>(ConvertibleTo<int64_t>());
d = d / ConvertibleTo<int64_t>();
// CHECK-MESSAGES: [[@LINE-1]]:11: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: d = d / static_cast<int64_t>(ConvertibleTo<int64_t>());
d.operator*=(ConvertibleTo<int64_t>());
// CHECK-MESSAGES: [[@LINE-1]]:16: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: d.operator*=(static_cast<int64_t>(ConvertibleTo<int64_t>()));
d.operator/=(ConvertibleTo<int64_t>());
// CHECK-MESSAGES: [[@LINE-1]]:16: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: d.operator/=(static_cast<int64_t>(ConvertibleTo<int64_t>()));
d = operator*(ConvertibleTo<int64_t>(), d);
// CHECK-MESSAGES: [[@LINE-1]]:17: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: d = operator*(static_cast<int64_t>(ConvertibleTo<int64_t>()), d);
d = operator*(d, ConvertibleTo<int64_t>());
// CHECK-MESSAGES: [[@LINE-1]]:20: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: d = operator*(d, static_cast<int64_t>(ConvertibleTo<int64_t>()));
d = operator/(d, ConvertibleTo<int64_t>());
// CHECK-MESSAGES: [[@LINE-1]]:20: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: d = operator/(d, static_cast<int64_t>(ConvertibleTo<int64_t>()));
ConvertibleTo<int64_t> c;
d *= (c + c) * c + c;
// CHECK-MESSAGES: [[@LINE-1]]:8: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: d *= static_cast<int64_t>((c + c) * c + c)
d /= (c + c) * c + c;
// CHECK-MESSAGES: [[@LINE-1]]:8: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: d /= static_cast<int64_t>((c + c) * c + c)
d = d * c * c;
// CHECK-MESSAGES: [[@LINE-1]]:11: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-MESSAGES: [[@LINE-2]]:15: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: d = d * static_cast<int64_t>(c) * static_cast<int64_t>(c)
d = c * d * c;
// CHECK-MESSAGES: [[@LINE-1]]:7: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-MESSAGES: [[@LINE-2]]:15: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: d = static_cast<int64_t>(c) * d * static_cast<int64_t>(c)
d = d / c * c;
// CHECK-MESSAGES: [[@LINE-1]]:11: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-MESSAGES: [[@LINE-2]]:15: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: d = d / static_cast<int64_t>(c) * static_cast<int64_t>(c)
}
void arithmeticOperatorBasicNegative() {
absl::Duration d;
d *= char{1};
d *= 1;
d *= int64_t{1};
d *= 1.0f;
d *= 1.0;
d *= 1.0l;
d /= char{1};
d /= 1;
d /= int64_t{1};
d /= 1.0f;
d /= 1.0;
d /= 1.0l;
d = d * char{1};
d = d * 1;
d = d * int64_t{1};
d = d * 1.0f;
d = d * 1.0;
d = d * 1.0l;
d = char{1} * d;
d = 1 * d;
d = int64_t{1} * d;
d = 1.0f * d;
d = 1.0 * d;
d = 1.0l * d;
d = d / char{1};
d = d / 1;
d = d / int64_t{1};
d = d / 1.0f;
d = d / 1.0;
d = d / 1.0l;
d *= static_cast<int>(ConvertibleTo<int>());
d *= (int)ConvertibleTo<int>();
d *= int(ConvertibleTo<int>());
d /= static_cast<int>(ConvertibleTo<int>());
d /= (int)ConvertibleTo<int>();
d /= int(ConvertibleTo<int>());
d = static_cast<int>(ConvertibleTo<int>()) * d;
d = (int)ConvertibleTo<int>() * d;
d = int(ConvertibleTo<int>()) * d;
d = d * static_cast<int>(ConvertibleTo<int>());
d = d * (int)ConvertibleTo<int>();
d = d * int(ConvertibleTo<int>());
d = d / static_cast<int>(ConvertibleTo<int>());
d = d / (int)ConvertibleTo<int>();
d = d / int(ConvertibleTo<int>());
d *= 1 + ConvertibleTo<int>();
d /= 1 + ConvertibleTo<int>();
d = (1 + ConvertibleTo<int>()) * d;
d = d * (1 + ConvertibleTo<int>());
d = d / (1 + ConvertibleTo<int>());
}
template <typename T> void templateForOpsSpecialization(T) {}
template <>
void templateForOpsSpecialization<absl::Duration>(absl::Duration d) {
d *= ConvertibleTo<int64_t>();
// CHECK-MESSAGES: [[@LINE-1]]:8: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: d *= static_cast<int64_t>(ConvertibleTo<int64_t>());
}
template <int N> void arithmeticNonTypeTemplateParamSpecialization() {
absl::Duration d;
d *= N;
}
template <> void arithmeticNonTypeTemplateParamSpecialization<5>() {
absl::Duration d;
d *= ConvertibleTo<int>();
// CHECK-MESSAGES: [[@LINE-1]]:8: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: d *= static_cast<int64_t>(ConvertibleTo<int>());
}
template <typename T> void templateOpsFix() {
absl::Duration d;
d *= ConvertibleTo<int64_t>();
// CHECK-MESSAGES: [[@LINE-1]]:8: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: d *= static_cast<int64_t>(ConvertibleTo<int64_t>());
}
template <typename T, typename U> void templateOpsWarnOnly(T t, U u) {
t *= u;
// CHECK-MESSAGES: [[@LINE-1]]:8: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
absl::Duration d;
d *= u;
// CHECK-MESSAGES: [[@LINE-1]]:8: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
}
template <typename T> struct TemplateTypeOpsWarnOnly {
void memberA(T t) {
d *= t;
// CHECK-MESSAGES: [[@LINE-1]]:10: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
}
template <typename U, typename V> void memberB(U u, V v) {
u *= v;
// CHECK-MESSAGES: [[@LINE-1]]:10: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
d *= v;
// CHECK-MESSAGES: [[@LINE-1]]:10: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
}
absl::Duration d;
};
template <typename T, typename U>
void templateOpsInstantiationBeforeDefinition(T t, U u);
void arithmeticOperatorsInTemplates() {
templateForOpsSpecialization(5);
templateForOpsSpecialization(absl::Duration());
arithmeticNonTypeTemplateParamSpecialization<1>();
arithmeticNonTypeTemplateParamSpecialization<5>();
templateOpsFix<int>();
templateOpsWarnOnly(absl::Duration(), ConvertibleTo<int>());
templateOpsInstantiationBeforeDefinition(absl::Duration(),
ConvertibleTo<int>());
TemplateTypeOpsWarnOnly<ConvertibleTo<int>> t;
t.memberA(ConvertibleTo<int>());
t.memberB(absl::Duration(), ConvertibleTo<int>());
}
template <typename T, typename U>
void templateOpsInstantiationBeforeDefinition(T t, U u) {
t *= u;
// CHECK-MESSAGES: [[@LINE-1]]:8: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
absl::Duration d;
d *= u;
// CHECK-MESSAGES: [[@LINE-1]]:8: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
}
#define FUNCTION_MACRO(x) x
#define CONVERTIBLE_TMP ConvertibleTo<int>()
#define ONLY_WARN_INSIDE_MACRO_ARITHMETIC_OP d *= ConvertibleTo<int>()
#define T_OBJECT T()
#define T_CALL_EXPR d *= T()
template <typename T> void arithmeticTemplateAndMacro() {
absl::Duration d;
d *= T_OBJECT;
// CHECK-MESSAGES: [[@LINE-1]]:8: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
d *= CONVERTIBLE_TMP;
// CHECK-MESSAGES: [[@LINE-1]]:8: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: d *= static_cast<int64_t>(CONVERTIBLE_TMP);
T_CALL_EXPR;
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
}
#define TEMPLATE_MACRO(type) \
template <typename T> void TemplateInMacro(T t) { \
type d; \
d *= t; \
}
TEMPLATE_MACRO(absl::Duration)
// CHECK-MESSAGES: [[@LINE-1]]:1: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
void arithmeticOperatorsInMacros() {
absl::Duration d;
d = FUNCTION_MACRO(d * ConvertibleTo<int>());
// CHECK-MESSAGES: [[@LINE-1]]:26: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: d = FUNCTION_MACRO(d * static_cast<int64_t>(ConvertibleTo<int>()));
d *= FUNCTION_MACRO(ConvertibleTo<int>());
// CHECK-MESSAGES: [[@LINE-1]]:23: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: d *= static_cast<int64_t>(FUNCTION_MACRO(ConvertibleTo<int>()));
d *= CONVERTIBLE_TMP;
// CHECK-MESSAGES: [[@LINE-1]]:8: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: d *= static_cast<int64_t>(CONVERTIBLE_TMP);
ONLY_WARN_INSIDE_MACRO_ARITHMETIC_OP;
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
arithmeticTemplateAndMacro<ConvertibleTo<int>>();
TemplateInMacro(ConvertibleTo<int>());
}
void factoryFunctionPositive() {
// User defined conversion:
(void)absl::Nanoseconds(ConvertibleTo<int64_t>());
// CHECK-MESSAGES: [[@LINE-1]]:27: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Nanoseconds(static_cast<int64_t>(ConvertibleTo<int64_t>()));
(void)absl::Microseconds(ConvertibleTo<int64_t>());
// CHECK-MESSAGES: [[@LINE-1]]:28: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Microseconds(static_cast<int64_t>(ConvertibleTo<int64_t>()));
(void)absl::Milliseconds(ConvertibleTo<int64_t>());
// CHECK-MESSAGES: [[@LINE-1]]:28: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Milliseconds(static_cast<int64_t>(ConvertibleTo<int64_t>()));
(void)absl::Seconds(ConvertibleTo<int64_t>());
// CHECK-MESSAGES: [[@LINE-1]]:23: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Seconds(static_cast<int64_t>(ConvertibleTo<int64_t>()));
(void)absl::Minutes(ConvertibleTo<int64_t>());
// CHECK-MESSAGES: [[@LINE-1]]:23: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Minutes(static_cast<int64_t>(ConvertibleTo<int64_t>()));
(void)absl::Hours(ConvertibleTo<int64_t>());
// CHECK-MESSAGES: [[@LINE-1]]:21: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Hours(static_cast<int64_t>(ConvertibleTo<int64_t>()));
// User defined conversion to integral type, followed by built-in conversion:
(void)absl::Nanoseconds(ConvertibleTo<char>());
// CHECK-MESSAGES: [[@LINE-1]]:27: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Nanoseconds(static_cast<int64_t>(ConvertibleTo<char>()));
(void)absl::Microseconds(ConvertibleTo<char>());
// CHECK-MESSAGES: [[@LINE-1]]:28: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Microseconds(static_cast<int64_t>(ConvertibleTo<char>()));
(void)absl::Milliseconds(ConvertibleTo<char>());
// CHECK-MESSAGES: [[@LINE-1]]:28: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Milliseconds(static_cast<int64_t>(ConvertibleTo<char>()));
(void)absl::Seconds(ConvertibleTo<char>());
// CHECK-MESSAGES: [[@LINE-1]]:23: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Seconds(static_cast<int64_t>(ConvertibleTo<char>()));
(void)absl::Minutes(ConvertibleTo<char>());
// CHECK-MESSAGES: [[@LINE-1]]:23: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Minutes(static_cast<int64_t>(ConvertibleTo<char>()));
(void)absl::Hours(ConvertibleTo<char>());
// CHECK-MESSAGES: [[@LINE-1]]:21: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Hours(static_cast<int64_t>(ConvertibleTo<char>()));
// User defined conversion to floating point type, followed by built-in conversion:
(void)absl::Nanoseconds(ConvertibleTo<float>());
// CHECK-MESSAGES: [[@LINE-1]]:27: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Nanoseconds(static_cast<int64_t>(ConvertibleTo<float>()));
(void)absl::Microseconds(ConvertibleTo<float>());
// CHECK-MESSAGES: [[@LINE-1]]:28: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Microseconds(static_cast<int64_t>(ConvertibleTo<float>()));
(void)absl::Milliseconds(ConvertibleTo<float>());
// CHECK-MESSAGES: [[@LINE-1]]:28: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Milliseconds(static_cast<int64_t>(ConvertibleTo<float>()));
(void)absl::Seconds(ConvertibleTo<float>());
// CHECK-MESSAGES: [[@LINE-1]]:23: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Seconds(static_cast<int64_t>(ConvertibleTo<float>()));
(void)absl::Minutes(ConvertibleTo<float>());
// CHECK-MESSAGES: [[@LINE-1]]:23: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Minutes(static_cast<int64_t>(ConvertibleTo<float>()));
(void)absl::Hours(ConvertibleTo<float>());
// CHECK-MESSAGES: [[@LINE-1]]:21: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Hours(static_cast<int64_t>(ConvertibleTo<float>()));
}
void factoryFunctionNegative() {
(void)absl::Nanoseconds(char{1});
(void)absl::Nanoseconds(1);
(void)absl::Nanoseconds(int64_t{1});
(void)absl::Nanoseconds(1.0f);
(void)absl::Microseconds(char{1});
(void)absl::Microseconds(1);
(void)absl::Microseconds(int64_t{1});
(void)absl::Microseconds(1.0f);
(void)absl::Milliseconds(char{1});
(void)absl::Milliseconds(1);
(void)absl::Milliseconds(int64_t{1});
(void)absl::Milliseconds(1.0f);
(void)absl::Seconds(char{1});
(void)absl::Seconds(1);
(void)absl::Seconds(int64_t{1});
(void)absl::Seconds(1.0f);
(void)absl::Minutes(char{1});
(void)absl::Minutes(1);
(void)absl::Minutes(int64_t{1});
(void)absl::Minutes(1.0f);
(void)absl::Hours(char{1});
(void)absl::Hours(1);
(void)absl::Hours(int64_t{1});
(void)absl::Hours(1.0f);
(void)absl::Nanoseconds(static_cast<int>(ConvertibleTo<int>()));
(void)absl::Microseconds(static_cast<int>(ConvertibleTo<int>()));
(void)absl::Milliseconds(static_cast<int>(ConvertibleTo<int>()));
(void)absl::Seconds(static_cast<int>(ConvertibleTo<int>()));
(void)absl::Minutes(static_cast<int>(ConvertibleTo<int>()));
(void)absl::Hours(static_cast<int>(ConvertibleTo<int>()));
}
template <typename T> void templateForFactorySpecialization(T) {}
template <> void templateForFactorySpecialization<ConvertibleTo<int>>(ConvertibleTo<int> c) {
(void)absl::Nanoseconds(c);
// CHECK-MESSAGES: [[@LINE-1]]:27: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Nanoseconds(static_cast<int64_t>(c));
}
template <int N> void factoryNonTypeTemplateParamSpecialization() {
(void)absl::Nanoseconds(N);
}
template <> void factoryNonTypeTemplateParamSpecialization<5>() {
(void)absl::Nanoseconds(ConvertibleTo<int>());
// CHECK-MESSAGES: [[@LINE-1]]:27: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Nanoseconds(static_cast<int64_t>(ConvertibleTo<int>()));
}
template <typename T> void templateFactoryFix() {
(void)absl::Nanoseconds(ConvertibleTo<int>());
// CHECK-MESSAGES: [[@LINE-1]]:27: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Nanoseconds(static_cast<int64_t>(ConvertibleTo<int>()));
}
template <typename T> void templateFactoryWarnOnly(T t) {
(void)absl::Nanoseconds(t);
// CHECK-MESSAGES: [[@LINE-1]]:27: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
}
template <typename T> void templateFactoryInstantiationBeforeDefinition(T t);
template <typename T> struct TemplateTypeFactoryWarnOnly {
void memberA(T t) {
(void)absl::Nanoseconds(t);
// CHECK-MESSAGES: [[@LINE-1]]:29: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
}
template <typename U> void memberB(U u) {
(void)absl::Nanoseconds(u);
// CHECK-MESSAGES: [[@LINE-1]]:29: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
}
};
void factoryInTemplates() {
templateForFactorySpecialization(5);
templateForFactorySpecialization(ConvertibleTo<int>());
factoryNonTypeTemplateParamSpecialization<1>();
factoryNonTypeTemplateParamSpecialization<5>();
templateFactoryFix<int>();
templateFactoryWarnOnly(ConvertibleTo<int>());
templateFactoryInstantiationBeforeDefinition(ConvertibleTo<int>());
TemplateTypeFactoryWarnOnly<ConvertibleTo<int>> t;
t.memberA(ConvertibleTo<int>());
t.memberB(ConvertibleTo<int>());
}
template <typename T> void templateFactoryInstantiationBeforeDefinition(T t) {
(void)absl::Nanoseconds(t);
// CHECK-MESSAGES: [[@LINE-1]]:27: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
}
#define ONLY_WARN_INSIDE_MACRO_FACTORY \
(void)absl::Nanoseconds(ConvertibleTo<int>())
#define T_CALL_FACTORTY_INSIDE_MACRO (void)absl::Nanoseconds(T())
template <typename T> void factoryTemplateAndMacro() {
(void)absl::Nanoseconds(T_OBJECT);
// CHECK-MESSAGES: [[@LINE-1]]:27: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
(void)absl::Nanoseconds(CONVERTIBLE_TMP);
// CHECK-MESSAGES: [[@LINE-1]]:27: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Nanoseconds(static_cast<int64_t>(CONVERTIBLE_TMP))
T_CALL_FACTORTY_INSIDE_MACRO;
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
}
#define TEMPLATE_FACTORY_MACRO(factory) \
template <typename T> void TemplateFactoryInMacro(T t) { (void)factory(t); }
TEMPLATE_FACTORY_MACRO(absl::Nanoseconds)
// CHECK-MESSAGES: [[@LINE-1]]:1: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
void factoryInMacros() {
(void)absl::Nanoseconds(FUNCTION_MACRO(ConvertibleTo<int>()));
// CHECK-MESSAGES: [[@LINE-1]]:42: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Nanoseconds(static_cast<int64_t>(FUNCTION_MACRO(ConvertibleTo<int>())));
(void)absl::Nanoseconds(CONVERTIBLE_TMP);
// CHECK-MESSAGES: [[@LINE-1]]:27: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
// CHECK-FIXES: (void)absl::Nanoseconds(static_cast<int64_t>(CONVERTIBLE_TMP))
ONLY_WARN_INSIDE_MACRO_FACTORY;
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: implicit conversion to 'int64_t' is deprecated in this context; use an explicit cast instead
factoryTemplateAndMacro<ConvertibleTo<int>>();
TemplateFactoryInMacro(ConvertibleTo<int>());
}
// This is a reduced test-case for PR39949 and manifested in this check.
namespace std {
template <typename _Tp>
_Tp declval();
template <typename _Functor, typename... _ArgTypes>
struct __res {
template <typename... _Args>
static decltype(declval<_Functor>()(_Args()...)) _S_test(int);
template <typename...>
static void _S_test(...);
typedef decltype(_S_test<_ArgTypes...>(0)) type;
};
template <typename>
struct function;
template <typename... _ArgTypes>
struct function<void(_ArgTypes...)> {
template <typename _Functor,
typename = typename __res<_Functor, _ArgTypes...>::type>
function(_Functor) {}
};
} // namespace std
typedef std::function<void(void)> F;
F foo() {
return F([] {});
}