summaryrefslogtreecommitdiff
path: root/clang-tools-extra/docs
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2018-10-31 19:11:38 +0000
committerAaron Ballman <aaron@aaronballman.com>2018-10-31 19:11:38 +0000
commit8e213e7cfd15b107fed292bf93b920e6ebb77130 (patch)
tree6f5af07c7ca1f115e8f59df737d39c8a438bb787 /clang-tools-extra/docs
parentcc147eb1dccb79a6be0a06ebf63d6b70ed6a425f (diff)
Implement the readability-const-return-type check.
This check flags function top-level const-qualified return types and suggests removing the mostly-superfluous const qualifier where possible. Patch by Yitzhak Mandelbaum.
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/list.rst1
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/readability-const-return-type.rst26
3 files changed, 33 insertions, 0 deletions
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst
index 5987c3c47d9..45dffb92978 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -142,6 +142,12 @@ Improvements to clang-tidy
Detects local variable declarations declaring more than one variable and
tries to refactor the code to one statement per declaration.
+- New :doc:`readability-const-return-type
+ <clang-tidy/checks/readability-const-return-type>` check.
+
+ Checks for functions with a ``const``-qualified return type and recommends
+ removal of the ``const`` keyword.
+
- New :doc:`readability-magic-numbers
<clang-tidy/checks/readability-magic-numbers>` check.
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index 082ec276af4..f33130b5e46 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -225,6 +225,7 @@ Clang-Tidy Checks
portability-simd-intrinsics
readability-avoid-const-params-in-decls
readability-braces-around-statements
+ readability-const-return-type
readability-container-size-empty
readability-delete-null-pointer
readability-deleted-default
diff --git a/clang-tools-extra/docs/clang-tidy/checks/readability-const-return-type.rst b/clang-tools-extra/docs/clang-tidy/checks/readability-const-return-type.rst
new file mode 100644
index 00000000000..e236d8d00e6
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability-const-return-type.rst
@@ -0,0 +1,26 @@
+.. title:: clang-tidy - readability-const-return-type
+
+readability-const-return-type
+=============================
+
+Checks for functions with a ``const``-qualified return type and recommends
+removal of the ``const`` keyword. Such use of `const` is usually superfluous,
+and can prevent valuable compiler optimizations. Does not (yet) fix trailing
+return types.
+
+Examples:
+
+.. code-block:: c++
+
+ const int foo();
+ const Clazz foo();
+ Clazz *const foo();
+
+Note that this applies strictly to top-level qualification, which excludes
+pointers or references to const values. For example, these are fine:
+
+.. code-block:: c++
+
+ const int* foo();
+ const int& foo();
+ const Clazz* foo();