misc-dangling-handle
====================
-Detect dangling references in value handlers like
+Detect dangling references in value handles like
``std::experimental::string_view``.
-These dangling references can come from constructing handles from temporary
+These dangling references can be a result of constructing handles from temporary
values, where the temporary is destroyed soon after the handle is created.
-By default only ``std::experimental::basic_string_view`` is considered.
-This list can be modified by passing a `;` separated list of class names using
-the HandleClasses option.
-
Examples:
.. code-block:: c++
char Array[10]{};
return Array;
}
+
+Options
+-------
+
+.. option:: HandleClasses
+
+ A semicolon-separated list of class names that should be treated as handles.
+ By default only ``std::experimental::basic_string_view`` is considered.
`speed regression <http://htmlpreview.github.io/?https://github.com/HowardHinnant/papers/blob/master/insert_vs_emplace.html>`_, but it might get support with some addition flag in the future.
By default only ``std::vector``, ``std::deque``, ``std::list`` are considered.
-This list can be modified by passing a semicolon-separated list of class names
-using the `ContainersWithPushBack` option.
+This list can be modified using the :option:`ContainersWithPushBack` option.
Before:
-.. code:: c++
+.. code-block:: c++
std::vector<MyClass> v;
v.push_back(MyClass(21, 37));
After:
-.. code:: c++
+.. code-block:: c++
std::vector<MyClass> v;
v.emplace_back(21, 37);
Before:
-.. code:: c++
+.. code-block:: c++
std::vector<boost::optional<std::string> > v;
v.push_back("abc");
After:
-.. code:: c++
+.. code-block:: c++
std::vector<boost::optional<std::string> > v;
v.emplace_back("abc");
wouldn't be exception safe.
In this case the calls of ``push_back`` won't be replaced.
-.. code:: c++
+.. code-block:: c++
std::vector<std::unique_ptr<int>> v;
v.push_back(std::unique_ptr<int>(new int(0)));
v.push_back(std::unique_ptr<int>(ptr));
This is because replacing it with ``emplace_back`` could cause a leak of this
-pointer if ``emplace_back`` would throw exception before emplacement
-(e.g. not enough memory to add new element).
+pointer if ``emplace_back`` would throw exception before emplacement (e.g. not
+enough memory to add new element).
-For more info read item 42 - "Consider emplacement instead of insertion."
-of Scott Meyers Effective Modern C++.
+For more info read item 42 - "Consider emplacement instead of insertion." of
+Scott Meyers Effective Modern C++.
-The default smart pointers that are considered are
-``std::unique_ptr``, ``std::shared_ptr``, ``std::auto_ptr``.
-To specify other smart pointers or other classes use option
-`SmartPointers` similar to `ContainersWithPushBack`.
+The default smart pointers that are considered are ``std::unique_ptr``,
+``std::shared_ptr``, ``std::auto_ptr``. To specify other smart pointers or
+other classes use the :option:`SmartPointers` option.
Check also fires if any argument of constructor call would be:
or if the argument would be converted via derived-to-base cast.
This check requires C++11 of higher to run.
+
+Options
+-------
+
+.. option:: ContainersWithPushBack
+
+ Semicolon-separated list of class names of custom containers that support
+ ``push_back``.
+
+.. option:: SmartPointers
+
+ Semicolon-separated list of class names of custom smart pointers.