You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/code-quality/c26441.md
+11-1Lines changed: 11 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,17 @@ The standard library provides locks to help control concurrent access to resourc
19
19
20
20
This diagnostic only analyzes the standard lock types `std::scoped_lock`, `std::unique_lock`, and `std::lock_guard`. Warning [C26444](c26444.md) covers other unnamed RAII types.
21
21
22
-
The analyzer only analyzes simple calls to constructors. More complex initializer expressions may lead to inaccurate results in the form of missed warnings. The analyzer ignores locks passed as arguments to function calls or returned from function calls. It is unable to determine if those locks are deliberately trying to protect that function call or if they should be extended. To provide similar protection for types returned by a function call, annotate them with `[[nodiscard]]`. You can also annotate constructors with `[[nodiscard]]` to avoid unnamed objects of that type. The analyzer ignores locks created as temporaries but assigned to named references to extend their lifetime.
22
+
The analyzer only analyzes simple calls to constructors. More complex initializer expressions may lead to inaccurate results in the form of missed warnings. The analyzer ignores locks passed as arguments to function calls or returned from function calls. It is unable to determine if those locks are deliberately trying to protect that function call or if they should be extended. To provide similar protection for types returned by a function call, annotate them with `[[nodiscard]]`. You can also annotate constructors with `[[nodiscard]]` to avoid unnamed objects of that type:
23
+
24
+
```cpp
25
+
structX { [[nodiscard]] X(); };
26
+
27
+
void f() {
28
+
X{}; // warning C4834
29
+
}
30
+
```
31
+
32
+
The analyzer ignores locks created as temporaries but assigned to named references to extend their lifetime.
[ES.84: Don't (try to) declare a local variable with no name](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-noname)
15
15
16
-
Unnamed temporary objects with nontrivial behavior may point to either (a) inefficient code that allocates and immediately throws away resources or (b) to the code that unintentionally ignores nonprimitive data. Sometimes it may also indicate plainly wrong declaration.
16
+
An unnamed variable declaration will create a temporary object that is discarded at the end of the statement. Such temporary objects with nontrivial behavior may point to either (a) inefficient code that allocates and immediately throws away resources or (b) to the code that unintentionally ignores nonprimitive data. Sometimes it may also indicate plainly wrong declaration.
17
17
18
18
## Remarks
19
19
20
-
- This rule detects types with nontrivial destructors. Keep in mind that destructors can be compiler generated.
21
-
- The warning can flag code that invokes a nontrivial constructor of a RAII type.
20
+
- This rule detects types with a hand-written destructor or a compiler-generated destructor that transitively calls a hand-written destructor.
22
21
- The logic skips temporaries if they're used in higher-level expressions. One example is temporaries that are passed as arguments or used to invoke a function.
0 commit comments