34 lines · plain
1.. title:: clang-tidy - abseil-duration-comparison2 3abseil-duration-comparison4==========================5 6Checks for comparisons which should be in the ``absl::Duration`` domain instead7of the floating point or integer domains.8 9N.B.: In cases where a ``Duration`` was being converted to an integer and then10compared against a floating-point value, truncation during the ``Duration``11conversion might yield a different result. In practice this is very rare, and12still indicates a bug which should be fixed.13 14Examples:15 16.. code-block:: c++17 18 // Original - Comparison in the floating point domain19 double x;20 absl::Duration d;21 if (x < absl::ToDoubleSeconds(d)) ...22 23 // Suggested - Compare in the absl::Duration domain instead24 if (absl::Seconds(x) < d) ...25 26 27 // Original - Comparison in the integer domain28 int x;29 absl::Duration d;30 if (x < absl::ToInt64Microseconds(d)) ...31 32 // Suggested - Compare in the absl::Duration domain instead33 if (absl::Microseconds(x) < d) ...34