| 1 |
.. title:: clang-tidy - abseil-duration-factory-scale |
| 2 |
|
| 3 |
abseil-duration-factory-scale |
| 4 |
============================= |
| 5 |
|
| 6 |
Checks for cases where arguments to ``absl::Duration`` factory functions are |
| 7 |
scaled internally and could be changed to a different factory function. This |
| 8 |
check also looks for arguments with a zero value and suggests using |
| 9 |
``absl::ZeroDuration()`` instead. |
| 10 |
|
| 11 |
Examples: |
| 12 |
|
| 13 |
.. code-block:: c++ |
| 14 |
|
| 15 |
// Original - Internal multiplication. |
| 16 |
int x; |
| 17 |
absl::Duration d = absl::Seconds(60 * x); |
| 18 |
|
| 19 |
// Suggested - Use absl::Minutes instead. |
| 20 |
absl::Duration d = absl::Minutes(x); |
| 21 |
|
| 22 |
|
| 23 |
// Original - Internal division. |
| 24 |
int y; |
| 25 |
absl::Duration d = absl::Milliseconds(y / 1000.); |
| 26 |
|
| 27 |
// Suggested - Use absl:::Seconds instead. |
| 28 |
absl::Duration d = absl::Seconds(y); |
| 29 |
|
| 30 |
|
| 31 |
// Original - Zero-value argument. |
| 32 |
absl::Duration d = absl::Hours(0); |
| 33 |
|
| 34 |
// Suggested = Use absl::ZeroDuration instead |
| 35 |
absl::Duration d = absl::ZeroDuration(); |