Skip to content

Commit 8efa696

Browse files
Merge pull request #4595 from MicrosoftDocs/main638229656532987699sync_temp
For protected CLA branch, push strategy should use PR and merge to target branch method to work around git push error
2 parents 358c9dc + 646f98f commit 8efa696

File tree

2 files changed

+83
-9
lines changed

2 files changed

+83
-9
lines changed

docs/build/reference/std-specify-language-standard-version.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ The compiler doesn't support most optional features of ISO C11. Several of these
103103

104104
- `aligned_alloc` support is missing, because of the Windows heap implementation. The alternative is to use [`_aligned_malloc`](../../c-runtime-library/reference/aligned-malloc.md).
105105

106-
- [DR 400](https://wg14.link/n2148#dr_400) support is currently unimplemented for `realloc`, because this change would break the ABI.
106+
- [Defect report 400](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2148.htm#dr_400) support is currently unimplemented for `realloc` because this change would break the ABI.
107107

108108
- Variable length array (VLA) support isn't planned. VLAs provide attack vectors comparable to [`gets`](../../c-runtime-library/gets-getws.md), which is deprecated and planned for removal.
109109

docs/overview/cpp-conformance-improvements.md

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,88 @@
11
---
22
title: "C++ conformance improvements in Visual Studio 2022"
33
description: "Microsoft C++ in Visual Studio is improving standards conformance and fixing bugs regularly."
4-
ms.date: 03/01/2023
4+
ms.date: 06/19/2023
55
ms.technology: "cpp-language"
66
---
77
# C++ Conformance improvements, behavior changes, and bug fixes in Visual Studio 2022
88

9-
Microsoft C/C++ in Visual Studio (MSVC) makes conformance improvements and bug fixes in every release. This article lists the significant improvements by major release, then by version. To jump directly to the changes for a specific version, use the list below **In this article**.
9+
Microsoft C/C++ in Visual Studio (MSVC) makes conformance improvements and bug fixes in every release. This article lists the significant improvements by major release, then by version. To jump directly to the changes for a specific version, use **In this article** links, above.
1010

11-
This document lists the changes in Visual Studio 2022. For a guide to the changes in Visual Studio 2019, see [C++ conformance improvements in Visual Studio 2019](cpp-conformance-improvements-2019.md). For changes in Visual Studio 2017, see [C++ conformance improvements in Visual Studio 2017](cpp-conformance-improvements-2017.md). For a complete list of previous conformance improvements, see [Visual C++ What's New 2003 through 2015](../porting/visual-cpp-what-s-new-2003-through-2015.md).
11+
This document lists the changes in Visual Studio 2022:
12+
13+
- For a guide to the changes in Visual Studio 2019, see [C++ conformance improvements in Visual Studio 2019](cpp-conformance-improvements-2019.md).
14+
- For changes in Visual Studio 2017, see [C++ conformance improvements in Visual Studio 2017](cpp-conformance-improvements-2017.md).
15+
- For a complete list of previous conformance improvements, see [Visual C++ What's New 2003 through 2015](../porting/visual-cpp-what-s-new-2003-through-2015.md).
16+
17+
## <a name="improvements_176"></a> Conformance improvements in Visual Studio 2022 version 17.6
18+
19+
Visual Studio 2022 version 17.6 contains the following conformance improvements, bug fixes, and behavior changes in the Microsoft C/C++ compiler.
20+
21+
### Compound `volatile` assignments no longer deprecated
22+
23+
C++20 deprecated applying certain operators to types qualified with `volatile`. For example, when the following code is compiled with `cl /std:c++20 /Wall test.cpp`:
24+
25+
```cpp
26+
void f(volatile int& expr)
27+
{
28+
++expr;
29+
}
30+
```
31+
32+
The compiler produces `test.cpp(3): warning C5214: applying '++' to an operand with a volatile qualified type is deprecated in C++20`.
33+
34+
In C++20, compound assignment operators (operators of the form `@=`) were deprecated. In C++23, compound operators excluded in C++20 are no longer deprecated. For example, in C++23 the following code doesn't produce a warning, whereas it does in C++20:
35+
36+
```cpp
37+
void f(volatile int& e1, int e2)
38+
{
39+
e1 += e2;
40+
}
41+
```
42+
43+
For more information about this change, see [CWG:2654](https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#2654)
44+
45+
### Rewriting equality in expressions is less of a breaking change (P2468R2)
46+
47+
In C++20, [P2468R2](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2468r2.html) changed the compiler to accept code such as:
48+
49+
```cpp
50+
struct S
51+
{
52+
bool operator==(const S&);
53+
bool operator!=(const S&);
54+
};
55+
bool b = S{} != S{};
56+
```
57+
58+
The compiler accepts this code, which means that the compiler is more strict with code such as:
59+
60+
```c++
61+
struct S
62+
{
63+
operator bool() const;
64+
bool operator==(const S&);
65+
};
66+
67+
bool b = S{} == S{};
68+
```
69+
70+
Version 17.5 of the compiler accepts this program. Version 17.6 of the compiler rejects it. To fix it, add `const` to `operator==` to remove the ambiguity. Or, add a corresponding `operator!=` to the definition as shown in the following example:
71+
72+
```cpp
73+
struct S
74+
{
75+
operator bool() const;
76+
bool operator==(const S&);
77+
bool operator!=(const S&);
78+
};
79+
80+
bool b = S{} == S{};
81+
```
82+
83+
Microsoft C/C++ compiler versions 17.5 and 17.6 accept the previous program, and calls `S::operator==` in both versions.
84+
85+
The general programming model outlined in P2468R2 is that if there's a corresponding `operator!=` for a type, it typically suppresses the rewrite behavior. Adding a corresponding `operator!=` is the suggested fix for code that previously compiled in C++17. For more information, see [Programming Model](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2468r2.html#programming-model).
1286

1387
## <a name="improvements_174"></a> Conformance improvements in Visual Studio 2022 version 17.4
1488

@@ -58,7 +132,7 @@ enum Changed
58132
59133
In versions of Visual Studio before Visual Studio 2022 version 17.4, the C++ compiler didn't correctly model the types of enumerators. It could assume an incorrect type in enumerations without a fixed underlying type before the closing brace of the enumeration. Under [`/Zc:enumTypes`](../build/reference/zc-enumtypes.md), the compiler now correctly implements the standard behavior.
60134
61-
The C++ Standard specifies that within an enumeration definition of no fixed underlying type, the types of enumerators are determined by their initializers. Or, for the enumerators with no initializer, by the type of the previous enumerator (accounting for overflow). Previously, such enumerators were always given the deduced type of the enumeration, with a placeholder for the underlying type (typically **`int`**).
135+
The C++ Standard specifies that within an enumeration definition of no fixed underlying type, initializers determine the types of enumerators. Or, for the enumerators with no initializer, by the type of the previous enumerator (accounting for overflow). Previously, such enumerators were always given the deduced type of the enumeration, with a placeholder for the underlying type (typically **`int`**).
62136
63137
When enabled, the **`/Zc:enumTypes`** option is a potential source and binary breaking change. It's off by default, and not enabled by **`/permissive-`**, because the fix may affect binary compatibility. Some enumeration types change size when the conformant fix is enabled. Certain Windows SDK headers include such enumeration definitions.
64138
@@ -252,9 +326,9 @@ void f()
252326

253327
Visual Studio 2022 version 17.1 contains the following conformance improvements, bug fixes, and behavior changes in the Microsoft C/C++ compiler.
254328

255-
### Detect ill-formed capture default in non-local lambda-expressions
329+
### Detect ill-formed capture default in nonlocal lambda-expressions
256330

257-
The C++ Standard only allows a lambda expression in block scope to have a capture-default. In Visual Studio 2022 version 17.1 and later, the compiler detects when a capture default isn't allowed in a non-local lambda expression. It emits a new level 4 warning, C5253.
331+
The C++ Standard only allows a lambda expression in block scope to have a capture-default. In Visual Studio 2022 version 17.1 and later, the compiler detects when a capture default isn't allowed in a nonlocal lambda expression. It emits a new level 4 warning, C5253.
258332

259333
This change is a source breaking change. It applies in any mode that uses the new lambda processor: **`/Zc:lambda`**, **`/std:c++20`**, or **`/std:c++latest`**.
260334

@@ -267,7 +341,7 @@ In Visual Studio 2022 version 17.1 this code now emits an error:
267341

268342
auto incr = [=](int value) { return value + 1; };
269343

270-
// capture_default.cpp(3,14): error C5253: a non-local lambda cannot have a capture default
344+
// capture_default.cpp(3,14): error C5253: a nonlocal lambda cannot have a capture default
271345
// auto incr = [=](int value) { return value + 1; };
272346
// ^
273347
```
@@ -301,7 +375,7 @@ int main(void)
301375
// C4113: 'int (__cdecl *)(char *)' differs in parameter lists from 'int (__cdecl *)(int)'
302376
```
303377
304-
### Error on a non-dependent `static_assert`
378+
### Error on a nondependent `static_assert`
305379
306380
In Visual Studio 2022 version 17.1 and later, if the expression associated with a `static_assert` isn't a dependent expression, the compiler evaluates the expression as soon as it's parsed. If the expression evaluates to `false`, the compiler emits an error. Previously, if the `static_assert` was within the body of a function template (or within the body of a member function of a class template), the compiler wouldn't perform this analysis.
307381

0 commit comments

Comments
 (0)