Skip to content

Repo sync for protected CLA branch #4602

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jun 26, 2023
18 changes: 9 additions & 9 deletions docs/build/reference/zw-windows-runtime-compilation.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
---
description: "Learn more about: /ZW (Windows Runtime Compilation)"
title: "/ZW (Windows Runtime Compilation)"
ms.date: "04/08/2019"
ms.date: 06/22/2023
f1_keywords: ["VC.Project.VCCLCompilerTool.CompileAsWinRT", "/zw"]
helpviewer_keywords: ["/ZW", "-ZW compiler option", "/ZW compiler option", "-ZW", "Windows Runtime compiler option"]
ms.assetid: 0fe362b0-9526-498b-96e0-00d7a965a248
---
# /ZW (Windows Runtime Compilation)
# `/ZW` (Windows Runtime Compilation)

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

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

## Syntax

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

## Arguments

**nostdlib**<br/>
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.
**`nostdlib`**\
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.

## Remarks

When you specify the **/ZW** option, the compiler supports these features:
When you specify the **`/ZW`** option, the compiler supports these features:

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

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

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**.
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`**.

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

## Requirements

## See also

[MSVC Compiler Options](compiler-options.md)<br/>
[MSVC Compiler Options](compiler-options.md)\
[MSVC Compiler Command-Line Syntax](compiler-command-line-syntax.md)
13 changes: 6 additions & 7 deletions docs/code-quality/c26437.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: "Learn more about: Warning C26437 DONT_SLICE"
title: Warning C26437
ms.date: 10/07/2019
description: "Learn more about: Warning C26437 DONT_SLICE"
ms.date: 05/17/2023
f1_keywords: ["C26437", "DONT_SLICE"]
helpviewer_keywords: ["C26437"]
ms.assetid: ed2f55bc-a6d8-4cc4-8069-5c96e581a96a
Expand All @@ -11,9 +11,9 @@ ms.assetid: ed2f55bc-a6d8-4cc4-8069-5c96e581a96a
> Do not slice.

**C++ Core Guidelines**:
[ES.63: Don't slice](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Res-slice)
[ES.63: Don't slice](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Res-slice)

[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.
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.

## Remarks

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

## Example

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

```cpp
interface
struct id {
int value;
};
Expand All @@ -45,7 +44,7 @@ bool read_id(stream &s, id &v) {
}
```

Slicing points to outdated interface - corrected:
To fix the issue, update the function to use the correct types:

```cpp
// ...
Expand Down
28 changes: 16 additions & 12 deletions docs/code-quality/c26439.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
---
title: Warning C26439
ms.date: 11/15/2017
description: CppCoreCheck rule C26439 that enforces C++ Core Guidelines F.6
ms.date: 05/17/2023
f1_keywords: ["C26439", "SPECIAL_NOEXCEPT"]
helpviewer_keywords: ["C26439"]
ms.assetid: 9df2a1b0-ea94-4884-9d28-c1522ec33a1b
description: CppCoreCheck rule C26439 that enforces C++ Core Guidelines F.6
---
# Warning C26439

> This kind of function may not throw. Declare it 'noexcept'.

[**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
[**C++ Core Guidelines** F.6](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-noexcept): If your function must not throw, declare it `noexcept`

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.

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.

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.
Code analysis name: `SPECIAL_NOEXCEPT`

## Remarks

- Special kinds of operations:
- destructors;
- default constructors;
- move constructors and move assignment operators;
- standard functions with move semantics: `std::move` and `std::swap`.

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

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

- The warning may still appear for operations that are marked as `constexpr`. This check may change in future releases.

## Example

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

```cpp
struct S
{
S() {} // C26455, Default constructor may not throw. Declare it 'noexcept'
~S() {}

S(S&& s) {/*impl*/} // C26439, This kind of function may not throw. Declare it 'noexcept' (f.6)
Expand All @@ -46,12 +46,11 @@ struct S
};
```

With noexcept decorating the same structure, all warnings are removed.
With `noexcept` decorating the same structure, all warnings are removed.

```cpp
struct S
{
S() noexcept {}
~S() {}

S(S&& s) noexcept {/*impl*/}
Expand All @@ -61,3 +60,8 @@ struct S
S& operator=(const S& s) noexcept {/*impl*/}
};
```

## See also

[C26455](./c26455.md)\
[**C++ Core Guidelines** F.6](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-noexcept)
7 changes: 4 additions & 3 deletions docs/code-quality/c26455.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
description: "Learn more about the C26455 DEFAULT_CTOR_NOEXCEPT C++ Core Guidelines Checker warning. Default constructors shouldn't do anything that can throw."
title: Warning C26455
description: "Learn more about the C26455 DEFAULT_CTOR_NOEXCEPT"
ms.date: 04/29/2022
f1_keywords: ["C26455", "DEFAULT_CTOR_NOEXCEPT"]
helpviewer_keywords: ["C26455"]
Expand All @@ -13,7 +13,7 @@ ms.custom: kr2b-contr-experiment

> Default constructor should not throw. Declare it '`noexcept`' (f.6)

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

## Remarks

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

## See also

- [C++ Core Guideline F.6](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Rf-noexcept)
[C26439](./c26439.md)\
[**C++ Core Guidelines** F.6](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-noexcept)
33 changes: 30 additions & 3 deletions docs/code-quality/c26498.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
description: "Learn more about: Warning C26498 USE_CONSTEXPR_FOR_FUNCTIONCALL"
title: Warning C26498
description: "Learn more about: Warning C26498 USE_CONSTEXPR_FOR_FUNCTIONCALL"
ms.date: 08/18/2020
f1_keywords: ["C26498", "USE_CONSTEXPR_FOR_FUNCTIONCALL"]
helpviewer_keywords: ["C26498"]
Expand All @@ -9,15 +9,17 @@ helpviewer_keywords: ["C26498"]

> The function '*function*' is constexpr, mark variable '*variable*' constexpr if compile-time evaluation is desired (con.5)

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

## Remarks

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.

Code analysis name: `USE_CONSTEXPR_FOR_FUNCTIONCALL`

## Example

This sample code shows where C26498 may appear, and how to avoid it:
This sample code shows where C26498 may appear:

```cpp
constexpr int getMyValue()
Expand All @@ -34,3 +36,28 @@ void foo()
val3 = val3 * val2;
}
```

To fix the issues, mark `val1` and `val2` **`constexpr`**:

```cpp
constexpr int getMyValue()
{
return 1;
}

void foo()
{
constexpr int val0 = getMyValue(); // OK
constexpr int val1 = getMyValue(); // OK
constexpr int val2 = getMyValue(); // OK
int val3 = getMyValue(); // OK
val3 = val3 * val2;
}
```


## See also

[C26497](./c26407.md)\
[C26814](./c26814.md)\
[Con.5](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rconst-constexpr)
39 changes: 34 additions & 5 deletions docs/code-quality/c26800.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
description: "Learn more about: Warning C26800"
title: Warning C26800
description: "Learn more about: Warning C26800"
ms.date: 01/14/2019
f1_keywords: ["C26800", "USE_OF_A_MOVED_FROM_OBJECT"]
helpviewer_keywords: ["C26800"]
Expand All @@ -11,13 +11,42 @@ helpviewer_keywords: ["C26800"]

## Remarks

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`.
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.

The following methods are considered state resetting methods:
- Functions with the following case-insensitive substring in their name: `clear`, `clean`, `reset`, `free`, `destroy`, `release`, `dealloc`, `assign`
- Overloaded assignment operators, destructor

This check respects the `std::swap` operation:

```cpp
void f() {
Y y1, y2;
consume(std::move(y1));
std::swap(y1, y2);
y1.method(); // OK, valid after swap.
y2.method(); // warning C26800
}
```

The check also supports the `try_emplace` operations in STL that conditionally move its argument:

```cpp
int g() {
std::map<int, Y> m;
Y val;
auto emplRes = m.try_emplace(1, std::move(val));
if (!emplRes.second) {
val.method(); // No C26800, val was not moved because the insertion did not happen.
}
}
```

Code analysis name: `USE_OF_A_MOVED_FROM_OBJECT`

## Examples

The following code will generate C26800.
The following code generates C26800.

```cpp
#include <utility>
Expand All @@ -37,11 +66,11 @@ void use_cref(const T&);
void test() {
X x1;
X x2 = std::move(x1);
use_cref(x1); // @expected(26800)
use_cref(x1); // warning C26800
}
```

The following code won't generate C26800.
The following code doesn't generate C26800.

```cpp
#include <utility>
Expand Down
4 changes: 2 additions & 2 deletions docs/code-quality/c26813.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: "Learn more about: Warning C26813"
title: Warning C26813
ms.date: 03/02/2022
description: "Learn more about: Warning C26813"
ms.date: 05/17/2022
f1_keywords: ["C26813", "USE_BITWISE_AND_TO_CHEK_ENUM_FLAGS", "USE_BITWISE_AND_TO_CHECK_ENUM_FLAGS"]
helpviewer_keywords: ["C26813"]
---
Expand Down
4 changes: 2 additions & 2 deletions docs/code-quality/c26827.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: "Learn more about: Warning C26827"
title: Warning C26827
ms.date: 03/02/2022
description: "Learn more about: Warning C26827"
ms.date: 05/17/2023
f1_keywords: ["C26827", "ALMOST_BITWISE_ENUM"]
helpviewer_keywords: ["C26827"]
---
Expand Down
4 changes: 2 additions & 2 deletions docs/code-quality/c26828.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: "Learn more about: Warning C26828"
title: Warning C26828
ms.date: 03/02/2022
description: "Learn more about: Warning C26828"
ms.date: 05/17/2023
f1_keywords: ["C26828", "MIXING_OVERLAPPING_ENUMS"]
helpviewer_keywords: ["C26828"]
---
Expand Down