Skip to content

Commit 190e2ee

Browse files
Merge pull request #4810 from MicrosoftDocs/main638352395035749263sync_temp
For protected branch, push strategy should use PR and merge to target branch method to work around git push error
2 parents e6ead26 + ef4b6df commit 190e2ee

File tree

1 file changed

+108
-7
lines changed

1 file changed

+108
-7
lines changed

docs/overview/cpp-conformance-improvements.md

Lines changed: 108 additions & 7 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: 06/19/2023
4+
ms.date: 11/08/2023
55
ms.technology: "cpp-language"
66
---
77
# 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:
1414
- For changes in Visual Studio 2017, see [C++ conformance improvements in Visual Studio 2017](cpp-conformance-improvements-2017.md).
1515
- 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).
1616

17+
## <a name="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+
## <a name="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+
namespace A
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+
namespace B
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+
namespace C
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+
namespace D
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+
namespace Addin {}
94+
namespace Gui
95+
{
96+
using namespace Addin;
97+
}
98+
99+
namespace Addin
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 <class T, class U = allocator<T*>>
108+
class resource_list
109+
{
110+
};
111+
112+
namespace Gui
113+
{
114+
typedef resource_list<int> intlist;
115+
}
116+
```
117+
17118
## <a name="improvements_176"></a> Conformance improvements in Visual Studio 2022 version 17.6
18119

19120
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
94195

95196
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.
96197

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

99200
#### Example
100201

@@ -134,7 +235,7 @@ In versions of Visual Studio before Visual Studio 2022 version 17.4, the C++ com
134235
135236
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`**).
136237
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.
138239
139240
#### Example
140241
@@ -209,9 +310,9 @@ bidi.cpp(8): warning C5255: unterminated bidirectional character encountered: 'U
209310

210311
### `from_chars()` `float` tiebreaker
211312

212-
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).
213314

214-
This change affects runtime behavior in the specified range of cases.
315+
This change affects runtime behavior in the specified range of cases:
215316

216317
#### Example
217318

@@ -377,7 +478,7 @@ int main(void)
377478
378479
### Error on a nondependent `static_assert`
379480
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.
381482
382483
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.
383484
@@ -449,7 +550,7 @@ bool f(int *p)
449550
}
450551
```
451552
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:
453554
454555
```Output
455556
t.cpp(3,14): error C7664: '>=': ordered comparison of pointer and integer zero ('int *' and 'int')

0 commit comments

Comments
 (0)