summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/docs/clang-tidy
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/docs/clang-tidy')
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/list.rst3
-rw-r--r--clang-tools-extra/docs/clang-tidy/checks/misc-sizeof-container.rst20
2 files changed, 22 insertions, 1 deletions
diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst
index be7bf3b0f71..600b09d9273 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/list.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst
@@ -31,6 +31,7 @@ List of clang-tidy Checks
misc-macro-repeated-side-effects
misc-move-constructor-init
misc-noexcept-move-constructor
+ misc-sizeof-container
misc-static-assert
misc-swapped-arguments
misc-undelegated-constructor
@@ -54,4 +55,4 @@ List of clang-tidy Checks
readability-named-parameter
readability-redundant-smartptr-get
readability-redundant-string-cstr
- readability-simplify-boolean-expr \ No newline at end of file
+ readability-simplify-boolean-expr
diff --git a/clang-tools-extra/docs/clang-tidy/checks/misc-sizeof-container.rst b/clang-tools-extra/docs/clang-tidy/checks/misc-sizeof-container.rst
new file mode 100644
index 00000000000..2e880d4ef1e
--- /dev/null
+++ b/clang-tools-extra/docs/clang-tidy/checks/misc-sizeof-container.rst
@@ -0,0 +1,20 @@
+misc-sizeof-container
+=====================
+
+The check finds usages of ``sizeof`` on expressions of STL container types. Most
+likely the user wanted to use ``.size()`` instead.
+
+Currently only ``std::string`` and ``std::vector<T>`` are supported.
+
+Examples:
+
+.. code:: c++
+
+ std::string s;
+ int a = 47 + sizeof(s); // warning: sizeof() doesn't return the size of the container. Did you mean .size()?
+ // The suggested fix is: int a = 47 + s.size();
+
+ int b = sizeof(std::string); // no warning, probably intended.
+
+ std::string array_of_strings[10];
+ int c = sizeof(array_of_strings) / sizeof(array_of_strings[0]); // no warning, definitely intended.
OpenPOWER on IntegriCloud