Skip to content

Commit c003409

Browse files
author
3836425+corob-msft@users.noreply.github.com
committed
Update 16.1 conformance per J Emmett
1 parent 290a881 commit c003409

2 files changed

Lines changed: 106 additions & 2 deletions

File tree

docs/error-messages/compiler-errors-2/compiler-error-c2666.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: "Learn more about: Compiler Error C2666"
33
title: "Compiler Error C2666"
4-
ms.date: "11/04/2016"
4+
ms.date: 10/18/2021
55
f1_keywords: ["C2666"]
66
helpviewer_keywords: ["C2666"]
77
ms.assetid: 78364d15-c6eb-439a-9088-e04a0176692b
@@ -30,6 +30,52 @@ int main() {
3030
}
3131
```
3232
33+
This error can be generated as a result fo compiler conformance work that was done for Visual Studio 2019 version 16.1:
34+
35+
- 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.
36+
37+
The following example demonstrates how compiler behavior changes in Visual Studio 2019 version 16.1 and later versions:
38+
39+
```cpp
40+
#include <type_traits>
41+
42+
enum E : unsigned char { e };
43+
44+
int f(unsigned int)
45+
{
46+
return 1;
47+
}
48+
49+
int f(unsigned char)
50+
{
51+
return 2;
52+
}
53+
54+
struct A {};
55+
struct B : public A {};
56+
57+
int f(unsigned int, const B&)
58+
{
59+
return 3;
60+
}
61+
62+
int f(unsigned char, const A&)
63+
{
64+
return 4;
65+
}
66+
67+
int main()
68+
{
69+
// Calls f(unsigned char) in 16.1 and later. Called f(unsigned int) in earlier versions.
70+
// The conversion from 'E' to the fixed underlying type 'unsigned char' is better than the
71+
// conversion from 'E' to the promoted type 'unsigned int'.
72+
f(e);
73+
74+
// Error C2666. This call is ambiguous, but previously called f(unsigned int, const B&).
75+
f(e, B{});
76+
}
77+
```
78+
3379
This error can also be generated as a result of compiler conformance work that was done for Visual Studio .NET 2003:
3480

3581
- binary operators and user-defined conversions to pointer types

docs/overview/cpp-conformance-improvements.md

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "C++ conformance improvements in Visual Studio 2019"
33
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
55
ms.technology: "cpp-language"
66
---
77
# C++ Conformance improvements, behavior changes, and bug fixes in Visual Studio 2019
@@ -523,6 +523,58 @@ void f() {
523523

524524
[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).
525525

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+
526578
### New and updated standard library functions (C++20)
527579
528580
- `starts_with()` and `ends_with()` for `basic_string` and `basic_string_view`.
@@ -2462,6 +2514,12 @@ struct S {
24622514
};
24632515
```
24642516

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+
24652523
## See also
24662524

24672525
[Microsoft C/C++ language conformance](visual-cpp-language-conformance.md)

0 commit comments

Comments
 (0)