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
Copy file name to clipboardExpand all lines: docs/overview/cpp-conformance-improvements.md
+12-15Lines changed: 12 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: "C++ conformance improvements in Visual Studio 2022"
3
3
description: "Microsoft C++ in Visual Studio is improving standards conformance and fixing bugs regularly."
4
-
ms.date: 05/29/2024
4
+
ms.date: 05/31/2024
5
5
ms.service: "visual-cpp"
6
6
ms.subservice: "cpp-lang"
7
7
---
@@ -19,11 +19,11 @@ For changes in older versions, see [Visual C++ What's New 2003 through 2015](../
19
19
20
20
Visual Studio 2022 version 17.10 contains the following conformance improvements, bug fixes, and behavior changes in the Microsoft C/C++ compiler.
21
21
22
-
For an in-depth summary of changes made to the Standard Template Library, including bug fixes and performance improvements, see [STL Changelog VS 2022 17.10](https://github.com/microsoft/STL/wiki/Changelog#vs-2022-1710).
22
+
For an in-depth summary of changes made to the Standard Template Library, including conformance changes, bug fixes and performance improvements, see [STL Changelog VS 2022 17.10](https://github.com/microsoft/STL/wiki/Changelog#vs-2022-1710).
23
23
24
24
### Conversion operator specialization with explicitly specified return type
25
25
26
-
The compiler used to specialize conversion operators incorrectly in some cases which could lead to mismatched return type. These invalid specializations no longer happen. This is a source code breaking change.
26
+
The compiler used to specialize conversion operators incorrectly in some cases which could lead to a mismatched return type. These invalid specializations no longer happen. This is a source code breaking change.
27
27
28
28
```cpp
29
29
// Example 1
@@ -56,7 +56,7 @@ void test()
56
56
57
57
### Added Support for `#elifdef` and `#elifndef`
58
58
59
-
Support added for WG21 [P2334R1](https://www.open-std.org/JTC1/SC22/WG21/docs/papers/2021/p2334r1.pdf) (C++23) and WG14 [N2645](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2645.pdf) (C23) which introduced the `#elifdef` and `#elifndef` preprocessor directives.
59
+
Support added for WG21 [P2334R1](https://www.open-std.org/JTC1/SC22/WG21/docs/papers/2021/p2334r1.pdf) (C++23) and WG14 [N2645](https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2645.pdf) (C++23) which introduced the `#elifdef` and `#elifndef` preprocessor directives.
According to the ISO-C Standard, this code should compile without `static_assert` emitting a diagnostic.
105
105
106
-
The `_Alignas` directive applies only to the member variable `member1`. It must not change the alignment of `struct Inner`. However, before Visual Studio 17.9.1, the diagnostic "incorrect alignment" was emitted. The compiler aligned `member2` to an offset of 32 bytes within the `struct Outer` type.
106
+
The `_Alignas` directive applies only to the member variable `member1`. It must not change the alignment of `struct Inner`. However, before Visual Studio 17.9.1, the diagnostic "incorrect alignment" was emitted. The compiler aligned `member2` to an offset of 32 bytes within the `struct Outer` type.
107
107
108
-
This is a binary breaking change, so a warning is now emitted when this change takes effect. Warning C5274 is now emitted at warning level 1 for the previous code:
109
-
110
-
```cpp
111
-
warning C5274: behavior change: _Alignas no longer applies to the type 'Inner' (only applies to declared data objects)
112
-
```
108
+
This is a binary breaking change, so a warning is now emitted when this change takes effect. Warning C5274 is now emitted at warning level 1 for the previous example: `
109
+
warning C5274: behavior change: _Alignas no longer applies to the type 'Inner' (only applies to declared data objects)`.
113
110
114
111
Also, in previous versions of Visual Studio, when the `_Alignas` specifier appeared adjacent to an anonymous type declaration, it was ignored.
Previously, both `static_assert` statements failed when compiling this code. Now the code compiles, but emits the following level 1 warnings:
130
127
131
-
```cpp
128
+
```c
132
129
warning C5274: behavior change: _Alignas no longer applies to the type '<unnamed-tag>' (only applies to declared data objects)
133
130
warning C5273: behavior change: _Alignas on anonymous type no longer ignored (promoted members will align)
134
131
```
@@ -137,7 +134,7 @@ To get the previous behavior, replace `_Alignas(N)` with `__declspec(align(N))`.
137
134
138
135
### Improved warning C4706
139
136
140
-
This is a source code breaking change. Previously, the compiler didn't detect the convention of wrapping an assignment in parentheses, if assignment was intended, to suppress the warning. The compiler now detects the parentheses and suppresses the warning.
137
+
This is a source code breaking change. Previously, the compiler didn't detect the convention of wrapping an assignment in parentheses, if assignment was intended, to suppress [warning C4706](../error-messages/compiler-warnings/compiler-warning-level-4-c4706.md) about assignment within a conditional expression. The compiler now detects the parentheses and suppresses the warning.
141
138
142
139
```cpp
143
140
#pragma warning(error: 4706)
@@ -159,8 +156,8 @@ struct S
159
156
The compiler now also emits the warning in cases where the function isn't referenced. Previously, because `mf` is an inline function that isn't referenced, warning C4706 wasn't emitted for this code. Now the warning is emitted:
160
157
161
158
```cpp
162
-
t.cpp(5): error C4706: assignment used as a condition
163
-
t.cpp(5): note: if an assignment is intended you can enclose it in parentheses, '(e1 = e2)', to silence this warning
159
+
error C4706: assignment used as a condition
160
+
note: if an assignment is intended you can enclose it in parentheses, '(e1 = e2)', to silence this warning
164
161
```
165
162
166
163
To fix this warning, either use an equality operator, `value == 9`, if this is what was intended. Or, wrap the assignment in parentheses, `(value = 9)`, if assignment is intended. Otherwise, since the function is unreferenced, remove it.
@@ -716,7 +713,7 @@ int main(void)
716
713
717
714
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 when 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.
718
715
719
-
This change is a source breaking change. It applies in any mode that implies **`/permissive-`** or **`/Zc:static_assert`**. This change in behavior can be disabled by using the **`/Zc:static_assert-`** compiler option.
716
+
This change is a source breaking change. It applies in any mode that implies **`/permissive-`** or **`/Zc:static_assert`**. This change in behavior can be disabled by using the **`/Zc:static_assert-`** compiler option.
0 commit comments