brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 3dfd326 Raw
37 lines · plain
1.. title:: clang-tidy - abseil-duration-subtraction2 3abseil-duration-subtraction4===========================5 6Checks for cases where subtraction should be performed in the7``absl::Duration`` domain. When subtracting two values, and the first one is8known to be a conversion from ``absl::Duration``, we can infer that the second9should also be interpreted as an ``absl::Duration``, and make that inference10explicit.11 12Examples:13 14.. code-block:: c++15 16  // Original - Subtraction in the double domain17  double x;18  absl::Duration d;19  double result = absl::ToDoubleSeconds(d) - x;20 21  // Suggestion - Subtraction in the absl::Duration domain instead22  double result = absl::ToDoubleSeconds(d - absl::Seconds(x));23 24  // Original - Subtraction of two Durations in the double domain25  absl::Duration d1, d2;26  double result = absl::ToDoubleSeconds(d1) - absl::ToDoubleSeconds(d2);27 28  // Suggestion - Subtraction in the absl::Duration domain instead29  double result = absl::ToDoubleSeconds(d1 - d2);30 31 32Note: As with other ``clang-tidy`` checks, it is possible that multiple fixes33may overlap (as in the case of nested expressions), so not all occurrences can34be transformed in one run. In particular, this may occur for nested subtraction35expressions. Running ``clang-tidy`` multiple times will find and fix these36overlaps.37