Skip to content

Commit 0e1fd22

Browse files
committed
Address review comments.
1 parent 764430b commit 0e1fd22

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

docs/code-quality/c26441.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,17 @@ The standard library provides locks to help control concurrent access to resourc
1919

2020
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.
2121

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+
struct X { [[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.
2333
2434
Code analysis name: `NO_UNNAMED_GUARDS`
2535

docs/code-quality/c26444.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@ helpviewer_keywords: ["C26444"]
1313

1414
[ES.84: Don't (try to) declare a local variable with no name](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-noname)
1515

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.
1717

1818
## Remarks
1919

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.
2221
- 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.
2322

2423
Code analysis name: `NO_UNNAMED_RAII_OBJECTS`

0 commit comments

Comments
 (0)