Skip to content

Commit 3d594a4

Browse files
author
Colin Robertson
authored
Update C26401 grammar
Update the date, description, and edit to make the grammar checker happy.
1 parent b6640e3 commit 3d594a4

1 file changed

Lines changed: 20 additions & 19 deletions

File tree

‎docs/code-quality/c26401.md‎

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
---
22
title: C26401
3-
ms.date: 07/21/2017
3+
ms.date: 12/14/2020
44
ms.topic: "conceptual"
55
f1_keywords: ["C26401"]
66
helpviewer_keywords: ["C26401"]
77
ms.assetid: b9d3d398-697a-4a5d-8bfe-9c667dffb90b
8-
description: CppCoreCheck rule that enforces C++ Core Guidelines I.11
8+
description: CppCoreCheck rule C26401 enforces C++ Core Guidelines I.11
99
---
1010
# C26401 DONT_DELETE_NON_OWNER
1111

12-
This check detects places where moving to `owner<T>` can be a good option for the first stage of refactoring. Like C26400 it enforces rules I.11 and R.3, but focuses on the "release" portion of the pointer lifetime. It warns on any call to operator **`delete`** if its target is neither an `owner<T>` nor an implicitly assumed owner. For more information, see [C26400](c26400.md) regarding the **`auto`** declarations. This does include expressions that refer to global variables, formals, and so on.
12+
This check detects places where moving to `owner<T>` can be a good option for the first stage of refactoring. Like C26400, it enforces rules I.11 and R.3, but focuses on the "release" portion of the pointer lifetime. It warns on any call to operator **`delete`** if its target isn't an `owner<T>` or an implicitly assumed owner. For more information about **`auto`** declarations, see [C26400](c26400.md). This check includes expressions that refer to global variables, formal parameters, and so on.
1313

14-
Warnings C26400 and C26401 always occur with [C26409](c26409.md), but they are more appropriate for scenarios where immediate migration to smart pointers is not feasible. In such cases the `owner<T>` concept can be adopted first and C26409 may be temporarily suppressed.
14+
Warnings C26400 and C26401 always occur with [C26409](c26409.md), but they're more appropriate for scenarios where immediate migration to smart pointers isn't feasible. In such cases, the `owner<T>` concept can be adopted first, and C26409 may be temporarily suppressed.
1515

1616
## See also
1717

1818
[C++ Core Guidelines I.11](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#i11-never-transfer-ownership-by-a-raw-pointer-t-or-reference-t)
1919

20-
## Example
20+
## Examples
2121

2222
```cpp
2323
struct myStruct {};
@@ -46,23 +46,24 @@ void function()
4646
}
4747
```
4848

49-
There is a C++ idiom `delete this` that triggers this warning. The warning is intentional as this pattern is discouraged by the C++ Core Guidelines. The warning can be suppressed using the `gsl::suppress` attribute in such cases. See the example below.
49+
There's a C++ idiom, `delete this`, that triggers this warning. The warning is intentional, because the C++ Core Guidelines discourage this pattern. You can suppress the warning by using the `gsl::suppress` attribute, as shown in this example:
5050

5151
```cpp
52-
class MyReferenceCountingObject final
52+
class MyReferenceCountingObject final
53+
{
54+
public:
55+
void AddRef();
56+
void Release() noexcept
5357
{
54-
public:
55-
void AddRef();
56-
void Release() noexcept
58+
ref_count_--;
59+
if (ref_count_ == 0)
5760
{
58-
ref_count_--;
59-
if (ref_count_ == 0)
60-
{
61-
[[gsl::suppress(i.11)]]
62-
delete this;
63-
}
61+
[[gsl::suppress(i.11)]]
62+
delete this;
6463
}
65-
private:
66-
unsigned int ref_count_{1};
67-
};
64+
}
65+
private:
66+
unsigned int ref_count_{1};
67+
};
6868
```
69+

0 commit comments

Comments
 (0)