diff options
author | Jonas Toth <jonas.toth@gmail.com> | 2018-10-24 17:40:50 +0000 |
---|---|---|
committer | Jonas Toth <jonas.toth@gmail.com> | 2018-10-24 17:40:50 +0000 |
commit | 9f57606b0c513c7cdfc7aae83f702f772a2dcecc (patch) | |
tree | da89cfc04dd1e36b066db07d2e0e7960951f52aa /clang-tools-extra/docs | |
parent | 571b05ab9982c123dc54ec9c9abe9292dc077f46 (diff) |
[clang-tidy] Add the abseil-duration-factory-float check
Summary:
This check finds cases where calls to an absl::Duration factory could use the more efficient integer overload.
For example:
// Original - Providing a floating-point literal.
absl::Duration d = absl::Seconds(10.0);
// Suggested - Use an integer instead.
absl::Duration d = absl::Seconds(10);
Patch by hwright.
Reviewers: alexfh, hokein, aaron.ballman, JonasToth
Reviewed By: hokein, JonasToth
Subscribers: zturner, xazax.hun, Eugene.Zelenko, mgorny, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D53339
Diffstat (limited to 'clang-tools-extra/docs')
-rw-r--r-- | clang-tools-extra/docs/ReleaseNotes.rst | 7 | ||||
-rw-r--r-- | clang-tools-extra/docs/clang-tidy/checks/abseil-duration-factory-float.rst | 29 | ||||
-rw-r--r-- | clang-tools-extra/docs/clang-tidy/checks/list.rst | 1 |
3 files changed, 37 insertions, 0 deletions
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 7b70216b81d..4b1a6f2b7c8 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -74,6 +74,13 @@ Improvements to clang-tidy floating-point context, and recommends the use of a function that returns a floating-point value. +- New :doc:`abseil-duration-factory-float + <clang-tidy/checks/abseil-duration-factory-float>` check. + + Checks for cases where the floating-point overloads of various + ``absl::Duration`` factory functions are called when the more-efficient + integer versions could be used instead. + - 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-float.rst b/clang-tools-extra/docs/clang-tidy/checks/abseil-duration-factory-float.rst new file mode 100644 index 00000000000..a4fc6d4291d --- /dev/null +++ b/clang-tools-extra/docs/clang-tidy/checks/abseil-duration-factory-float.rst @@ -0,0 +1,29 @@ +.. title:: clang-tidy - abseil-duration-factory-float + +abseil-duration-factory-float +============================= + +Checks for cases where the floating-point overloads of various +``absl::Duration`` factory functions are called when the more-efficient +integer versions could be used instead. + +This check will not suggest fixes for literals which contain fractional +floating point values or non-literals. It will suggest removing +superfluous casts. + +Examples: + +.. code-block:: c++ + + // Original - Providing a floating-point literal. + absl::Duration d = absl::Seconds(10.0); + + // Suggested - Use an integer instead. + absl::Duration d = absl::Seconds(10); + + + // Original - Explicitly casting to a floating-point type. + absl::Duration d = absl::Seconds(static_cast<double>(10)); + + // Suggested - Remove the explicit cast + absl::Duration d = absl::Seconds(10); diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst index f7fa7c5a33f..a5b5a4f7780 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/list.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst @@ -5,6 +5,7 @@ Clang-Tidy Checks .. toctree:: abseil-duration-division + abseil-duration-factory-float abseil-faster-strsplit-delimiter abseil-no-internal-dependencies abseil-no-namespace |