1.. title:: clang-tidy - abseil-duration-subtraction
2
3abseil-duration-subtraction
4===========================
5
6Checks for cases where subtraction should be performed in the
7``absl::Duration`` domain. When subtracting two values, and the first one is
8known to be a conversion from ``absl::Duration``, we can infer that the second
9should also be interpreted as an ``absl::Duration``, and make that inference
10explicit.
11
12Examples:
13
14.. code-block:: c++
15
16  // Original - Subtraction in the double domain
17  double x;
18  absl::Duration d;
19  double result = absl::ToDoubleSeconds(d) - x;
20
21  // Suggestion - Subtraction in the absl::Duration domain instead
22  double result = absl::ToDoubleSeconds(d - absl::Seconds(x));
23
24  // Original - Subtraction of two Durations in the double domain
25  absl::Duration d1, d2;
26  double result = absl::ToDoubleSeconds(d1) - absl::ToDoubleSeconds(d2);
27
28  // Suggestion - Subtraction in the absl::Duration domain instead
29  double result = absl::ToDoubleSeconds(d1 - d2);
30
31
32Note: As with other ``clang-tidy`` checks, it is possible that multiple fixes
33may overlap (as in the case of nested expressions), so not all occurrences can
34be transformed in one run. In particular, this may occur for nested subtraction
35expressions. Running ``clang-tidy`` multiple times will find and fix these
36overlaps.
37