Skip to content

Commit e5ea538

Browse files
author
Colin Robertson
authored
Merge pull request MicrosoftDocs#3057 from MicrosoftDocs/FromPublicMasterBranch
Confirm merge from FromPublicMasterBranch to master to sync with https://github.com/MicrosoftDocs/cpp-docs (branch master)
2 parents 41083fa + 46ea68a commit e5ea538

File tree

6 files changed

+46
-15
lines changed

6 files changed

+46
-15
lines changed

docs/build/reference/msbuild-visual-cpp-overview.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ By default, the primary Visual Studio support files are located in the following
1616

1717
### Visual Studio 2019
1818

19-
- %VSINSTALLDIR%MSBuild\\Microsoft\\VC\\*version*\\VCTargets\\
19+
- %VSINSTALLDIR%MSBuild\\Microsoft\\VC\\*version*\\
2020

2121
Contains the primary target files (.targets) and property files (.props) that are used by the targets. By default, the $(VCTargetsPath) macro references this directory. The *version* placeholder refers to the Visual Studio version: v160 for Visual Studio 2019, v150 for Visual Studio 2017.
2222

23-
- %VSINSTALLDIR%MSBuild\\Microsoft\\VC\\*version*\\VCTargets\\Platforms\\*platform*\\
23+
- %VSINSTALLDIR%MSBuild\\Microsoft\\VC\\*version*\\Platforms\\*platform*\\
2424

2525
Contains platform-specific target and property files that override targets and properties in its parent directory. This directory also contains a DLL that defines the tasks that are used by the targets in this directory. The *platform* placeholder represents the ARM, Win32, or x64 subdirectory.
2626

27-
- %VSINSTALLDIR%MSBuild\\Microsoft\\VC\\*version*\\VCTargets\\Platforms\\*platform*\\PlatformToolsets\\*toolset*\\
27+
- %VSINSTALLDIR%MSBuild\\Microsoft\\VC\\*version*\\Platforms\\*platform*\\PlatformToolsets\\*toolset*\\
2828

2929
Contains the directories that enable the build to generate C++ applications by using the specified *toolset*. The *platform* placeholder represents the ARM, Win32, or x64 subdirectory. The *toolset* placeholder represents the toolset subdirectory.
3030

docs/build/reference/std-specify-language-standard-version.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Enable supported C++ language features from the specified version of the C++ lan
1212

1313
> **`/std:c++14`**\
1414
> **`/std:c++17`**\
15-
> **`/std:c++latest`**]
15+
> **`/std:c++latest`**
1616
1717
## Remarks
1818

docs/code-quality/c26406.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
---
22
title: C26406
3-
ms.date: 07/21/2017
3+
ms.date: 08/18/2020
44
ms.topic: "conceptual"
55
f1_keywords: ["C26406"]
66
helpviewer_keywords: ["C26406"]
77
ms.assetid: 02fb8e23-1989-4e24-a5a5-e30f71d00325
88
---
99
# C26406 DONT_ASSIGN_RAW_TO_OWNER
1010

11-
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.
11+
This warning enforces R.3 from the C++ Core Guidelines. For more information, see [C++ Core Guidelines R.3](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#r3-a-raw-pointer-a-t-is-non-owning).
12+
13+
## Remarks
14+
15+
Owners are initialized from allocations or from other owners. This warning occurs when you assign a value from a raw pointer to an owner pointer. Raw pointers don’t guarantee ownership transfer; the original owner may still hold the resource and attempt to release it. It's okay to assign a value from an owner to a raw pointer. Raw pointers are valid clients to access resources, but not to manage them.
1216

1317
## Example 1: Using address of object
1418

19+
This sample attempts to assign ownership of the address of `defaultSocket` to owner pointer `socket`:
20+
1521
```cpp
1622
gsl::owner<Socket*> socket = defaultSocket ? &defaultSocket : new Socket(); // C26406
1723
```

docs/code-quality/c26407.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
---
22
title: C26407
3-
ms.date: 07/21/2017
3+
ms.date: 08/18/2020
44
ms.topic: "conceptual"
55
f1_keywords: ["C26407"]
66
helpviewer_keywords: ["C26407"]
77
ms.assetid: 5539907a-bfa0-40db-82a6-b860c97209e1
88
---
99
# C26407 DONT_HEAP_ALLOCATE_UNNECESSARILY
1010

11-
To avoid unnecessary use of pointers we try to detect common patterns of local allocations, for example when the result of a call to operator new is stored in a local variable and later explicitly deleted. This supports the rule R.5: *Prefer scoped objects, don't heap-allocate unnecessarily*. The suggested fix is to use an RAII type instead of a raw pointer and allow it to deal with resources. If an allocation is a single object, then it may be obviously unnecessary and a local variable of the objects type would work better.
11+
To avoid unnecessary use of pointers, we try to detect common patterns of local allocations. For example, we detect when the result of a call to operator **`new`** is stored in a local variable and later explicitly deleted. This supports the [C++ Core Guidelines rule R.5](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#r5-prefer-scoped-objects-dont-heap-allocate-unnecessarily): *Prefer scoped objects, don't heap-allocate unnecessarily*. To fix the issue, use an RAII type instead of a raw pointer, and allow it to deal with resources. Obviously, it isn't necessary to create a wrapper type to allocate a single object. Instead, a local variable of the object's type would work better.
1212

1313
## Remarks
1414

15-
- To reduce the number of warnings, this pattern is detected for owner pointers only. So, it is necessary to mark owners properly first. We can easily extend this to cover raw pointers if we receive feedback from customers in support of such scenario.
15+
- To reduce the number of warnings, code analysis only detects this pattern for owner pointers. So, it's necessary to mark owners properly first. We can easily extend this to cover raw pointers if we receive [feedback](https://developercommunity.visualstudio.com/spaces/62/index.html) from customers in support of such scenarios.
1616

17-
- The scoped object term may be a bit misleading, but the general idea is that we suggest using either a local variable whose lifetime is automatically managed, or a smart object which efficiently manages dynamic resources. Smart objects can of course do heap allocations, but it is not explicit in the code.
17+
- The *scoped object* term may be a bit misleading. In general, we suggest you use either a local variable whose lifetime is automatically managed, or a smart object that efficiently manages dynamic resources. Smart objects can of course do heap allocations, but it's not explicit in the code.
1818

19-
- If the warning fires on array allocation (which is usually needed for dynamic buffers), the fix can be to use standard containers, or `std::unique_pointer<T[]>`.
19+
- If the warning fires on array allocation, (which is usually needed for dynamic buffers), you can fix it by using standard containers, or `std::unique_pointer<T[]>`.
2020

21-
- The pattern is detected only for local variables, so we don’t warn on cases where an allocation is assigned to, say, a global variable and then deleted in the same function.
21+
- The pattern is detected only for local variables. We don’t warn in cases where an allocation is assigned to, say, a global variable and then deleted in the same function.
2222

2323
## Example 1: Unnecessary object allocation on heap
2424

docs/code-quality/c26427.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ms.assetid: 8fb95a44-8704-45b1-bc55-eccd59b1db2f
1111
"Global initializer accesses extern object."
1212

1313
**C++ Core Guidelines**:
14-
I.22: Avoid complex initialization of global objects
14+
[I.22](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#i22-avoid-complex-initialization-of-global-objects): Avoid complex initialization of global objects
1515

1616
Global objects may be initialized in an inconsistent or undefined order, which means that interdependency between them is risky and should be avoided. This guideline is applicable when initializers refer to another object that's considered to be **`extern`**.
1717

docs/code-quality/c26498.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,35 @@
11
---
22
title: C26498
3-
ms.date: 03/22/2018
3+
ms.date: 08/18/2020
44
ms.topic: reference
55
f1_keywords: ["C26498"]
66
helpviewer_keywords: ["C26498"]
77
---
88
# C26498 USE_CONSTEXPR_FOR_FUNCTIONCALL
99

10-
This function call %function% can use `constexpr` if compile-time evaluation is desired. See [C++ Core Guidelines con.5](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rconst-constexpr).
10+
This rule helps to enforce Con.5 from the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#con5-use-constexpr-for-values-that-can-be-computed-at-compile-time): use constexpr for values that can be computed at compile time.
11+
12+
## Remarks
13+
14+
The warning is triggered by assigning the result of a **`constexpr`** function to any non-**`constexpr`** variable whose value doesn't change after the initial assignment.
15+
16+
## Example
17+
18+
This sample code shows where C26498 may appear, and how to avoid it:
19+
20+
```cpp
21+
constexpr int getMyValue()
22+
{
23+
return 1;
24+
}
25+
26+
void foo()
27+
{
28+
constexpr int val0 = getMyValue(); // no C26498
29+
const int val1 = getMyValue(); // C26498, C26814
30+
int val2 = getMyValue(); // C26498, value is never modified
31+
int val3 = getMyValue(); // no C26498, val3 is assigned to below.
32+
val3 = val3 * val2;
33+
}
34+
```
35+

0 commit comments

Comments
 (0)