summaryrefslogtreecommitdiff
path: root/clang-tools-extra/docs
diff options
context:
space:
mode:
authorJonas Toth <jonas.toth@gmail.com>2018-12-03 19:22:08 +0000
committerJonas Toth <jonas.toth@gmail.com>2018-12-03 19:22:08 +0000
commita95c588a42b63481935f9ef33e4eb04df6b20997 (patch)
treee2dea97afa205e3470b78ec5739e0460264ceb83 /clang-tools-extra/docs
parentf53a9fdb51d53f5bbc4e489702e302320758616a (diff)
[clang-tidy] Recommit: Add the abseil-duration-comparison check
Summary: This check finds instances where Duration values are being converted to a numeric value in a comparison expression, and suggests that the conversion happen on the other side of the expression to a Duration. See documentation for examples. This also shuffles some code around so that the new check may perform in sone step simplifications also caught by other checks. Compilation is unbroken, because the hash-function is now directly specified for std::unordered_map, as 'enum class' does not compile as key (seamingly only on some compilers). Patch by hwright. Reviewers: aaron.ballman, JonasToth, alexfh, hokein Reviewed By: JonasToth Subscribers: sammccall, Eugene.Zelenko, xazax.hun, cfe-commits, mgorny Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D54737
Diffstat (limited to 'clang-tools-extra/docs')
-rw-r--r--clang-tools-extra/docs/ReleaseNotes.rst6
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/abseil-duration-comparison.rst33
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/list.rst1
3 files changed, 40 insertions, 0 deletions
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index c7229df7086..19079686059 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -67,6 +67,12 @@ The improvements are...
Improvements to clang-tidy
--------------------------
+- New :doc:`abseil-duration-comparison
+ <clang-tidy/checks/abseil-duration-comparison>` check.
+
+ Checks for comparisons which should be done in the ``absl::Duration`` domain
+ instead of the float of integer domains.
+
- New :doc:`abseil-duration-division
<clang-tidy/checks/abseil-duration-division>` check.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/abseil-duration-comparison.rst b/clang-tools-extra/docs/clang-tidy/checks/abseil-duration-comparison.rst
new file mode 100644
index 00000000000..6df0514dec6
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/abseil-duration-comparison.rst
@@ -0,0 +1,33 @@
+.. title:: clang-tidy - abseil-duration-comparison
+
+abseil-duration-comparison
+==========================
+
+Checks for comparisons which should be in the ``absl::Duration`` domain instead
+of the floating point or integer domains.
+
+N.B.: In cases where a ``Duration`` was being converted to an integer and then
+compared against a floating-point value, truncation during the ``Duration``
+conversion might yield a different result. In practice this is very rare, and
+still indicates a bug which should be fixed.
+
+Examples:
+
+.. code-block:: c++
+
+ // Original - Comparison in the floating point domain
+ double x;
+ absl::Duration d;
+ if (x < absl::ToDoubleSeconds(d)) ...
+
+ // Suggested - Compare in the absl::Duration domain instead
+ if (absl::Seconds(x) < d) ...
+
+
+ // Original - Comparison in the integer domain
+ int x;
+ absl::Duration d;
+ if (x < absl::ToInt64Microseconds(d)) ...
+
+ // Suggested - Compare in the absl::Duration domain instead
+ if (absl::Microseconds(x) < d) ...
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 7fa19471895..e3528ae90e8 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -4,6 +4,7 @@ Clang-Tidy Checks
=================
.. toctree::
+ abseil-duration-comparison
abseil-duration-division
abseil-duration-factory-float
abseil-duration-factory-scale