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
+108-7Lines changed: 108 additions & 7 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: 06/19/2023
4
+
ms.date: 11/08/2023
5
5
ms.technology: "cpp-language"
6
6
---
7
7
# C++ Conformance improvements, behavior changes, and bug fixes in Visual Studio 2022
@@ -14,6 +14,107 @@ This document lists the changes in Visual Studio 2022:
14
14
- For changes in Visual Studio 2017, see [C++ conformance improvements in Visual Studio 2017](cpp-conformance-improvements-2017.md).
15
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
16
17
+
## <aname="improvements_178"></a> Conformance improvements in Visual Studio 2022 version 17.8
18
+
19
+
Visual Studio 2022 version 17.8 contains the following conformance improvements, bug fixes, and behavior changes in the Microsoft C/C++ compiler.
20
+
21
+
### /FU issues an error
22
+
23
+
The C compiler used to accept the `/FU` option, even though it hasn't support managed compilation for some time. It now issues an error. Projects that pass this option need to restrict it to C++/CLI projects only.
24
+
25
+
### C++ Standard Library
26
+
27
+
The C++23 named modules `std` and `std.compat` are now available when compiling with `/std:c++20`.
28
+
29
+
For a broader summary of changes made to the C++ Standard Library, see [STL Changelog VS 2022 17.8](https://github.com/microsoft/STL/wiki/Changelog#vs-2022-178-preview-3).
30
+
31
+
## <aname="improvements_177"></a> Conformance improvements in Visual Studio 2022 version 17.7
32
+
33
+
Visual Studio 2022 version 17.7 contains the following highlighted conformance improvements, bug fixes, and behavior changes in the Microsoft C/C++ compiler.
34
+
35
+
### C++ Standard Library
36
+
37
+
The `<print>` library is now supported. See [P2093R14 Formatted output](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2093r14.html).
38
+
39
+
Implemented `views::cartesian_product`.
40
+
41
+
For a broader summary of changes made to the Standard Template Library, see [STL Changelog VS 2022 17.7](https://github.com/microsoft/STL/wiki/Changelog#vs-2022-177).
42
+
43
+
### `using` conformance
44
+
45
+
Previously, the `using` directive could cause names from used namespaces to remain visible when they shouldn't. This could cause unqualified name lookup to find a name in a namespace even when there's no `using` directive active.
46
+
47
+
Here are some examples of the new and old behavior.\
48
+
References in the following comments to "(1)" mean the call to `f<K>(t)` in namespace `A`:
49
+
50
+
```cpp
51
+
namespaceA
52
+
{
53
+
template<typename K, typename T>
54
+
auto f2(T t)
55
+
{
56
+
return f<K>(t); // (1) Unqualified lookup should not find anything
57
+
}
58
+
}
59
+
60
+
namespaceB
61
+
{
62
+
template<typename K, typename T>
63
+
auto f(T t) noexcept
64
+
{ // Previous behavior: This function was erroneously found during unqualified lookup at (1)
65
+
return A::f2<K>(t);
66
+
}
67
+
}
68
+
69
+
namespaceC
70
+
{
71
+
template<typename T>
72
+
struct S {};
73
+
74
+
template<typename, typename U>
75
+
U&& f(U&&) noexcept; // New behavior: ADL at (1) correctly finds this function
76
+
}
77
+
78
+
namespaceD
79
+
{
80
+
using namespace B;
81
+
82
+
void h()
83
+
{
84
+
D::f<void>(C::S<int>());
85
+
}
86
+
}
87
+
```
88
+
89
+
The same underlying issue can cause code that previously compiled to now be rejected:
90
+
91
+
```cpp
92
+
#include<memory>
93
+
namespaceAddin {}
94
+
namespace Gui
95
+
{
96
+
using namespace Addin;
97
+
}
98
+
99
+
namespaceAddin
100
+
{
101
+
using namespace std;
102
+
}
103
+
104
+
// This previously compiled, but now emits error C2065 for undeclared name 'allocator'.
105
+
// This should be declared as 'std::allocator<T*>' because the using directive nominating
106
+
// 'std' is not active at this point.
107
+
template <classT, class U = allocator<T*>>
108
+
class resource_list
109
+
{
110
+
};
111
+
112
+
namespaceGui
113
+
{
114
+
typedef resource_list<int> intlist;
115
+
}
116
+
```
117
+
17
118
## <aname="improvements_176"></a> Conformance improvements in Visual Studio 2022 version 17.6
18
119
19
120
Visual Studio 2022 version 17.6 contains the following conformance improvements, bug fixes, and behavior changes in the Microsoft C/C++ compiler.
@@ -94,7 +195,7 @@ In versions of Visual Studio before Visual Studio 2022 version 17.4, the C++ com
94
195
95
196
The C++ Standard requires the underlying type of an **`enum`** to be large enough to hold all enumerators in that **`enum`**. Sufficiently large enumerators can set the underlying type of the **`enum`** to **`unsigned int`**, **`long long`**, or **`unsigned long long`**. Previously, such **`enum`** types always had an underlying type of **`int`** in the Microsoft compiler, regardless of enumerator values.
96
197
97
-
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.
198
+
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 might affect binary compatibility. Some enumeration types change size when the conformant fix is enabled. Certain Windows SDK headers include such enumeration definitions.
98
199
99
200
#### Example
100
201
@@ -134,7 +235,7 @@ In versions of Visual Studio before Visual Studio 2022 version 17.4, the C++ com
134
235
135
236
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`**).
136
237
137
-
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.
238
+
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 might affect binary compatibility. Some enumeration types change size when the conformant fix is enabled. Certain Windows SDK headers include such enumeration definitions.
Visual Studio 2022 version 17.2 fixes a bug in `<charconv>``from_chars()``float` tiebreaker rules that produced incorrect results. This bug affected decimal strings that were at the exact midpoint of consecutive `float` values, within a narrow range. (The smallest and largest affected values were `32768.009765625` and `131071.98828125`, respectively.) The tiebreaker rule wanted to round to "even" and "even" happened to be "down", but the implementation incorrectly rounded "up". (`double` was unaffected.) For more information and implementation details, see [microsoft/STL#2366](https://github.com/microsoft/STL/pull/2366).
313
+
Visual Studio 2022 version 17.2 fixes a bug in `<charconv>``from_chars()``float` tiebreaker rules that produced incorrect results. This bug affected decimal strings that were at the exact midpoint of consecutive `float` values, within a narrow range. (The smallest and largest affected values were `32768.009765625` and `131071.98828125`, respectively.) The tiebreaker rule wanted to round to "even," and "even" happened to be "down", but the implementation incorrectly rounded "up." (`double` was unaffected.) For more information and implementation details, see [microsoft/STL#2366](https://github.com/microsoft/STL/pull/2366).
213
314
214
-
This change affects runtime behavior in the specified range of cases.
315
+
This change affects runtime behavior in the specified range of cases:
215
316
216
317
#### Example
217
318
@@ -377,7 +478,7 @@ int main(void)
377
478
378
479
### Error on a nondependent `static_assert`
379
480
380
-
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.
481
+
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 is 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.
381
482
382
483
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.
383
484
@@ -449,7 +550,7 @@ bool f(int *p)
449
550
}
450
551
```
451
552
452
-
WG21 paper [N3478](https://wg21.link/n3478) removed this oversight. MSVC has now implemented this change. When the example is compiled by using **`/permissive-`** (and **`/diagnostics:caret`**), it emits the following error:
553
+
WG21 paper [N3478](https://wg21.link/n3478) removed this oversight. This change is implemented in MSVC. When the example is compiled by using **`/permissive-`** (and **`/diagnostics:caret`**), it emits the following error:
453
554
454
555
```Output
455
556
t.cpp(3,14): error C7664: '>=': ordered comparison of pointer and integer zero ('int *' and 'int')
0 commit comments