Debian Codegraph @

clang-tools-extra/docs/clang-tidy/checks/abseil/duration-comparison.rst

raw
1 .. title:: clang-tidy - abseil-duration-comparison
2
3 abseil-duration-comparison
4 ==========================
5
6 Checks for comparisons which should be in the ``absl::Duration`` domain instead
7 of the floating point or integer domains.
8
9 N.B.: In cases where a ``Duration`` was being converted to an integer and then
10 compared against a floating-point value, truncation during the ``Duration``
11 conversion might yield a different result. In practice this is very rare, and
12 still indicates a bug which should be fixed.
13
14 Examples:
15
16 .. code-block:: c++
17
18 // Original - Comparison in the floating point domain
19 double x;
20 absl::Duration d;
21 if (x < absl::ToDoubleSeconds(d)) ...
22
23 // Suggested - Compare in the absl::Duration domain instead
24 if (absl::Seconds(x) < d) ...
25
26
27 // Original - Comparison in the integer domain
28 int x;
29 absl::Duration d;
30 if (x < absl::ToInt64Microseconds(d)) ...
31
32 // Suggested - Compare in the absl::Duration domain instead
33 if (absl::Microseconds(x) < d) ...