Skip to content

Commit cdfe2a5

Browse files
TylerMSFTTylerMSFT
authored andcommitted
last edits
1 parent 6997751 commit cdfe2a5

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

docs/overview/cpp-conformance-improvements.md

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
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: 05/29/2024
4+
ms.date: 05/31/2024
55
ms.service: "visual-cpp"
66
ms.subservice: "cpp-lang"
77
---
@@ -19,11 +19,11 @@ For changes in older versions, see [Visual C++ What's New 2003 through 2015](../
1919

2020
Visual Studio 2022 version 17.10 contains the following conformance improvements, bug fixes, and behavior changes in the Microsoft C/C++ compiler.
2121

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

2424
### Conversion operator specialization with explicitly specified return type
2525

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

2828
```cpp
2929
// Example 1
@@ -56,7 +56,7 @@ void test()
5656

5757
### Added Support for `#elifdef` and `#elifndef`
5858

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.
6060
Requires `/std:clatest` or `/std:c++latest`.
6161

6262
Before:
@@ -103,13 +103,10 @@ static_assert(offsetof(struct Outer, member2)==4, "incorrect alignment");
103103
104104
According to the ISO-C Standard, this code should compile without `static_assert` emitting a diagnostic.
105105
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.
107107
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)`.
113110
114111
Also, in previous versions of Visual Studio, when the `_Alignas` specifier appeared adjacent to an anonymous type declaration, it was ignored.
115112
@@ -128,7 +125,7 @@ static_assert(sizeof(struct S)==32, "incorrect size");
128125

129126
Previously, both `static_assert` statements failed when compiling this code. Now the code compiles, but emits the following level 1 warnings:
130127

131-
```cpp
128+
```c
132129
warning C5274: behavior change: _Alignas no longer applies to the type '<unnamed-tag>' (only applies to declared data objects)
133130
warning C5273: behavior change: _Alignas on anonymous type no longer ignored (promoted members will align)
134131
```
@@ -137,7 +134,7 @@ To get the previous behavior, replace `_Alignas(N)` with `__declspec(align(N))`.
137134
138135
### Improved warning C4706
139136
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.
141138
142139
```cpp
143140
#pragma warning(error: 4706)
@@ -159,8 +156,8 @@ struct S
159156
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:
160157

161158
```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
164161
```
165162

166163
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)
716713
717714
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.
718715
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.
720717
721718
#### Example
722719

0 commit comments

Comments
 (0)