| 1 |
.. title:: clang-tidy - bugprone-unused-local-non-trivial-variable |
| 2 |
|
| 3 |
bugprone-unused-local-non-trivial-variable |
| 4 |
========================================== |
| 5 |
|
| 6 |
Warns when a local non trivial variable is unused within a function. |
| 7 |
The following types of variables are excluded from this check: |
| 8 |
|
| 9 |
* trivial and trivially copyable |
| 10 |
* references and pointers |
| 11 |
* exception variables in catch clauses |
| 12 |
* static or thread local |
| 13 |
* structured bindings |
| 14 |
* variables with ``[[maybe_unused]]`` attribute |
| 15 |
|
| 16 |
This check can be configured to warn on all non-trivial variables by setting |
| 17 |
`IncludeTypes` to `.*`, and excluding specific types using `ExcludeTypes`. |
| 18 |
|
| 19 |
In the this example, `my_lock` would generate a warning that it is unused. |
| 20 |
|
| 21 |
.. code-block:: c++ |
| 22 |
|
| 23 |
std::mutex my_lock; |
| 24 |
// my_lock local variable is never used |
| 25 |
|
| 26 |
In the next example, `future2` would generate a warning that it is unused. |
| 27 |
|
| 28 |
.. code-block:: c++ |
| 29 |
|
| 30 |
std::future<MyObject> future1; |
| 31 |
std::future<MyObject> future2; |
| 32 |
// ... |
| 33 |
MyObject foo = future1.get(); |
| 34 |
// future2 is not used. |
| 35 |
|
| 36 |
Options |
| 37 |
------- |
| 38 |
|
| 39 |
.. option:: IncludeTypes |
| 40 |
|
| 41 |
Semicolon-separated list of regular expressions matching types of variables |
| 42 |
to check. By default the following types are checked: |
| 43 |
|
| 44 |
* `::std::.*mutex` |
| 45 |
* `::std::future` |
| 46 |
* `::std::basic_string` |
| 47 |
* `::std::basic_regex` |
| 48 |
* `::std::basic_istringstream` |
| 49 |
* `::std::basic_stringstream` |
| 50 |
* `::std::bitset` |
| 51 |
* `::std::filesystem::path` |
| 52 |
|
| 53 |
.. option:: ExcludeTypes |
| 54 |
|
| 55 |
A semicolon-separated list of regular expressions matching types that are |
| 56 |
excluded from the `IncludeTypes` matches. By default it is an empty list. |