Merge branch 'master' of https://github.com/MicrosoftDocs/cpp-docs-pr… · codevenkat/cpp-docs@f44ceba · GitHub
Skip to content

Commit f44ceba

Browse files
Tyler WhitneyTyler Whitney
authored andcommitted
Merge branch 'master' of https://github.com/MicrosoftDocs/cpp-docs-pr into twhitney-c11-17
2 parents f1f7137 + afb7152 commit f44ceba

23 files changed

Lines changed: 397 additions & 27 deletions

docs/build/reference/cetcompat.md

Lines changed: 3 additions & 3 deletions

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/c26460.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,34 @@ ms.date: 03/22/2018
44
ms.topic: reference
55
f1_keywords: ["C26460"]
66
helpviewer_keywords: ["C26460"]
7+
description: CppCoreCheck rule that enforces C++ Core Guidelines Con.3
78
---
89
# C26460 USE_CONST_REFERENCE_ARGUMENTS
10+
The reference argument '%argument%' for function '%function%' can be marked as `const` (con.3).
911

10-
The reference argument '%argument%' for function '%function%' can be marked as `const`. See [C++ Core Guidelines con.3](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rconst-ref).
12+
Passing an object by reference indicates that the function has the potential modify the object. If that is not the intent of the function, it is better to mark the argument as a const reference.
13+
14+
## See also
15+
[C++ Core Guidelines con.3](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rconst-ref).
16+
17+
## Example
18+
```cpp
19+
struct MyStruct
20+
{
21+
void MemberFn1() const;
22+
void MemberFn2();
23+
};
24+
25+
26+
void Function1_Helper(const MyStruct&);
27+
void Function1(MyStruct& myStruct) // C26460, see comments below.
28+
{
29+
myStruct.MemberFn1(); // The member function is marked as const
30+
Function1_Helper(myStruct); // Function1_Helper takes a const reference
31+
}
32+
33+
void Function2(MyStruct& myStruct)
34+
{
35+
myStruct.MemberFn2(); // MemberFn2 is non-const and has the potential to modify data
36+
}
37+
```

docs/code-quality/c26461.md

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

10-
The pointer argument '%argument%' for function '%function%' can be marked as a pointer to `const`. See [C++ Core Guidelines con.3](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rconst-ref).
11+
The pointer argument '%argument%' for function '%function%' can be marked as a pointer to `const` (con.3).
12+
13+
A function with a `T*` argument has the potential to modify the value of the object. If that is not the intent of the function, it is better to make the pointer a `const T*` instead.
14+
15+
## See also
16+
[C++ Core Guidelines con.3](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rconst-ref).
17+
18+
## Example
19+
```cpp
20+
struct MyStruct
21+
{
22+
void MemberFn1() const;
23+
void MemberFn2();
24+
};
25+
26+
void Function1_Helper(const MyStruct* myStruct);
27+
void Function1(MyStruct* myStruct) // C26461, neither of the operations on myStruct would modify the pointer's value.
28+
{
29+
if (!myStruct)
30+
return;
31+
32+
myStruct->MemberFn1(); // The member function is const
33+
Function1_Helper(myStruct); // Function1_Helper takes a const
34+
}
35+
36+
void Function2(MyStruct* myStruct)
37+
{
38+
if (!myStruct)
39+
return;
40+
41+
myStruct->MemberFn2(); // The member function is non-const, so no C26461 will be issued
42+
}
43+
```

docs/code-quality/c26462.md

Lines changed: 20 additions & 1 deletion

0 commit comments

Comments
 (0)