|
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: 12/07/2023 |
| 4 | +ms.date: 2/6/2024 |
5 | 5 | ms.service: "visual-cpp"
|
6 | 6 | ms.subservice: "cpp-lang"
|
7 | 7 | ---
|
8 | 8 | # C++ Conformance improvements, behavior changes, and bug fixes in Visual Studio 2022
|
9 | 9 |
|
10 |
| -Microsoft C/C++ in Visual Studio (MSVC) makes conformance improvements and bug fixes in every release. This article lists the significant improvements by major release, then by version. To jump directly to the changes for a specific version, use **In this article** links, above. |
| 10 | +Microsoft C/C++ in Visual Studio (MSVC) makes conformance improvements and bug fixes in every release. This article lists the significant improvements by major release, then by version. To jump directly to the changes for a specific version, use the **In this article** links. |
11 | 11 |
|
12 | 12 | This document lists the changes in Visual Studio 2022.
|
13 | 13 |
|
14 |
| -For a guide to the changes in Visual Studio 2019, see [C++ conformance improvements in Visual Studio 2019](cpp-conformance-improvements-2019.md).\ |
| 14 | +For changes in Visual Studio 2019, see [C++ conformance improvements in Visual Studio 2019](cpp-conformance-improvements-2019.md).\ |
15 | 15 | For changes in Visual Studio 2017, see [C++ conformance improvements in Visual Studio 2017](cpp-conformance-improvements-2017.md).\
|
16 |
| -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 | +For changes in older versions, see [Visual C++ What's New 2003 through 2015](../porting/visual-cpp-what-s-new-2003-through-2015.md). |
| 17 | + |
| 18 | +## <a name="improvements_179"></a> Conformance improvements in Visual Studio 2022 version 17.9 |
| 19 | + |
| 20 | +Visual Studio 2022 version 17.9 contains the following conformance improvements, bug fixes, and behavior changes in the Microsoft C/C++ compiler. |
| 21 | + |
| 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 | + |
| 24 | +### `__VA_OPT__` is enabled as an extension under `/Zc:preprocessor` |
| 25 | + |
| 26 | +`__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. |
| 27 | + |
| 28 | +For example, this now compiles without error: |
| 29 | + |
| 30 | +```cpp |
| 31 | +#define LOG_WRAPPER(message, ...) WRITE_LOG(__LINE__, message __VA_OPT__(, __VA_ARGS__)) |
| 32 | + |
| 33 | +// Failed to build under /std:c11, now succeeds. |
| 34 | +LOG_WRAPPER("Log message"); |
| 35 | +LOG_WRAPPER("Log message with %s", "argument") |
| 36 | +``` |
| 37 | +
|
| 38 | +### C23 language ### |
| 39 | +
|
| 40 | +For C23, the following are available when using the `/std:clatest` compiler switch: |
| 41 | +
|
| 42 | +[`typeof`](../c-language/typeof-c.md)\ |
| 43 | +[`typeof_unqual`](../c-language/typeof-unqual-c.md) |
| 44 | +
|
| 45 | +The following are available for all C language versions: |
| 46 | +
|
| 47 | +[`__typeof__`](../c-language/typeof-c.md)\ |
| 48 | +[`__typeof_unqual__`](../c-language/typeof-unqual-c.md) |
| 49 | +
|
| 50 | +### C++ Standard Library |
| 51 | +
|
| 52 | +**C++23 features** |
| 53 | +
|
| 54 | +- `formattable`, `range_format`, `format_kind`, and `set_debug_format()` as part of [P2286R8 Formatting Ranges](https://wg21.link/P2286R8) |
| 55 | +- `<mdspan>` per [P0009R18](https://wg21.link/P0009R18) and subsequent wording changes that were applied to the C++23 Standard. |
| 56 | +- `format()` pointers per [P2510R3](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2510r3.pdf). |
17 | 57 |
|
18 | 58 | ## <a name="improvements_178"></a> Conformance improvements in Visual Studio 2022 version 17.8
|
19 | 59 |
|
@@ -315,7 +355,7 @@ bidi.cpp(8): warning C5255: unterminated bidirectional character encountered: 'U
|
315 | 355 |
|
316 | 356 | ### `from_chars()` `float` tiebreaker
|
317 | 357 |
|
318 |
| -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). |
| 358 | +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). |
319 | 359 |
|
320 | 360 | This change affects runtime behavior in the specified range of cases:
|
321 | 361 |
|
@@ -483,7 +523,7 @@ int main(void)
|
483 | 523 |
|
484 | 524 | ### Error on a nondependent `static_assert`
|
485 | 525 |
|
486 |
| -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. |
| 526 | +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. |
487 | 527 |
|
488 | 528 | 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.
|
489 | 529 |
|
|
0 commit comments