1.. title:: clang-tidy - abseil-upgrade-duration-conversions 2 3abseil-upgrade-duration-conversions 4=================================== 5 6Finds calls to ``absl::Duration`` arithmetic operators and factories whose 7argument needs an explicit cast to continue compiling after upcoming API 8changes. 9 10The operators ``*=``, ``/=``, ``*``, and ``/`` for ``absl::Duration`` currently 11accept an argument of class type that is convertible to an arithmetic type. Such 12a call currently converts the value to an ``int64_t``, even in a case such as 13``std::atomic<float>`` that would result in lossy conversion. 14 15Additionally, the ``absl::Duration`` factory functions (``absl::Hours``, 16``absl::Minutes``, etc) currently accept an ``int64_t`` or a floating-point 17type. Similar to the arithmetic operators, calls with an argument of class type 18that is convertible to an arithmetic type go through the ``int64_t`` path. 19 20These operators and factories will be changed to only accept arithmetic types to 21prevent unintended behavior. After these changes are released, passing an 22argument of class type will no longer compile, even if the type is implicitly 23convertible to an arithmetic type. 24 25Here are example fixes created by this check: 26 27.. code-block:: c++ 28 29 std::atomic<int> a; 30 absl::Duration d = absl::Milliseconds(a); 31 d *= a; 32 33becomes 34 35.. code-block:: c++ 36 37 std::atomic<int> a; 38 absl::Duration d = absl::Milliseconds(static_cast<int64_t>(a)); 39 d *= static_cast<int64_t>(a); 40 41Note that this check always adds a cast to ``int64_t`` in order to preserve the 42current behavior of user code. It is possible that this uncovers unintended 43behavior due to types implicitly convertible to a floating-point type. 44