Skip to content

Commit e58918c

Browse files
authored
Merge pull request MicrosoftDocs#3104 from MicrosoftDocs/master
9/1 AM Publishing
2 parents 3628707 + 8b795a6 commit e58918c

14 files changed

Lines changed: 232 additions & 26 deletions

File tree

docs/build/reference/cetcompat.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: "/CETCOMPAT (CET Shadow Stack compatible)"
3-
ms.date: "06/30/2020"
3+
ms.date: "09/01/2020"
44
f1_keywords: ["/CETCOMPAT"]
55
helpviewer_keywords: ["/CETCOMPAT linker option", "/CETCOMPAT"]
66
---
@@ -36,15 +36,15 @@ Starting in Visual Studio 2019 version 16.7:
3636

3737
1. Select the **CET Shadow Stack Compatible** property.
3838

39-
1. In the dropdown control, choose **`Yes (/CETCOMPAT)`** to enable EH continuation metadata, or **`No (/CETCOMPAT:NO)`** to disable it.
39+
1. In the dropdown control, choose **`Yes (/CETCOMPAT)`** to mark the binary as CET Shadow Stack compatible , or **`No (/CETCOMPAT:NO)`** to mark it as non-compatible.
4040

4141
In previous versions of Visual Studio 2019:
4242

4343
1. Open the **Property Pages** dialog box for the project. For more information, see [Working with Project Properties](../working-with-project-properties.md).
4444

4545
1. Select the **Configuration Properties** > **Linker** > **Command Line** property page.
4646

47-
1. In the **Additional Options** edit control, add *`/CETCOMPAT`* to enable EH continuation metadata, or *`/CETCOMPAT:NO`* to explicitly disable it.
47+
1. In the **Additional Options** edit control, add *`/CETCOMPAT`* to mark the binary as CET Shadow Stack compatible, or *`/CETCOMPAT:NO`* to explicitly mark it as non-compatible.
4848

4949
### To set this linker option programmatically
5050

docs/build/reference/linker-options.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "MSVC Linker options"
33
description: "A list of the options supported by the Microsoft LINK linker."
4-
ms.date: "02/09/2020"
4+
ms.date: "09/01/2020"
55
f1_keywords: ["link"]
66
helpviewer_keywords: ["linker [C++]", "linker [C++], options listed", "libraries [C++], linking to COFF", "LINK tool [C++], linker options"]
77
ms.assetid: c1d51b8a-bd23-416d-81e4-900e02b2c129
@@ -38,6 +38,7 @@ You can use the [comment](../../preprocessor/comment-c-cpp.md) pragma to specify
3838
|[/ASSEMBLYMODULE](assemblymodule-add-a-msil-module-to-the-assembly.md)|Specifies that a Microsoft intermediate language (MSIL) module should be imported into the assembly.|
3939
|[/ASSEMBLYRESOURCE](assemblyresource-embed-a-managed-resource.md)|Embeds a managed resource file in an assembly.|
4040
|[/BASE](base-base-address.md)|Sets a base address for the program.|
41+
|[/CETCOMPAT](cetcompat.md)|Marks the binary as CET Shadow Stack compatible.|
4142
|[/CGTHREADS](cgthreads-compiler-threads.md)|Sets number of cl.exe threads to use for optimization and code generation when link-time code generation is specified.|
4243
|[/CLRIMAGETYPE](clrimagetype-specify-type-of-clr-image.md)|Sets the type (IJW, pure, or safe) of a CLR image.|
4344
|[/CLRSUPPORTLASTERROR](clrsupportlasterror-preserve-last-error-code-for-pinvoke-calls.md)|Preserves the last error code of functions that are called through the P/Invoke mechanism.|

docs/code-quality/c26401.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,40 @@ 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
89
---
910
# C26401 DONT_DELETE_NON_OWNER
1011

1112
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.
1213

1314
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.
15+
16+
## See also
17+
[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)
18+
19+
## Example
20+
```cpp
21+
struct myStruct {};
22+
23+
myStruct* createMyStruct();
24+
void function()
25+
{
26+
myStruct* pMyStruct = createMyStruct();
27+
// ...
28+
delete pMyStruct; // C26401. Do not delete a raw pointer that is not an owner<T>
29+
}
30+
```
31+
32+
See that C26401 is removed if ownership of the pointer is indicated by gsl::owner.
33+
```cpp
34+
#include <gsl/pointers>
35+
struct myStruct {};
36+
37+
gsl::owner<myStruct*> createMyStruct();
38+
void function()
39+
{
40+
gsl::owner<myStruct*> pMyStruct = createMyStruct();
41+
// ...
42+
delete pMyStruct; // no warning.
43+
}
44+
```

docs/code-quality/c26408.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ ms.topic: "conceptual"
55
f1_keywords: ["C26408"]
66
helpviewer_keywords: ["C26408"]
77
ms.assetid: 55b0706f-1107-41c1-8ad0-c9e1e86a3b8c
8+
description: CppCoreCheck rule that enforces C++ Core Guidelines R.10
89
---
910
# C26408 NO_MALLOC_FREE
1011

@@ -15,3 +16,23 @@ This warning flags places where `malloc` or `free` is invoked explicitly in acco
1516
- To detect malloc() we check if a call invokes a global function with name "malloc" or "std::malloc". The function must return a pointer to **`void`** and accept one parameter of unsigned integral type.
1617

1718
- To detect free() we check global functions with names "free" or "std::free" which return no result and accept one parameter, which is a pointer to **`void`**.
19+
20+
## See also
21+
[C++ Core Guidelines R.10](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#r10-avoid-malloc-and-free)
22+
23+
## Example
24+
```cpp
25+
#include <new>
26+
27+
struct myStruct {};
28+
29+
void function_malloc_free() {
30+
myStruct* ms = static_cast<myStruct*>(malloc(sizeof(myStruct))); // C26408
31+
free(ms); // C26408
32+
}
33+
34+
void function_nothrow_new_delete() {
35+
myStruct* ms = new(std::nothrow) myStruct;
36+
operator delete (ms, std::nothrow);
37+
}
38+
```

docs/code-quality/c26436.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,46 @@ ms.topic: "conceptual"
55
f1_keywords: ["C26436"]
66
helpviewer_keywords: ["C26436"]
77
ms.assetid: 82d14d5d-5c5d-4e27-bdc8-268f9973a312
8+
description: CppCoreCheck rule that enforces C++ Core Guidelines C.35
89
---
910
# C26436 NEED_VIRTUAL_DTOR
1011

1112
"The type with a virtual function needs either public virtual or protected nonvirtual destructor."
1213

13-
**C++ Core Guidelines**:
14-
C.35: A base class destructor should be either public and virtual, or protected and nonvirtual
14+
[**C++ Core Guidelines**: C.35](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c35-a-base-class-destructor-should-be-either-public-and-virtual-or-protected-and-non-virtual): A base class destructor should be either public and virtual, or protected and nonvirtual
1515

1616
If a class defines a virtual function it becomes polymorphic, which implies that derived classes can change its behavior including resource management and destruction logic. Because client code may call polymorphic types via pointers to base classes, there is no way a client can explicitly choose which behavior is appropriate without downcasting. To make sure that resources are managed consistently and destruction occurs according to the actual type's rules it is recommended to define a public virtual destructor. If the type hierarchy is designed to disallow client code to destroy objects directly, destructors should be defined as protected non-virtual.
1717

1818
## Remarks
1919

2020
- The warning shows up on the first virtual function definition of a type (it can be a virtual destructor if it is not public), once per type.
2121
- Since definition can be placed separately from declaration, it may not always have any of the virtual specifiers. But the warning is still valid – it checks the actual 'virtuality' of a function.
22+
23+
## Example
24+
```cpp
25+
namespace no_destructor
26+
{
27+
struct base {
28+
virtual void foo() {} // C26436, see remarks to understand the placement of the warning.
29+
};
30+
}
31+
```
32+
33+
The warning does not appear when the base class has either a virtual public destructor or a protected non-virtual destructor.
34+
```cpp
35+
namespace virtual_destructor
36+
{
37+
struct base {
38+
virtual ~base();
39+
virtual void foo() {}
40+
};
41+
}
42+
namespace protected_destructor
43+
{
44+
struct base {
45+
virtual void foo() {}
46+
protected:
47+
~base() {}
48+
};
49+
}
50+
```

docs/code-quality/c26439.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ ms.topic: "conceptual"
55
f1_keywords: ["C26439"]
66
helpviewer_keywords: ["C26439"]
77
ms.assetid: 9df2a1b0-ea94-4884-9d28-c1522ec33a1b
8+
description: CppCoreCheck rule that enforces C++ Core Guidelines F.6
89
---
910
# C26439 SPECIAL_NOEXCEPT
1011

1112
"This kind of function may not throw. Declare it 'noexcept'."
1213

13-
**C++ Core Guidelines**:
14-
F.6: If your function may not throw, declare it noexcept
14+
[**C++ Core Guidelines** F.6](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#f6-if-your-function-may-not-throw-declare-it-noexcept): If your function may not throw, declare it noexcept
1515

1616
Some kinds of operations should never cause exceptions. Their implementations should be reliable and should handle possible errors conditions gracefully. They should never use exceptions to indicate failure. This rule flags cases where such operations are not explicitly marked as 'noexcept' which means that they may throw exceptions and cannot convey assumptions about their reliability.
1717

@@ -25,3 +25,33 @@ Some kinds of operations should never cause exceptions. Their implementations sh
2525
- Non-standard and outdated specifiers like throw() or declspec(nothrow) are not equivalent to 'noexcept'.
2626
- Explicit specifiers noexcept(false) and noexcept(true) are respected appropriately.
2727
- The warning may still appear for operations that are marked as constexpr. This may change in future releases.
28+
29+
## Example
30+
All functions except the destructor will warn because they are missing noexcept.
31+
```cpp
32+
struct S
33+
{
34+
S() {} // C26455, Default constructor may not throw. Declare it 'noexcept'
35+
~S() {}
36+
37+
S(S&& s) {/*impl*/} // C26439, This kind of function may not throw. Declare it 'noexcept' (f.6)
38+
S& operator=(S&& s) {/*impl*/} // C26439, This kind of function may not throw. Declare it 'noexcept' (f.6)
39+
40+
S(const S& s) {/*impl*/} // C26440, This function can be declared 'noexcept'
41+
S& operator=(const S& s) {/*impl*/} // C26440, This function can be declared 'noexcept'
42+
};
43+
```
44+
With noexcept decorating the same structure, all warnings are removed.
45+
```cpp
46+
struct S
47+
{
48+
S() noexcept {}
49+
~S() {}
50+
51+
S(S&& s) noexcept {/*impl*/}
52+
S& operator=(S&& s) noexcept {/*impl*/}
53+
54+
S(const S& s) noexcept {/*impl*/}
55+
S& operator=(const S& s) noexcept {/*impl*/}
56+
};
57+
```

docs/code-quality/c26440.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ ms.topic: "conceptual"
55
f1_keywords: ["C26440"]
66
helpviewer_keywords: ["C26440"]
77
ms.assetid: b6d2b188-35cc-4de2-878c-6f97d5a2444a
8+
description: CppCoreCheck rule that enforces C++ Core Guidelines F.6
89
---
910
# C26440 DECLARE_NOEXCEPT
1011

1112
"Function can be declared 'noexcept'."
1213

13-
**C++ Core Guidelines**:
14-
F.6: If your function may not throw, declare it noexcept
14+
[**C++ Core Guidelines** F.6](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#f6-if-your-function-may-not-throw-declare-it-noexcept): If your function may not throw, declare it noexcept
1515

1616
If code is not supposed to cause any exceptions, it should be marked as such by using the 'noexcept' specifier. This would help to simplify error handling on the client code side, as well as enable compiler to do additional optimizations.
1717

@@ -25,3 +25,33 @@ If code is not supposed to cause any exceptions, it should be marked as such by
2525
- Functions marked as constexpr are not supposed to cause exceptions and are not analyzed.
2626
- The rule also applies to lambda expressions.
2727
- The logic doesn't consider recursive calls as potentially non-throwing. This may change in the future.
28+
29+
## Example
30+
All functions except the destructor will warn because they are missing noexcept.
31+
```cpp
32+
struct S
33+
{
34+
S() {} // C26455, Default constructor may not throw. Declare it 'noexcept'
35+
~S() {}
36+
37+
S(S&& s) {/*impl*/} // C26439, This kind of function may not throw. Declare it 'noexcept' (f.6)
38+
S& operator=(S&& s) {/*impl*/} // C26439, This kind of function may not throw. Declare it 'noexcept' (f.6)
39+
40+
S(const S& s) {/*impl*/} // C26440, This function can be declared 'noexcept'
41+
S& operator=(const S& s) {/*impl*/} // C26440, This function can be declared 'noexcept'
42+
};
43+
```
44+
With noexcept decorating the same structure, all warnings are removed.
45+
```cpp
46+
struct S
47+
{
48+
S() noexcept {}
49+
~S() {}
50+
51+
S(S&& s) noexcept {/*impl*/}
52+
S& operator=(S&& s) noexcept {/*impl*/}
53+
54+
S(const S& s) noexcept {/*impl*/}
55+
S& operator=(const S& s) noexcept {/*impl*/}
56+
};
57+
```

docs/code-quality/c26482.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,21 @@ ms.date: 03/22/2018
44
ms.topic: reference
55
f1_keywords: ["C26482"]
66
helpviewer_keywords: ["C26482"]
7+
description: CppCoreCheck rule that enforces C++ Core Guidelines Bounds.2
78
---
89
# C26482 NO_DYNAMIC_ARRAY_INDEXING
910

10-
Only index into arrays using constant expressions. See [C++ Core Guidelines Bounds.2](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#SS-bounds)
11+
Only index into arrays using constant expressions.
12+
## See also
13+
[C++ Core Guidelines Bounds.2](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#SS-bounds)
14+
15+
## Example
16+
17+
```cpp
18+
int getSomeIndex();
19+
20+
void function(int* p, int count)
21+
{
22+
p[getSomeIndex()] = 0; // C26482, Only index into arrays using constant expressions
23+
}
24+
```

docs/code-quality/c26490.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,18 @@ ms.date: 03/22/2018
44
ms.topic: reference
55
f1_keywords: ["C26490"]
66
helpviewer_keywords: ["C26490"]
7+
description: CppCoreCheck rule that enforces C++ Core Guidelines Type.1
78
---
89
# C26490 NO_REINTERPRET_CAST
910

10-
Don't use `reinterpret_cast`. See [C++ Core Guidelines Type.1](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#SS-type).
11+
Don't use `reinterpret_cast`.
12+
## See also
13+
[C++ Core Guidelines Type.1](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#SS-type).
14+
15+
## Example
16+
```cpp
17+
void function(void* ptr)
18+
{
19+
std::size_t val = reinterpret_cast<std::size_t>(ptr); // C26490, Don't use reinterpret_cast
20+
}
21+
```

docs/code-quality/c26492.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,20 @@ ms.date: 03/22/2018
44
ms.topic: reference
55
f1_keywords: ["C26492"]
66
helpviewer_keywords: ["C26492"]
7+
description: CppCoreCheck rule that enforces C++ Core Guidelines Type.3
78
---
89
# C26492 NO_CONST_CAST
910

10-
Don't use `const_cast` to cast away `const`. See [C++ Core Guidelines Type.3](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#SS-type).
11+
Don't use `const_cast` to cast away `const`.
12+
13+
## See also
14+
[C++ Core Guidelines Type.3](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#SS-type).
15+
16+
## Example
17+
18+
```cpp
19+
void function(const int* constIntPtr)
20+
{
21+
int* intPtr = const_cast<int*>(constIntPtr); // C26492, Do not use const_cast to cast away const
22+
}
23+
```

0 commit comments

Comments
 (0)