|
1 | 1 | --- |
2 | 2 | title: "C++ conformance improvements in Visual Studio 2019" |
3 | 3 | description: "Microsoft C++ in Visual Studio is progressing toward full conformance with the C++20 language standard." |
4 | | -ms.date: 06/11/2021 |
| 4 | +ms.date: 10/18/2021 |
5 | 5 | ms.technology: "cpp-language" |
6 | 6 | --- |
7 | 7 | # C++ Conformance improvements, behavior changes, and bug fixes in Visual Studio 2019 |
@@ -523,6 +523,58 @@ void f() { |
523 | 523 |
|
524 | 524 | [P0329R4](https://wg21.link/p0329r4) (C++20) *Designated initialization* allows specific members to be selected in aggregate initialization by using the `Type t { .member = expr }` syntax. Requires **`/std:c++latest`** (or **`/std:c++20`** starting in Visual Studio 2019 version 16.11). |
525 | 525 |
|
| 526 | +### Ranking of enum conversion to its fixed underlying type |
| 527 | + |
| 528 | +The compiler now ranks enum conversions according to [N4800](https://wg21.link/n4800) 11.3.3.2 Ranking implicit conversion sequences (4.2): |
| 529 | + |
| 530 | +- A conversion that promotes an enumeration whose underlying type is fixed to its underlying type is better than one that promotes to the promoted underlying type, if the two are different. |
| 531 | + |
| 532 | +This conversion ranking wasn't implemented correctly before Visual Studio 2019 version 16.1. The conforming behavior may change overload resolution behavior or expose an ambiguity where one previously was not detected. |
| 533 | + |
| 534 | +This compiler behavior change applies to all **`/std`** modes and is both a source and binary breaking change. |
| 535 | + |
| 536 | +The following example demonstrates how compiler behavior changes in 16.1 and later versions: |
| 537 | + |
| 538 | +```cpp |
| 539 | +#include <type_traits> |
| 540 | + |
| 541 | +enum E : unsigned char { e }; |
| 542 | + |
| 543 | +int f(unsigned int) |
| 544 | +{ |
| 545 | + return 1; |
| 546 | +} |
| 547 | + |
| 548 | +int f(unsigned char) |
| 549 | +{ |
| 550 | + return 2; |
| 551 | +} |
| 552 | + |
| 553 | +struct A {}; |
| 554 | +struct B : public A {}; |
| 555 | + |
| 556 | +int f(unsigned int, const B&) |
| 557 | +{ |
| 558 | + return 3; |
| 559 | +} |
| 560 | + |
| 561 | +int f(unsigned char, const A&) |
| 562 | +{ |
| 563 | + return 4; |
| 564 | +} |
| 565 | + |
| 566 | +int main() |
| 567 | +{ |
| 568 | + // Calls f(unsigned char) in 16.1 and later. Called f(unsigned int) in earlier versions. |
| 569 | + // The conversion from 'E' to the fixed underlying type 'unsigned char' is better than the |
| 570 | + // conversion from 'E' to the promoted type 'unsigned int'. |
| 571 | + f(e); |
| 572 | + |
| 573 | + // Error C2666. This call is ambiguous, but previously called f(unsigned int, const B&). |
| 574 | + f(e, B{}); |
| 575 | +} |
| 576 | +``` |
| 577 | +
|
526 | 578 | ### New and updated standard library functions (C++20) |
527 | 579 |
|
528 | 580 | - `starts_with()` and `ends_with()` for `basic_string` and `basic_string_view`. |
@@ -2462,6 +2514,12 @@ struct S { |
2462 | 2514 | }; |
2463 | 2515 | ``` |
2464 | 2516 |
|
| 2517 | +## <a name="improvements_16b"></a> Conformance improvements in Visual Studio 2019 version 16.11 |
| 2518 | + |
| 2519 | +### `/std:c++20` compiler mode |
| 2520 | + |
| 2521 | +Starting in Visual Studio 2019 version 16.11, the compiler now supports the [`/std:c++20`](../build/reference/std-specify-language-standard-version.md) compiler mode. Previously, C++20 features were available only in [`/std:c++latest`](../build/reference/std-specify-language-standard-version.md) mode in Visual Studio 2019. Features that originally required **`/std:c++latest`** mode now work in **`/std:c++20`** mode or later in the latest versions of Visual Studio. |
| 2522 | + |
2465 | 2523 | ## See also |
2466 | 2524 |
|
2467 | 2525 | [Microsoft C/C++ language conformance](visual-cpp-language-conformance.md) |
0 commit comments