You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Compiles source code to support Microsoft C++ component extensions C++/CX for the creation of Universal Windows Platform (UWP) apps.
12
11
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`**.
14
14
15
15
## Syntax
16
16
@@ -21,24 +21,24 @@ When you use **/ZW** to compile, always specify **/EHsc** as well.
21
21
22
22
## Arguments
23
23
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.
26
26
27
27
## Remarks
28
28
29
-
When you specify the **/ZW** option, the compiler supports these features:
29
+
When you specify the **`/ZW`** option, the compiler supports these features:
30
30
31
31
- The required metadata files, namespaces, data types, and functions that your app requires to execute in the Windows Runtime.
32
32
33
33
- Automatic reference-counting of Windows Runtime objects, and automatic discarding of an object when its reference count goes to zero.
34
34
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`**.
36
36
37
37
For more information, see [Visual C++ Language Reference](../../cppcx/visual-c-language-reference-c-cx.md).
[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.
17
17
18
18
## Remarks
19
19
@@ -23,10 +23,9 @@ The rule also flags cases where an assignment doesn't involve real data slicing
23
23
24
24
## Example
25
25
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:
27
27
28
28
```cpp
29
-
interface
30
29
structid {
31
30
int value;
32
31
};
@@ -45,7 +44,7 @@ bool read_id(stream &s, id &v) {
45
44
}
46
45
```
47
46
48
-
Slicing points to outdated interface - corrected:
47
+
To fix the issue, update the function to use the correct types:
description: CppCoreCheck rule C26439 that enforces C++ Core Guidelines F.6
4
+
ms.date: 05/17/2023
4
5
f1_keywords: ["C26439", "SPECIAL_NOEXCEPT"]
5
6
helpviewer_keywords: ["C26439"]
6
7
ms.assetid: 9df2a1b0-ea94-4884-9d28-c1522ec33a1b
7
-
description: CppCoreCheck rule C26439 that enforces C++ Core Guidelines F.6
8
8
---
9
9
# Warning C26439
10
10
11
11
> This kind of function may not throw. Declare it 'noexcept'.
12
12
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.
14
18
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`
16
20
17
21
## Remarks
18
22
19
23
- Special kinds of operations:
20
24
- destructors;
21
-
- default constructors;
22
25
- move constructors and move assignment operators;
23
26
- standard functions with move semantics: `std::move` and `std::swap`.
24
27
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`.
26
29
27
30
- Explicit specifiers `noexcept(false)` and `noexcept(true)` are respected appropriately.
28
31
29
-
- The warning may still appear for operations that are marked as `constexpr`. This check may change in future releases.
30
-
31
32
## Example
32
33
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`.
34
35
35
36
```cpp
36
37
structS
37
38
{
38
-
S() {} // C26455, Default constructor may not throw. Declare it 'noexcept'
39
39
~S() {}
40
40
41
41
S(S&& s) {/*impl*/} // C26439, This kind of function may not throw. Declare it 'noexcept' (f.6)
@@ -46,12 +46,11 @@ struct S
46
46
};
47
47
```
48
48
49
-
With noexcept decorating the same structure, all warnings are removed.
49
+
With `noexcept` decorating the same structure, all warnings are removed.
Copy file name to clipboardExpand all lines: docs/code-quality/c26455.md
+4-3Lines changed: 4 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
---
2
-
description: "Learn more about the C26455 DEFAULT_CTOR_NOEXCEPT C++ Core Guidelines Checker warning. Default constructors shouldn't do anything that can throw."
3
2
title: Warning C26455
3
+
description: "Learn more about the C26455 DEFAULT_CTOR_NOEXCEPT"
> Default constructor should not throw. Declare it '`noexcept`' (f.6)
15
15
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.
> The function '*function*' is constexpr, mark variable '*variable*' constexpr if compile-time evaluation is desired (con.5)
11
11
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.
13
13
14
14
## Remarks
15
15
16
16
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.
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
+
voidf() {
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
+
intg() {
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.
0 commit comments