Skip to content

Commit 78a70b1

Browse files
Merge pull request #4602 from MicrosoftDocs/main638233975384908330sync_temp
For protected CLA branch, push strategy should use PR and merge to target branch method to work around git push error
2 parents 80b22db + 1a17816 commit 78a70b1

File tree

9 files changed

+105
-45
lines changed

9 files changed

+105
-45
lines changed
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
---
22
description: "Learn more about: /ZW (Windows Runtime Compilation)"
33
title: "/ZW (Windows Runtime Compilation)"
4-
ms.date: "04/08/2019"
4+
ms.date: 06/22/2023
55
f1_keywords: ["VC.Project.VCCLCompilerTool.CompileAsWinRT", "/zw"]
66
helpviewer_keywords: ["/ZW", "-ZW compiler option", "/ZW compiler option", "-ZW", "Windows Runtime compiler option"]
7-
ms.assetid: 0fe362b0-9526-498b-96e0-00d7a965a248
87
---
9-
# /ZW (Windows Runtime Compilation)
8+
# `/ZW` (Windows Runtime Compilation)
109

1110
Compiles source code to support Microsoft C++ component extensions C++/CX for the creation of Universal Windows Platform (UWP) apps.
1211

13-
When you use **/ZW** to compile, always specify **/EHsc** as well.
12+
When you use **`/ZW`** to compile, always specify **`/EHsc`** as well.\
13+
**`/ZW`** isn't compatible with **`/std:c++20`**.
1414

1515
## Syntax
1616

@@ -21,24 +21,24 @@ When you use **/ZW** to compile, always specify **/EHsc** as well.
2121

2222
## Arguments
2323

24-
**nostdlib**<br/>
25-
Indicates that Platform.winmd, Windows.Foundation.winmd, and other default Windows metadata (.winmd) files are not automatically included in the compilation. Instead, you must use the [/FU (Name Forced #using File)](fu-name-forced-hash-using-file.md) compiler option to explicitly specify Windows metadata files.
24+
**`nostdlib`**\
25+
Indicates that `Platform.winmd`, `Windows.Foundation.winmd`, and other default Windows metadata (`.winmd`) files aren't automatically included in the compilation. Instead, you must use the [`/FU` (Name Forced #using File)](fu-name-forced-hash-using-file.md) compiler option to explicitly specify Windows metadata files.
2626

2727
## Remarks
2828

29-
When you specify the **/ZW** option, the compiler supports these features:
29+
When you specify the **`/ZW`** option, the compiler supports these features:
3030

3131
- The required metadata files, namespaces, data types, and functions that your app requires to execute in the Windows Runtime.
3232

3333
- Automatic reference-counting of Windows Runtime objects, and automatic discarding of an object when its reference count goes to zero.
3434

35-
Because the incremental linker does not support the Windows metadata included in .obj files by using the **/ZW** option, the deprecated [/Gm (Enable Minimal Rebuild)](gm-enable-minimal-rebuild.md) option is incompatible with **/ZW**.
35+
Because the incremental linker doesn't support the Windows metadata included in .obj files by using the **`/ZW`** option, the deprecated [/Gm (Enable Minimal Rebuild)](gm-enable-minimal-rebuild.md) option is incompatible with **`/ZW`**.
3636

3737
For more information, see [Visual C++ Language Reference](../../cppcx/visual-c-language-reference-c-cx.md).
3838

3939
## Requirements
4040

4141
## See also
4242

43-
[MSVC Compiler Options](compiler-options.md)<br/>
43+
[MSVC Compiler Options](compiler-options.md)\
4444
[MSVC Compiler Command-Line Syntax](compiler-command-line-syntax.md)

docs/code-quality/c26437.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
description: "Learn more about: Warning C26437 DONT_SLICE"
32
title: Warning C26437
4-
ms.date: 10/07/2019
3+
description: "Learn more about: Warning C26437 DONT_SLICE"
4+
ms.date: 05/17/2023
55
f1_keywords: ["C26437", "DONT_SLICE"]
66
helpviewer_keywords: ["C26437"]
77
ms.assetid: ed2f55bc-a6d8-4cc4-8069-5c96e581a96a
@@ -11,9 +11,9 @@ ms.assetid: ed2f55bc-a6d8-4cc4-8069-5c96e581a96a
1111
> Do not slice.
1212
1313
**C++ Core Guidelines**:
14-
[ES.63: Don't slice](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Res-slice)
14+
[ES.63: Don't slice](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-slice)
1515

16-
[Slicing](https://en.wikipedia.org/wiki/Object_slicing) is allowed by the compiler and can be viewed as a special case of a dangerous implicit cast. Even if it's done intentionally and doesn't lead to immediate issues, it's still highly discouraged. It makes code unmaintainable, by forcing extra requirements on related data types. It's especially true if types are polymorphic or involve resource management.
16+
The language allows [slicing](https://en.wikipedia.org/wiki/Object_slicing) and can be viewed as a special case of a dangerous implicit cast. Even if it's done intentionally and doesn't lead to immediate issues, it's still highly discouraged. It makes code harder to change, by forcing extra requirements on related data types. It's especially true if types are polymorphic or involve resource management.
1717

1818
## Remarks
1919

@@ -23,10 +23,9 @@ The rule also flags cases where an assignment doesn't involve real data slicing
2323

2424
## Example
2525

26-
Slicing points to outdated interface:
26+
In the next code example, we read `id_ex`, but the caller of the function will only get a slice of the object:
2727

2828
```cpp
29-
interface
3029
struct id {
3130
int value;
3231
};
@@ -45,7 +44,7 @@ bool read_id(stream &s, id &v) {
4544
}
4645
```
4746
48-
Slicing points to outdated interface - corrected:
47+
To fix the issue, update the function to use the correct types:
4948
5049
```cpp
5150
// ...

docs/code-quality/c26439.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
---
22
title: Warning C26439
3-
ms.date: 11/15/2017
3+
description: CppCoreCheck rule C26439 that enforces C++ Core Guidelines F.6
4+
ms.date: 05/17/2023
45
f1_keywords: ["C26439", "SPECIAL_NOEXCEPT"]
56
helpviewer_keywords: ["C26439"]
67
ms.assetid: 9df2a1b0-ea94-4884-9d28-c1522ec33a1b
7-
description: CppCoreCheck rule C26439 that enforces C++ Core Guidelines F.6
88
---
99
# Warning C26439
1010

1111
> This kind of function may not throw. Declare it 'noexcept'.
1212
13-
[**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
13+
[**C++ Core Guidelines** F.6](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-noexcept): If your function must not throw, declare it `noexcept`
14+
15+
Some operations should never throw exceptions. Their implementations should be reliable and should handle possible errors conditions gracefully. They shouldn't use exceptions to indicate failure. This rule flags cases where such operations aren't explicitly marked as `noexcept`, which means that they may throw exceptions and consumers can't make assumptions about its reliability.
16+
17+
It's important for these functions to be reliable as they're often used as building blocks to implement functions with [exception safety guarantees](https://en.cppreference.com/w/cpp/language/exceptions). A move constructor that throws will force Standard Template Library (STL) containers to fall back to copy operations, reducing runtime performance.
1418

15-
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 aren't explicitly marked as `noexcept`, which means that they may throw exceptions and can't convey assumptions about their reliability.
19+
Code analysis name: `SPECIAL_NOEXCEPT`
1620

1721
## Remarks
1822

1923
- Special kinds of operations:
2024
- destructors;
21-
- default constructors;
2225
- move constructors and move assignment operators;
2326
- standard functions with move semantics: `std::move` and `std::swap`.
2427

25-
- Non-standard and outdated specifiers like `throw()` or `declspec(nothrow)` aren't equivalent to `noexcept`.
28+
- Nonstandard and outdated specifiers like `throw()` or `declspec(nothrow)` aren't equivalent to `noexcept`.
2629

2730
- Explicit specifiers `noexcept(false)` and `noexcept(true)` are respected appropriately.
2831

29-
- The warning may still appear for operations that are marked as `constexpr`. This check may change in future releases.
30-
3132
## Example
3233

33-
All functions except the destructor will warn because they're missing noexcept.
34+
The tool warns on all functions except the destructor because they're missing `noexcept`.
3435

3536
```cpp
3637
struct S
3738
{
38-
S() {} // C26455, Default constructor may not throw. Declare it 'noexcept'
3939
~S() {}
4040

4141
S(S&& s) {/*impl*/} // C26439, This kind of function may not throw. Declare it 'noexcept' (f.6)
@@ -46,12 +46,11 @@ struct S
4646
};
4747
```
4848
49-
With noexcept decorating the same structure, all warnings are removed.
49+
With `noexcept` decorating the same structure, all warnings are removed.
5050
5151
```cpp
5252
struct S
5353
{
54-
S() noexcept {}
5554
~S() {}
5655
5756
S(S&& s) noexcept {/*impl*/}
@@ -61,3 +60,8 @@ struct S
6160
S& operator=(const S& s) noexcept {/*impl*/}
6261
};
6362
```
63+
64+
## See also
65+
66+
[C26455](./c26455.md)\
67+
[**C++ Core Guidelines** F.6](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-noexcept)

docs/code-quality/c26455.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
description: "Learn more about the C26455 DEFAULT_CTOR_NOEXCEPT C++ Core Guidelines Checker warning. Default constructors shouldn't do anything that can throw."
32
title: Warning C26455
3+
description: "Learn more about the C26455 DEFAULT_CTOR_NOEXCEPT"
44
ms.date: 04/29/2022
55
f1_keywords: ["C26455", "DEFAULT_CTOR_NOEXCEPT"]
66
helpviewer_keywords: ["C26455"]
@@ -13,7 +13,7 @@ ms.custom: kr2b-contr-experiment
1313

1414
> Default constructor should not throw. Declare it '`noexcept`' (f.6)
1515
16-
The C++ Core Guidelines suggest that default constructors shouldn't do anything that can throw. If the default constructor is allowed to throw, operations such as move and swap will also throw which is undesirable because move and swap should always succeed. Parameterized constructors may throw.
16+
The C++ Core Guidelines suggest that default constructors shouldn't do anything that can throw. When the default constructor can throw, all code that relies on a properly instantiated object may also throw.
1717

1818
## Remarks
1919

@@ -23,4 +23,5 @@ Code analysis name: `DEFAULT_CTOR_NOEXCEPT`
2323

2424
## See also
2525

26-
- [C++ Core Guideline F.6](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rf-noexcept)
26+
[C26439](./c26439.md)\
27+
[**C++ Core Guidelines** F.6](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-noexcept)

docs/code-quality/c26498.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
description: "Learn more about: Warning C26498 USE_CONSTEXPR_FOR_FUNCTIONCALL"
32
title: Warning C26498
3+
description: "Learn more about: Warning C26498 USE_CONSTEXPR_FOR_FUNCTIONCALL"
44
ms.date: 08/18/2020
55
f1_keywords: ["C26498", "USE_CONSTEXPR_FOR_FUNCTIONCALL"]
66
helpviewer_keywords: ["C26498"]
@@ -9,15 +9,17 @@ helpviewer_keywords: ["C26498"]
99

1010
> The function '*function*' is constexpr, mark variable '*variable*' constexpr if compile-time evaluation is desired (con.5)
1111
12-
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.
12+
This rule helps to enforce Con.5 from the [C++ Core Guidelines](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rconst-constexpr): use constexpr for values that can be computed at compile time.
1313

1414
## Remarks
1515

1616
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.
1717

18+
Code analysis name: `USE_CONSTEXPR_FOR_FUNCTIONCALL`
19+
1820
## Example
1921

20-
This sample code shows where C26498 may appear, and how to avoid it:
22+
This sample code shows where C26498 may appear:
2123

2224
```cpp
2325
constexpr int getMyValue()
@@ -34,3 +36,28 @@ void foo()
3436
val3 = val3 * val2;
3537
}
3638
```
39+
40+
To fix the issues, mark `val1` and `val2` **`constexpr`**:
41+
42+
```cpp
43+
constexpr int getMyValue()
44+
{
45+
return 1;
46+
}
47+
48+
void foo()
49+
{
50+
constexpr int val0 = getMyValue(); // OK
51+
constexpr int val1 = getMyValue(); // OK
52+
constexpr int val2 = getMyValue(); // OK
53+
int val3 = getMyValue(); // OK
54+
val3 = val3 * val2;
55+
}
56+
```
57+
58+
59+
## See also
60+
61+
[C26497](./c26407.md)\
62+
[C26814](./c26814.md)\
63+
[Con.5](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rconst-constexpr)

docs/code-quality/c26800.md

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
description: "Learn more about: Warning C26800"
32
title: Warning C26800
3+
description: "Learn more about: Warning C26800"
44
ms.date: 01/14/2019
55
f1_keywords: ["C26800", "USE_OF_A_MOVED_FROM_OBJECT"]
66
helpviewer_keywords: ["C26800"]
@@ -11,13 +11,42 @@ helpviewer_keywords: ["C26800"]
1111
1212
## Remarks
1313

14-
Warning C26800 is triggered when variable is used after it has been moved from. A variable is considered moved from after it was passed to a function as rvalue reference. There are some legitimate exceptions for uses such as assignment, destruction, and some state resetting functions such as `std::vector::clear`.
14+
Warning C26800 is triggered when a variable is used after it has been moved from. A variable is considered moved from after it's passed to a function as rvalue reference. There are some exceptions for assignment, destruction, and some state resetting functions such as `std::vector::clear`. After using a state resetting function, we're free to use the variable. This check only reasons about the local variables.
15+
16+
The following methods are considered state resetting methods:
17+
- Functions with the following case-insensitive substring in their name: `clear`, `clean`, `reset`, `free`, `destroy`, `release`, `dealloc`, `assign`
18+
- Overloaded assignment operators, destructor
19+
20+
This check respects the `std::swap` operation:
21+
22+
```cpp
23+
void f() {
24+
Y y1, y2;
25+
consume(std::move(y1));
26+
std::swap(y1, y2);
27+
y1.method(); // OK, valid after swap.
28+
y2.method(); // warning C26800
29+
}
30+
```
31+
32+
The check also supports the `try_emplace` operations in STL that conditionally move its argument:
33+
34+
```cpp
35+
int g() {
36+
std::map<int, Y> m;
37+
Y val;
38+
auto emplRes = m.try_emplace(1, std::move(val));
39+
if (!emplRes.second) {
40+
val.method(); // No C26800, val was not moved because the insertion did not happen.
41+
}
42+
}
43+
```
1544

1645
Code analysis name: `USE_OF_A_MOVED_FROM_OBJECT`
1746

1847
## Examples
1948

20-
The following code will generate C26800.
49+
The following code generates C26800.
2150

2251
```cpp
2352
#include <utility>
@@ -37,11 +66,11 @@ void use_cref(const T&);
3766
void test() {
3867
X x1;
3968
X x2 = std::move(x1);
40-
use_cref(x1); // @expected(26800)
69+
use_cref(x1); // warning C26800
4170
}
4271
```
4372
44-
The following code won't generate C26800.
73+
The following code doesn't generate C26800.
4574
4675
```cpp
4776
#include <utility>

docs/code-quality/c26813.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
description: "Learn more about: Warning C26813"
32
title: Warning C26813
4-
ms.date: 03/02/2022
3+
description: "Learn more about: Warning C26813"
4+
ms.date: 05/17/2022
55
f1_keywords: ["C26813", "USE_BITWISE_AND_TO_CHEK_ENUM_FLAGS", "USE_BITWISE_AND_TO_CHECK_ENUM_FLAGS"]
66
helpviewer_keywords: ["C26813"]
77
---

docs/code-quality/c26827.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
description: "Learn more about: Warning C26827"
32
title: Warning C26827
4-
ms.date: 03/02/2022
3+
description: "Learn more about: Warning C26827"
4+
ms.date: 05/17/2023
55
f1_keywords: ["C26827", "ALMOST_BITWISE_ENUM"]
66
helpviewer_keywords: ["C26827"]
77
---

docs/code-quality/c26828.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
description: "Learn more about: Warning C26828"
32
title: Warning C26828
4-
ms.date: 03/02/2022
3+
description: "Learn more about: Warning C26828"
4+
ms.date: 05/17/2023
55
f1_keywords: ["C26828", "MIXING_OVERLAPPING_ENUMS"]
66
helpviewer_keywords: ["C26828"]
77
---

0 commit comments

Comments
 (0)