[clang-tools-extra] r360247 - Documentation for bugprone-inaccurate-erase: added an example of a bug that this checker catches

Dmitri Gribenko via cfe-commits cfe-commits at lists.llvm.org
Wed May 8 05:02:32 PDT 2019


Author: gribozavr
Date: Wed May  8 05:02:31 2019
New Revision: 360247

URL: http://llvm.org/viewvc/llvm-project?rev=360247&view=rev
Log:
Documentation for bugprone-inaccurate-erase: added an example of a bug that this checker catches

Reviewers: alexfh

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D61644

Modified:
    clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-inaccurate-erase.rst

Modified: clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-inaccurate-erase.rst
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-inaccurate-erase.rst?rev=360247&r1=360246&r2=360247&view=diff
==============================================================================
--- clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-inaccurate-erase.rst (original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-inaccurate-erase.rst Wed May  8 05:02:31 2019
@@ -11,3 +11,19 @@ container but return an iterator to the
 of the container. These redundant elements must be removed using the
 ``erase()`` method. This check warns when not all of the elements will be
 removed due to using an inappropriate overload.
+
+For example, the following code erases only one element:
+
+.. code-block:: c++
+
+  std::vector<int> xs;
+  ...
+  xs.erase(std::remove(xs.begin(), xs.end(), 10));
+
+Call the two-argument overload of ``erase()`` to remove the subrange:
+
+.. code-block:: c++
+
+  std::vector<int> xs;
+  ...
+  xs.erase(std::remove(xs.begin(), xs.end(), 10), xs.end());




More information about the cfe-commits mailing list