brintos

brintos / llvm-project-archived public Read only

0
0
Text · 964 B · 05c11cd Raw
32 lines · plain
1.. title:: clang-tidy - abseil-duration-conversion-cast2 3abseil-duration-conversion-cast4===============================5 6Checks for casts of ``absl::Duration`` conversion functions, and recommends7the right conversion function instead.8 9Examples:10 11.. code-block:: c++12 13  // Original - Cast from a double to an integer14  absl::Duration d;15  int i = static_cast<int>(absl::ToDoubleSeconds(d));16 17  // Suggested - Use the integer conversion function directly.18  int i = absl::ToInt64Seconds(d);19 20 21  // Original - Cast from a double to an integer22  absl::Duration d;23  double x = static_cast<double>(absl::ToInt64Seconds(d));24 25  // Suggested - Use the integer conversion function directly.26  double x = absl::ToDoubleSeconds(d);27 28 29Note: In the second example, the suggested fix could yield a different result,30as the conversion to integer could truncate. In practice, this is very rare,31and you should use ``absl::Trunc`` to perform this operation explicitly instead.32