summaryrefslogtreecommitdiff
path: root/clang-tools-extra/docs
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2018-11-18 16:41:06 +0000
committerAaron Ballman <aaron@aaronballman.com>2018-11-18 16:41:06 +0000
commit319ea2af5537ff3e2b8ff9a4cf7b5151195d7a1f (patch)
tree6503dbe780ba6dfd383e079988666c7498b7c9d9 /clang-tools-extra/docs
parent2275b485ccb700761bbde9e1398b66354011998a (diff)
Add the abseil-duration-factory-scale check.
This check removes unneeded scaling of arguments when calling Abseil Time factory functions. Patch by Hyrum Wright.
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-factory-scale.rst35
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/list.rst1
3 files changed, 42 insertions, 0 deletions
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 1d49c81aba9..2773e235462 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -81,6 +81,12 @@ Improvements to clang-tidy
``absl::Duration`` factory functions are called when the more-efficient
integer versions could be used instead.
+- New :doc:`abseil-duration-factory-scale
+ <clang-tidy/checks/abseil-duration-factory-scale>` check.
+
+ Checks for cases where arguments to ``absl::Duration`` factory functions are
+ scaled internally and could be changed to a different factory function.
+
- New :doc:`abseil-faster-strsplit-delimiter
<clang-tidy/checks/abseil-faster-strsplit-delimiter>` check.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/abseil-duration-factory-scale.rst b/clang-tools-extra/docs/clang-tidy/checks/abseil-duration-factory-scale.rst
new file mode 100644
index 00000000000..8b99d4685f3
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/abseil-duration-factory-scale.rst
@@ -0,0 +1,35 @@
+.. title:: clang-tidy - abseil-duration-factory-scale
+
+abseil-duration-factory-scale
+=============================
+
+Checks for cases where arguments to ``absl::Duration`` factory functions are
+scaled internally and could be changed to a different factory function. This
+check also looks for arguements with a zero value and suggests using
+``absl::ZeroDuration()`` instead.
+
+Examples:
+
+.. code-block:: c++
+
+ // Original - Internal multiplication.
+ int x;
+ absl::Duration d = absl::Seconds(60 * x);
+
+ // Suggested - Use absl::Minutes instead.
+ absl::Duration d = absl::Minutes(x);
+
+
+ // Original - Internal division.
+ int y;
+ absl::Duration d = absl::Milliseconds(y / 1000.);
+
+ // Suggested - Use absl:::Seconds instead.
+ absl::Duration d = absl::Seconds(y);
+
+
+ // Original - Zero-value argument.
+ absl::Duration d = absl::Hours(0);
+
+ // Suggested = Use absl::ZeroDuration instead
+ absl::Duration d = absl::ZeroDuration();
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index f33af36ed58..7fa19471895 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -6,6 +6,7 @@ Clang-Tidy Checks
.. toctree::
abseil-duration-division
abseil-duration-factory-float
+ abseil-duration-factory-scale
abseil-faster-strsplit-delimiter
abseil-no-internal-dependencies
abseil-no-namespace