summaryrefslogtreecommitdiff
path: root/clang-tools-extra/docs
diff options
context:
space:
mode:
authorJonas Toth <jonas.toth@gmail.com>2018-12-03 18:35:56 +0000
committerJonas Toth <jonas.toth@gmail.com>2018-12-03 18:35:56 +0000
commitf2f9b3190cc91a3b2c3a352cbcaea5dfdfc6e6a4 (patch)
tree2fa8c35ef71c33f19b99782e1a18b63f0bcfe2ea /clang-tools-extra/docs
parentd4b1f4b3ad3098e99a0238de308f8e2a5671c51a (diff)
[clang-tidy] 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. 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