Skip to content

Commit c47d717

Browse files
authored
Merge branch 'master' into mikejo-snap
2 parents 122685f + d0a5b44 commit c47d717

File tree

389 files changed

+5047
-2034
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

389 files changed

+5047
-2034
lines changed

.openpublishing.publish.config.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@
6969
"live": "live",
7070
"master": "master"
7171
}
72+
},
73+
{
74+
"path_to_root": "dotnet-xref",
75+
"url": "https://github.com/MicrosoftDocs/dotnet-xref",
76+
"branch": "live",
77+
"branch_mapping": {
78+
"live": "live",
79+
"master": "master"
80+
}
7281
}
7382
],
7483
"branch_target_mapping": {},

docs/_breadcrumb/toc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
topicHref: /visualstudio/xml-tools/xml-tools-in-visual-studio
7777
- name: MSBuild
7878
tocHref: /visualstudio/msbuild/
79-
topicHref: /visualstudio/msbuild/msbuild1
79+
topicHref: /visualstudio/msbuild/msbuild
8080
- name: Installation
8181
tocHref: /visualstudio/install/
8282
topicHref: /visualstudio/install/install-visual-studio

docs/code-quality/C26400.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
title: "C26400 | Microsoft Docs"
3+
ms.custom: ""
4+
ms.date: "08/02/2017"
5+
ms.reviewer: ""
6+
ms.suite: ""
7+
ms.technology:
8+
- "vs-devops-test"
9+
ms.tgt_pltfrm: ""
10+
ms.topic: "article"
11+
f1_keywords:
12+
- "C26400"
13+
helpviewer_keywords:
14+
- "C26400"
15+
ms.assetid: b27e1c6d-8b52-40b3-9760-b93afef19c7a
16+
caps.latest.revision: 0
17+
author: "corob-msft"
18+
ms.author: "corob"
19+
manager: "ghogen"
20+
translation.priority.ht:
21+
- "de-de"
22+
- "es-es"
23+
- "fr-fr"
24+
- "it-it"
25+
- "ja-jp"
26+
- "ko-kr"
27+
- "ru-ru"
28+
- "zh-cn"
29+
- "zh-tw"
30+
translation.priority.mt:
31+
- "cs-cz"
32+
- "pl-pl"
33+
- "pt-br"
34+
- "tr-tr"
35+
---
36+
# C26400 NO_RAW_POINTER_ASSIGNMENT
37+
This check helps to enforce the *rule I.11: Never transfer ownership by a raw pointer (T\*)*, which is a subset of the rule *R.3: A raw pointer (a T\*) is non-owning.* Specifically, it warns on any call to operator `new` which saves its result in a variable of raw pointer type. It also warns on calls to functions that return `gsl::owner<T>` if their results are assigned to raw pointers. The idea here is that you should clearly state ownership of memory resources. For more information, see the [C++ Core Guidelines](http://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#r-resource-management).
38+
39+
The easiest way to fix this is to use `auto` declaration if the resource is assigned immediately at the variable declaration. If this is not possible, then we suggest that you use the type `gsl::owner<T>`. The `auto` declarations initialized with operator `new` are “owners” because we assume that the result of any allocation is implicitly an owner pointer. We transfer this assumption to the `auto` variable and treat it as `owner<T>`.
40+
41+
If this check flags a call to a function which returns `owner<T>`, this may be an indication of a legitimate bug in code. Basically, it points to a place where the code leaks an explicit notion of ownership (and maybe the resource itself).
42+
43+
## Remarks
44+
- This rule currently (Visual Studio 2017 version 15.3) checks only local variables. If allocation is assigned to a formal parameter, global variable, class member, and so on, it is not flagged. Appropriate coverage of such scenarios is a part of future work.
45+
46+
## Example 1: Simple allocation
47+
```cpp
48+
char *buffer = nullptr;
49+
if (useCache)
50+
buffer = GetCache();
51+
else
52+
buffer = new char[bufferSize]; // C26400
53+
```
54+
55+
## Example 2: Simple allocation (fixed with gsl::owner<T>)
56+
```cpp
57+
gsl::owner<char*> buffer = nullptr;
58+
if (useCache)
59+
buffer = GetCache();
60+
else
61+
buffer = new char[bufferSize]; // OK
62+
63+
Example 3: Simple allocation (fixed with auto)
64+
auto buffer = useCache ? GetCache() : new char[bufferSize]; // OK
65+
```
66+

docs/code-quality/C26401.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: "C26401 | Microsoft Docs"
3+
ms.custom: ""
4+
ms.date: "07/21/2017"
5+
ms.reviewer: ""
6+
ms.suite: ""
7+
ms.technology:
8+
- "vs-devops-test"
9+
ms.tgt_pltfrm: ""
10+
ms.topic: "article"
11+
f1_keywords:
12+
- "C26401"
13+
helpviewer_keywords:
14+
- "C26401"
15+
ms.assetid: b9d3d398-697a-4a5d-8bfe-9c667dffb90b
16+
caps.latest.revision: 0
17+
author: "corob-msft"
18+
ms.author: "corob"
19+
manager: "ghogen"
20+
translation.priority.ht:
21+
- "de-de"
22+
- "es-es"
23+
- "fr-fr"
24+
- "it-it"
25+
- "ja-jp"
26+
- "ko-kr"
27+
- "ru-ru"
28+
- "zh-cn"
29+
- "zh-tw"
30+
translation.priority.mt:
31+
- "cs-cz"
32+
- "pl-pl"
33+
- "pt-br"
34+
- "tr-tr"
35+
---
36+
# C26401 DONT_DELETE_NON_OWNER
37+
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.
38+
39+
40+
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.

docs/code-quality/C26402.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: "C26401 | Microsoft Docs"
3+
ms.custom: ""
4+
ms.date: "07/21/2017"
5+
ms.reviewer: ""
6+
ms.suite: ""
7+
ms.technology:
8+
- "vs-devops-test"
9+
ms.tgt_pltfrm: ""
10+
ms.topic: "article"
11+
f1_keywords:
12+
- "C26401"
13+
helpviewer_keywords:
14+
- "C26401"
15+
ms.assetid: b9d3d398-697a-4a5d-8bfe-9c667dffb90b
16+
caps.latest.revision: 0
17+
author: "corob-msft"
18+
ms.author: "corob"
19+
manager: "ghogen"
20+
translation.priority.ht:
21+
- "de-de"
22+
- "es-es"
23+
- "fr-fr"
24+
- "it-it"
25+
- "ja-jp"
26+
- "ko-kr"
27+
- "ru-ru"
28+
- "zh-cn"
29+
- "zh-tw"
30+
translation.priority.mt:
31+
- "cs-cz"
32+
- "pl-pl"
33+
- "pt-br"
34+
- "tr-tr"
35+
---
36+
# C26401 DONT_DELETE_NON_OWNER
37+
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.
38+
39+
40+
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.

docs/code-quality/C26403.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
---
2+
title: "C26403 | Microsoft Docs"
3+
ms.custom: ""
4+
ms.date: "07/21/2017"
5+
ms.reviewer: ""
6+
ms.suite: ""
7+
ms.technology:
8+
- "vs-devops-test"
9+
ms.tgt_pltfrm: ""
10+
ms.topic: "article"
11+
f1_keywords:
12+
- "C26403"
13+
helpviewer_keywords:
14+
- "C26403"
15+
ms.assetid: 7e14868d-df86-4df3-98d3-71b1e80ba14e
16+
caps.latest.revision: 0
17+
author: "corob-msft"
18+
ms.author: "corob"
19+
manager: "ghogen"
20+
translation.priority.ht:
21+
- "de-de"
22+
- "es-es"
23+
- "fr-fr"
24+
- "it-it"
25+
- "ja-jp"
26+
- "ko-kr"
27+
- "ru-ru"
28+
- "zh-cn"
29+
- "zh-tw"
30+
translation.priority.mt:
31+
- "cs-cz"
32+
- "pl-pl"
33+
- "pt-br"
34+
- "tr-tr"
35+
---
36+
# C26403 RESET_OR_DELETE_OWNER
37+
Owner pointers are like unique pointers: they own a resource exclusively, and manage release of the resource, as well as its transfers to other owners. This check validates that a local owner pointer properly maintains its resource through all execution paths in a function. If the resource was not transferred to another owner, or was not explicitly release, the checker warns, and points to the declaration of the pointer variable.
38+
39+
For more information, see the [C++ Core Guidelines](http://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#r-resource-management).
40+
41+
## Remarks
42+
- Currently (Visual Studio 2017 version 15.3) this check doesn’t give the exact path which fails to release the resource. This behavior may be imporved in future releases. It may be difficult to find exact location for a fix. The better approach is to try to replace plain pointers in complex functions with unique pointers to avoid any risks.
43+
44+
- The check may discard an over-complicated function in order to not block code analysis. Generally, the complexity of functions should be maintained under some reasonable threshold. We may consider adding a local complexity check to the C++ Core Guidelines module if there is clear demand for it. This limitation is applicable to other rules which are sensitive to data flow.
45+
46+
- The warning may fire on clearly false positive cases where memory is deleted only after the nullness check of a pointer. This is the result of a current limitation of the tool’s API, but it may be improved in future.
47+
48+
## Example 1: Missing cleanup during error handling
49+
```cpp
50+
gsl::owner<int*> sequence = GetRandomSequence(); // C26403
51+
52+
try
53+
{
54+
StartSimulation(sequence);
55+
}
56+
catch (const std::exception& e)
57+
{
58+
if (KnownException(e))
59+
return; // Skipping the path which deletes the owner.
60+
61+
ReportException(e);
62+
}
63+
64+
delete [] sequence;
65+
```

docs/code-quality/C26404.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: "C26404 | Microsoft Docs"
3+
ms.custom: ""
4+
ms.date: "07/21/2017"
5+
ms.reviewer: ""
6+
ms.suite: ""
7+
ms.technology:
8+
- "vs-devops-test"
9+
ms.tgt_pltfrm: ""
10+
ms.topic: "article"
11+
f1_keywords:
12+
- "C26404"
13+
helpviewer_keywords:
14+
- "C26404"
15+
ms.assetid: 94afb700-3f3b-40db-8afc-2481935360c2
16+
caps.latest.revision: 0
17+
author: "corob-msft"
18+
ms.author: "corob"
19+
manager: "ghogen"
20+
translation.priority.ht:
21+
- "de-de"
22+
- "es-es"
23+
- "fr-fr"
24+
- "it-it"
25+
- "ja-jp"
26+
- "ko-kr"
27+
- "ru-ru"
28+
- "zh-cn"
29+
- "zh-tw"
30+
translation.priority.mt:
31+
- "cs-cz"
32+
- "pl-pl"
33+
- "pt-br"
34+
- "tr-tr"
35+
---
36+
# C26404 DONT_DELETE_INVALID
37+
Once owner pointer releases or transfers its resource, it gets into an “invalid” state.
38+
Deleting such a pointer may lead to immediate memory corruption due to double delete, or to an access violation when the deleted resource is accessed from another owner pointer.
39+
40+
## Example 1: Deleting an owner after transferring its value
41+
```cpp
42+
gsl::owner<State*> validState = nullptr;
43+
gsl::owner<State*> state = ReadState();
44+
validState = state;
45+
if (!IsValid(state))
46+
delete state; // C26404
47+
```
48+
49+
## Example 2: Deleting an uninitialized owner
50+
```cpp
51+
gsl::owner<Message*> message;
52+
if (popLast)
53+
message = ReleaseMessage();
54+
delete message; // C26404
55+
```

docs/code-quality/C26405.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: "C26405 | Microsoft Docs"
3+
ms.custom: ""
4+
ms.date: "07/21/2017"
5+
ms.reviewer: ""
6+
ms.suite: ""
7+
ms.technology:
8+
- "vs-devops-test"
9+
ms.tgt_pltfrm: ""
10+
ms.topic: "article"
11+
f1_keywords:
12+
- "C26405"
13+
helpviewer_keywords:
14+
- "C26405"
15+
ms.assetid: 2034d961-3ec5-4184-bbef-aa792e4c03c0
16+
caps.latest.revision: 0
17+
author: "corob-msft"
18+
ms.author: "corob"
19+
manager: "ghogen"
20+
translation.priority.ht:
21+
- "de-de"
22+
- "es-es"
23+
- "fr-fr"
24+
- "it-it"
25+
- "ja-jp"
26+
- "ko-kr"
27+
- "ru-ru"
28+
- "zh-cn"
29+
- "zh-tw"
30+
translation.priority.mt:
31+
- "cs-cz"
32+
- "pl-pl"
33+
- "pt-br"
34+
- "tr-tr"
35+
---
36+
# C26405 DONT_ASSIGN_TO_VALID
37+
If an owner pointer already points to a valid memory buffer, it must not be assigned to another value without releasing its current resource first. Such assignment may lead to a resource leak even if the resource address is copied into some raw pointer (because raw pointers shouldn’t release resources).
38+
39+
## Example 1: Overwriting an owner in a loop
40+
```cpp
41+
gsl::owner<Shape*> shape = nullptr;
42+
while (shape = NextShape()) // C26405
43+
Process(shape) ? delete shape : 0;
44+
```

docs/code-quality/C26406.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: "C26406 | Microsoft Docs"
3+
ms.custom: ""
4+
ms.date: "07/21/2017"
5+
ms.reviewer: ""
6+
ms.suite: ""
7+
ms.technology:
8+
- "vs-devops-test"
9+
ms.tgt_pltfrm: ""
10+
ms.topic: "article"
11+
f1_keywords:
12+
- "C26406"
13+
helpviewer_keywords:
14+
- "C26406"
15+
ms.assetid: 02fb8e23-1989-4e24-a5a5-e30f71d00325
16+
caps.latest.revision: 0
17+
author: "corob-msft"
18+
ms.author: "corob"
19+
manager: "ghogen"
20+
translation.priority.ht:
21+
- "de-de"
22+
- "es-es"
23+
- "fr-fr"
24+
- "it-it"
25+
- "ja-jp"
26+
- "ko-kr"
27+
- "ru-ru"
28+
- "zh-cn"
29+
- "zh-tw"
30+
translation.priority.mt:
31+
- "cs-cz"
32+
- "pl-pl"
33+
- "pt-br"
34+
- "tr-tr"
35+
---
36+
# C26406 DONT_ASSIGN_RAW_TO_OWNER
37+
Owners are initialized from allocations or from other owners. Assigning a value from a raw pointer to an owner pointer is not allowed. Raw pointers don’t guarantee ownership transfer; there is still may be an original owner which holds the resource and will attempt to release it. Note that assigning a value from owner to a raw pointer is fine; raw pointers are valid clients to access resources, but not to manage them.
38+
39+
## Example 1: Using address of object
40+
```cpp
41+
gsl::owner<Socket*> socket = defaultSocket ? &defaultSocket : new Socket(); // C26406
42+
```

0 commit comments

Comments
 (0)