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
+43-2Lines changed: 43 additions & 2 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: 2/6/2024
4
+
ms.date: 02/20/2024
5
5
ms.service: "visual-cpp"
6
6
ms.subservice: "cpp-lang"
7
7
---
@@ -21,6 +21,47 @@ Visual Studio 2022 version 17.9 contains the following conformance improvements,
21
21
22
22
For a broader summary of changes made to the Standard Template Library, see [STL Changelog VS 2022 17.9](https://github.com/microsoft/STL/wiki/Changelog#vs-2022-179).
23
23
24
+
### Application of `_Alignas` on a structured type in C
25
+
26
+
In versions of Visual C++ before Visual Studio 2022 version 17.9, when `_Alignas` appeared next to a structure type in a declaration, it wasn't applied correctly according to the ISO-C Standard. For example:
According to the ISO-C Standard, this code should compile without the `static_assert` emitting a diagnostic. The `_Alignas` directive applies only to the member variable `member1`. It must not change the alignment of `struct Inner`. However, before release 17.9.1 of Visual Studio, the diagnostic "incorrect alignment" was emitted. The compiler aligned `member2` to a 32 byte offset within `struct Outer`.
40
+
41
+
Fixing this is a binary breaking change, so when this change in behavior is applied a warning is emitted. For the preceding code, Warning C5274, "`_Alignas` no longer applies to the type 'Inner' (only applies to declared data objects)" is now emitted at warning level 1.
42
+
43
+
In previous versions of Visual Studio, `_Alignas` was ignored when it appeared next to an anonymous type declaration. For example:
Previously, both `static_assert` statements failed when compiling this code. The code now compiles, but with the following level 1 warnings:
57
+
58
+
```c
59
+
warning C5274: behavior change: _Alignas no longer applies to the type '<unnamed-tag>' (only applies to declared data objects)
60
+
warning C5273: behavior change: _Alignas on anonymous type no longer ignored (promoted members will align)
61
+
```
62
+
63
+
If you want the earlier behavior, replace `_Alignas(N)` with `__declspec(align(N))`. Unlike `_Alignas`, `declspec(align)` can be applied to a type.
64
+
24
65
### `__VA_OPT__` is enabled as an extension under `/Zc:preprocessor`
25
66
26
67
`__VA_OPT__` was added to C++20 and C23. Previous to its addition, there wasn't a standard way to elide a comma in a variadic macro. To provide better backward compatibility, `__VA_OPT__` is enabled under the token based preprocessor `/Zc:preprocessor` across all language versions.
@@ -293,7 +334,7 @@ enum Enum {
293
334
static_assert(B == 1); // previously failed, now succeeds under /Zc:enumTypes
294
335
```
295
336
296
-
In this example the enumerator `A` should have type **`char`**prior to the closing brace of the enumeration, so `B` should be initialized using `sizeof(char)`. Before the **`/Zc:enumTypes`** fix, `A` had enumeration type `Enum` with a deduced underlying type **`int`**, and `B` was initialized using `sizeof(Enum)`, or 4.
337
+
In this example the enumerator `A` should have type **`char`**before the closing brace of the enumeration, so `B` should be initialized using `sizeof(char)`. Before the **`/Zc:enumTypes`** fix, `A` had enumeration type `Enum` with a deduced underlying type **`int`**, and `B` was initialized using `sizeof(Enum)`, or 4.
297
338
298
339
## <aname="improvements_173"></a> Conformance improvements in Visual Studio 2022 version 17.3
0 commit comments