| 1 |
.. title:: clang-tidy - bugprone-unused-raii |
| 2 |
|
| 3 |
bugprone-unused-raii |
| 4 |
==================== |
| 5 |
|
| 6 |
Finds temporaries that look like RAII objects. |
| 7 |
|
| 8 |
The canonical example for this is a scoped lock. |
| 9 |
|
| 10 |
.. code-block:: c++ |
| 11 |
|
| 12 |
{ |
| 13 |
scoped_lock(&global_mutex); |
| 14 |
critical_section(); |
| 15 |
} |
| 16 |
|
| 17 |
The destructor of the scoped_lock is called before the ``critical_section`` is |
| 18 |
entered, leaving it unprotected. |
| 19 |
|
| 20 |
We apply a number of heuristics to reduce the false positive count of this |
| 21 |
check: |
| 22 |
|
| 23 |
- Ignore code expanded from macros. Testing frameworks make heavy use of this. |
| 24 |
|
| 25 |
- Ignore types with trivial destructors. They are very unlikely to be RAII |
| 26 |
objects and there's no difference when they are deleted. |
| 27 |
|
| 28 |
- Ignore objects at the end of a compound statement (doesn't change behavior). |
| 29 |
|
| 30 |
- Ignore objects returned from a call. |