Skip to content

Commit 447b1b9

Browse files
author
Colin Robertson
authored
Style fixes
Update to add actual error message, make Acrolinx and i18n happier, fix Example heading, set current date, add example comments, fix code style.
1 parent 064d394 commit 447b1b9

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

docs/code-quality/c26409.md

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,36 @@
11
---
22
title: C26409
3-
ms.date: 07/21/2017
3+
ms.date: 08/20/2020
44
ms.topic: "conceptual"
55
f1_keywords: ["C26409"]
66
helpviewer_keywords: ["C26409"]
77
ms.assetid: a3b3a229-d566-4be3-bd28-2876ccc8dc37
88
---
99
# C26409 NO_NEW_DELETE
1010

11-
Even if code is clean of calls to malloc() and free() we still suggest that you consider better options than explicit use of operators [new and delete](/cpp/cpp/new-and-delete-operators).
11+
> `Avoid calling new and delete explicitly, use std::make_unique<T> instead (r.11).`
1212
13-
**C++ Core Guidelines**:
13+
Even if code is clean of calls to` malloc()` and `free()`, we still suggest that you consider better options than explicit use of operators [`new` and `delete`](/cpp/cpp/new-and-delete-operators).
14+
15+
**C++ Core Guidelines**:\
1416
[R.11: Avoid calling new and delete explicitly](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#r11-avoid-calling-new-and-delete-explicitly)
1517

16-
The ultimate fix is to start using smart pointers with appropriate factory functions, such as [std::make_unique](/cpp/standard-library/memory-functions#make_unique).
18+
The ultimate fix is to use smart pointers and appropriate factory functions, such as [`std::make_unique`](/cpp/standard-library/memory-functions#make_unique).
1719

1820
## Remarks
1921

20-
- The checker warns on calls to any kind of operator **`new`** or **`delete`**: scalar, vector, overloaded versions (global and class-specific), as well as on placement versions. The latter case may require some clarifications on the Core Guidelines in terms of suggested fixes and may be omitted in the future.
22+
- The checker warns on calls to any kind of operator **`new`** or **`delete`**: scalar, vector, overloaded versions (global and class-specific), and placement versions. The placement **`new`** case may require some clarifications in the Core Guidelines for suggested fixes, and may be omitted in the future.
2123

22-
# Example
23-
```cpp
24+
## Example
25+
26+
This example shows C26409 is raised for explicit **`new`** and **`delete`**. Consider using smart pointer factory functions such as `std::make_unique` instead.
2427

28+
```cpp
2529
void f(int i)
2630
{
27-
int* arr = new int[i]{}; // C26409, warning is issued for all new calls
28-
delete[] arr; // C26409, warning is issued for all delete calls
29-
30-
auto unique = std::make_unique<int[]>(i); // prefer using smart pointers over new and delete
31+
int* arr = new int[i]{}; // C26409, warning is issued for all new calls
32+
delete[] arr; // C26409, warning is issued for all delete calls
33+
34+
auto unique = std::make_unique<int[]>(i); // prefer using smart pointers over new and delete
3135
}
3236
```

0 commit comments

Comments
 (0)