| 1 |
.. title:: clang-tidy - bugprone-dangling-handle |
| 2 |
|
| 3 |
bugprone-dangling-handle |
| 4 |
======================== |
| 5 |
|
| 6 |
Detect dangling references in value handles like ``std::string_view``. |
| 7 |
These dangling references can be a result of constructing handles from temporary |
| 8 |
values, where the temporary is destroyed soon after the handle is created. |
| 9 |
|
| 10 |
Examples: |
| 11 |
|
| 12 |
.. code-block:: c++ |
| 13 |
|
| 14 |
string_view View = string(); // View will dangle. |
| 15 |
string A; |
| 16 |
View = A + "A"; // still dangle. |
| 17 |
|
| 18 |
vector<string_view> V; |
| 19 |
V.push_back(string()); // V[0] is dangling. |
| 20 |
V.resize(3, string()); // V[1] and V[2] will also dangle. |
| 21 |
|
| 22 |
string_view f() { |
| 23 |
// All these return values will dangle. |
| 24 |
return string(); |
| 25 |
string S; |
| 26 |
return S; |
| 27 |
char Array[10]{}; |
| 28 |
return Array; |
| 29 |
} |
| 30 |
|
| 31 |
Options |
| 32 |
------- |
| 33 |
|
| 34 |
.. option:: HandleClasses |
| 35 |
|
| 36 |
A semicolon-separated list of class names that should be treated as handles. |
| 37 |
By default only ``std::basic_string_view`` and |
| 38 |
``std::experimental::basic_string_view`` are considered. |