Skip to content

Commit 0668927

Browse files
authored
Merge pull request #4123 from corob-msft/docs/corob/C5054
Add C5054, C5055, C5056 warnings
2 parents 081f7c8 + 18b28c9 commit 0668927

6 files changed

Lines changed: 146 additions & 10 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
---
2+
title: "Compiler Warning C5054"
3+
description: Compiler warning C5054 description and solution.
4+
ms.date: 02/22/2022
5+
f1_keywords: ["C5054"]
6+
helpviewer_keywords: ["C5054"]
7+
---
8+
# Compiler warning (level 4) C5054
9+
10+
> operator '*operator-name*': deprecated between enumerations of different types
11+
12+
## Remarks
13+
14+
C++20 has deprecated the usual arithmetic conversions on operands, where one operand is of enumeration type and the other is of a different enumeration type. For more information, see C++ Standard proposal [P1120R0](https://wg21.link/p1120r0).
15+
16+
In Visual Studio 2019 version 16.2 and later, an implicit conversion between enumeration types produces a level 4 warning when the **`/std:c++latest`** compiler option is enabled. In Visual Studio 2019 version 16.11 and later, it also produces a warning under **`/std:c++20`**.
17+
18+
## Example
19+
20+
In Visual Studio 2019 version 16.2 and later, the following code produces a level 4 warning when the **`/std:c++latest`** compiler option is enabled. In Visual Studio 2019 version 16.11 and later, it also produces a warning under **`/std:c++20`**:
21+
22+
```cpp
23+
// C5054.cpp
24+
// Compile using: cl /EHsc /W4 /std:c++latest C5054.cpp
25+
enum E1 { a };
26+
enum E2 { b };
27+
int main() {
28+
int i = a | b; // warning C5054: operator '|': deprecated between enumerations of different types
29+
}
30+
```
31+
32+
To avoid the warning, use [`static_cast`](../../cpp/static-cast-operator.md) to convert the second operand:
33+
34+
```cpp
35+
// C5054_fixed.cpp
36+
// Compile using: cl /EHsc /W4 /std:c++latest C5054_fixed.cpp
37+
enum E1 { a };
38+
enum E2 { b };
39+
int main() {
40+
int i = a | static_cast<int>(b);
41+
}
42+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: "Compiler Warning C5055"
3+
description: Compiler warning C5055 description and solution.
4+
ms.date: 02/22/2022
5+
f1_keywords: ["C5055"]
6+
helpviewer_keywords: ["C5055"]
7+
---
8+
# Compiler warning (level 1) C5055
9+
10+
> operator '*operator-name*': deprecated between enumerations and floating-point types
11+
12+
## Remarks
13+
14+
C++20 has deprecated the usual arithmetic conversions on operands, where one operand is of enumeration type and the other is of floating-point type. For more information, see C++ Standard proposal [P1120R0](https://wg21.link/p1120r0).
15+
16+
In Visual Studio 2019 version 16.2 and later, an implicit conversion between enumeration types and floating-point types produces a level 1 warning when the **`/std:c++latest`** compiler option is enabled. In Visual Studio 2019 version 16.11 and later, it also produces a warning under **`/std:c++20`**.
17+
18+
## Example
19+
20+
In Visual Studio 2019 version 16.2 and later, a binary operation between an enumeration and a floating-point type produces a level 1 warning when the **`/std:c++latest`** compiler option is enabled. In Visual Studio 2019 version 16.11 and later, it also produces a warning under **`/std:c++20`**:
21+
22+
```cpp
23+
// C5055.cpp
24+
// Compile using: cl /EHsc /W4 /std:c++latest C5055.cpp
25+
enum E1 { a };
26+
int main() {
27+
double i = a * 1.1; // Warning C5055: operator '*': deprecated between enumerations and floating-point types
28+
}
29+
```
30+
31+
To avoid the warning, use [`static_cast`](../../cpp/static-cast-operator.md) to convert the second operand:
32+
33+
```cpp
34+
// C5055_fixed.cpp
35+
// Compile using: cl /EHsc /W4 /std:c++latest C5055_fixed.cpp
36+
enum E1 { a };
37+
int main() {
38+
double i = static_cast<int>(a) * 1.1;
39+
}
40+
```
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: "Compiler Warning C5056"
3+
description: Compiler warning C5056 description and solution.
4+
ms.date: 02/22/2022
5+
f1_keywords: ["C5056"]
6+
helpviewer_keywords: ["C5056"]
7+
---
8+
# Compiler warning (level 1) C5056
9+
10+
> operator '*operator-name*': deprecated for array types
11+
12+
## Remarks
13+
14+
Equality and relational comparisons between two operands of array type are deprecated in C++20. For more information, see C++ Standard proposal [P1120R0](https://wg21.link/p1120r0).
15+
16+
In Visual Studio 2019 version 16.2 and later, a comparison operation between two arrays (despite rank and extent similarities) now produces a level 1 C5056 warning when the **`/std:c++latest`** compiler option is enabled. In Visual Studio 2019 version 16.11 and later, it also produces a warning under **`/std:c++20`**.
17+
18+
## Example
19+
20+
In Visual Studio 2019 version 16.2 and later, the following code produces warning C5056 when the **`/std:c++latest`** compiler option is enabled. In Visual Studio 2019 version 16.11 and later, it also produces a warning under **`/std:c++20`**:
21+
22+
```cpp
23+
// C5056.cpp
24+
// Compile using: cl /EHsc /W4 /std:c++latest C5056.cpp
25+
int main() {
26+
int a[] = { 1, 2, 3 };
27+
int b[] = { 1, 2, 3 };
28+
if (a == b) { return 1; } // warning C5056: operator '==': deprecated for array types
29+
}
30+
```
31+
32+
To avoid the warning, you can compare the addresses of the first elements:
33+
34+
```cpp
35+
// C5056_fixed.cpp
36+
// Compile using: cl /EHsc /W4 /std:c++latest C5056_fixed.cpp
37+
int main() {
38+
int a[] = { 1, 2, 3 };
39+
int b[] = { 1, 2, 3 };
40+
if (&a[0] == &b[0]) { return 1; }
41+
}
42+
```
43+
44+
To determine whether the contents of two arrays are equal, use the [`std::equal`](../../standard-library/algorithm-functions.md#equal) function:
45+
46+
```cpp
47+
std::equal(std::begin(a), std::end(a), std::begin(b), std::end(b));
48+
```

docs/error-messages/compiler-warnings/compiler-warnings-c4800-through-c4999.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
title: "Compiler warnings C4800 Through C5999"
33
description: "Table of Microsoft C/C++ compiler warnings C4800 through C5999."
44
ms.date: 02/22/2022
5-
f1_keywords: ["C4808", "C4809", "C4825", "C4827", "C4837", "C4842", "C4844", "C4845", "C4846", "C4847", "C4848", "C4854", "C4855", "C4856", "C4857", "C4872", "C4880", "C4881", "C4882", "C4916", "C4921", "C4934", "C4954", "C4955", "C4963", "C4966", "C4970", "C4971", "C4973", "C4974", "C4981", "C4987", "C4988", "C4989", "C4990", "C4991", "C4992", "C4998", "C5022", "C5023", "C5024", "C5025", "C5026", "C5027", "C5028", "C5029", "C5030", "C5031", "C5032", "C5034", "C5035", "C5036", "C5039", "C5040", "C5041", "C5042", "C5043", "C5044", "C5047", "C5048", "C5049", "C5051", "C5052", "C5053", "C5054", "C5055", "C5056", "C5057", "C5058", "C5059", "C5060", "C5061", "C5062", "C5063", "C5100", "C5101", "C5102", "C5103", "C5104", "C5106", "C5107", "C5108", "C5200", "C5201", "C5202", "C5203", "C5204", "C5205", "C5206", "C5207", "C5209", "C5210", "C5211", "C5212", "C5213", "C5214", "C5215", "C5216", "C5217", "C5218", "C5219", "C5220", "C5221", "C5222", "C5223", "C5224", "C5225", "C5226", "C5227", "C5228", "C5229", "C5230", "C5231", "C5232", "C5233", "C5234", "C5235", "C5236", "C5237", "C5238", "C5239", "C5241", "C5242", "C5244", "C5245", "C5246", "C5249", "C5250", "C5251", "C5252", "C5253", "C5254"]
6-
helpviewer_keywords: ["C4808", "C4809", "C4825", "C4827", "C4837", "C4842", "C4844", "C4845", "C4846", "C4847", "C4848", "C4854", "C4855", "C4856", "C4857", "C4872", "C4880", "C4881", "C4882", "C4916", "C4921", "C4934", "C4954", "C4955", "C4963", "C4966", "C4970", "C4971", "C4973", "C4974", "C4981", "C4987", "C4988", "C4989", "C4990", "C4991", "C4992", "C4998", "C5022", "C5023", "C5024", "C5025", "C5026", "C5027", "C5028", "C5029", "C5030", "C5031", "C5032", "C5034", "C5035", "C5036", "C5039", "C5040", "C5041", "C5042", "C5043", "C5044", "C5047", "C5048", "C5049", "C5051", "C5052", "C5053", "C5054", "C5055", "C5056", "C5057", "C5058", "C5059", "C5060", "C5061", "C5062", "C5063", "C5100", "C5101", "C5102", "C5103", "C5104", "C5106", "C5107", "C5108", "C5200", "C5201", "C5202", "C5203", "C5204", "C5205", "C5206", "C5207", "C5209", "C5210", "C5211", "C5212", "C5213", "C5214", "C5215", "C5216", "C5217", "C5218", "C5219", "C5220", "C5221", "C5222", "C5223", "C5224", "C5225", "C5226", "C5227", "C5228", "C5229", "C5230", "C5231", "C5232", "C5233", "C5234", "C5235", "C5236", "C5237", "C5238", "C5239", "C5241", "C5242", "C5244", "C5245", "C5246", "C5249", "C5250", "C5251", "C5252", "C5253", "C5254"]
5+
f1_keywords: ["C4808", "C4809", "C4825", "C4827", "C4837", "C4842", "C4844", "C4845", "C4846", "C4847", "C4848", "C4854", "C4855", "C4856", "C4857", "C4872", "C4880", "C4881", "C4882", "C4916", "C4921", "C4934", "C4954", "C4955", "C4963", "C4966", "C4970", "C4971", "C4973", "C4974", "C4981", "C4987", "C4988", "C4989", "C4990", "C4991", "C4992", "C4998", "C5022", "C5023", "C5024", "C5025", "C5026", "C5027", "C5028", "C5029", "C5030", "C5031", "C5032", "C5034", "C5035", "C5036", "C5039", "C5040", "C5041", "C5042", "C5043", "C5044", "C5047", "C5048", "C5049", "C5051", "C5052", "C5053", "C5057", "C5058", "C5059", "C5060", "C5061", "C5062", "C5063", "C5100", "C5101", "C5102", "C5103", "C5104", "C5106", "C5107", "C5108", "C5200", "C5201", "C5202", "C5203", "C5204", "C5205", "C5206", "C5207", "C5209", "C5210", "C5211", "C5212", "C5213", "C5214", "C5215", "C5216", "C5217", "C5218", "C5219", "C5220", "C5221", "C5222", "C5223", "C5224", "C5225", "C5226", "C5227", "C5228", "C5229", "C5230", "C5231", "C5232", "C5233", "C5234", "C5235", "C5236", "C5237", "C5238", "C5239", "C5241", "C5242", "C5244", "C5245", "C5246", "C5249", "C5250", "C5251", "C5252", "C5253", "C5254"]
6+
helpviewer_keywords: ["C4808", "C4809", "C4825", "C4827", "C4837", "C4842", "C4844", "C4845", "C4846", "C4847", "C4848", "C4854", "C4855", "C4856", "C4857", "C4872", "C4880", "C4881", "C4882", "C4916", "C4921", "C4934", "C4954", "C4955", "C4963", "C4966", "C4970", "C4971", "C4973", "C4974", "C4981", "C4987", "C4988", "C4989", "C4990", "C4991", "C4992", "C4998", "C5022", "C5023", "C5024", "C5025", "C5026", "C5027", "C5028", "C5029", "C5030", "C5031", "C5032", "C5034", "C5035", "C5036", "C5039", "C5040", "C5041", "C5042", "C5043", "C5044", "C5047", "C5048", "C5049", "C5051", "C5052", "C5053", "C5057", "C5058", "C5059", "C5060", "C5061", "C5062", "C5063", "C5100", "C5101", "C5102", "C5103", "C5104", "C5106", "C5107", "C5108", "C5200", "C5201", "C5202", "C5203", "C5204", "C5205", "C5206", "C5207", "C5209", "C5210", "C5211", "C5212", "C5213", "C5214", "C5215", "C5216", "C5217", "C5218", "C5219", "C5220", "C5221", "C5222", "C5223", "C5224", "C5225", "C5226", "C5227", "C5228", "C5229", "C5230", "C5231", "C5232", "C5233", "C5234", "C5235", "C5236", "C5237", "C5238", "C5239", "C5241", "C5242", "C5244", "C5245", "C5246", "C5249", "C5250", "C5251", "C5252", "C5253", "C5254"]
77
---
88
# Compiler warnings C4800 through C5999
99

@@ -162,9 +162,9 @@ The articles in this section of the documentation explain a subset of the warnin
162162
| Compiler warning (level 1) C5051 | attribute 'attribute-name' requires at least 'standard-level'; ignored |
163163
| Compiler warning (level 3, off) C5052 | Keyword 'keyword-name' was introduced in C++\<version> and requires use of the 'option-name' command-line option |
164164
| Compiler warning (level 1) C5053 | support for '`explicit(<expr>)`' in C++17 and earlier is a vendor extension |
165-
| Compiler warning (level 4) C5054 | operator 'operator-name': deprecated between enumerations of different types |
166-
| Compiler warning (level 1) C5055 | operator 'operator-name': deprecated between enumerations and floating-point types |
167-
| Compiler warning (level 1) C5056 | operator 'operator-name': deprecated for array types |
165+
| [Compiler warning (level 4) C5054](c5054.md) | operator 'operator-name': deprecated between enumerations of different types |
166+
| [Compiler warning (level 1) C5055](c5055.md) | operator 'operator-name': deprecated between enumerations and floating-point types |
167+
| [Compiler warning (level 1) C5056](c5056.md) | operator 'operator-name': deprecated for array types |
168168
| Compiler warning (level 1) C5057 | header unit reference to 'name' already exists. Ignoring header unit 'header-name' |
169169
| Compiler warning (level 1) C5058 | file system error: cannot find header file 'file-name' for header unit 'unit-name' |
170170
| Compiler warning C5059 | runtime checks and address sanitizer is not currently supported - disabling runtime checks |
@@ -238,5 +238,5 @@ The articles in this section of the documentation explain a subset of the warnin
238238

239239
## See also
240240

241-
[C/C++ Compiler and build tools errors and warnings](../compiler-errors-1/c-cpp-build-errors.md) \
241+
[C/C++ Compiler and build tools errors and warnings](../compiler-errors-1/c-cpp-build-errors.md)\
242242
[Compiler warnings C4000 - C5999](compiler-warnings-c4000-c5999.md)

docs/error-messages/toc.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4299,6 +4299,12 @@ items:
42994299
href: compiler-warnings/c5046.md
43004300
- name: Compiler warning C5050
43014301
href: compiler-warnings/c5050.md
4302+
- name: Compiler warning (level 4) C5054
4303+
href: compiler-warnings/c5054.md
4304+
- name: Compiler warning (level 1) C5055
4305+
href: compiler-warnings/c5055.md
4306+
- name: Compiler warning (level 1) C5056
4307+
href: compiler-warnings/c5056.md
43024308
- name: Compiler warning (level 1) C5105
43034309
href: compiler-warnings/c5105.md
43044310
- name: Compiler warning (level 1) C5208

docs/overview/cpp-conformance-improvements-2019.md

Lines changed: 4 additions & 4 deletions
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: 10/23/2021
4+
ms.date: 02/22/2022
55
ms.technology: "cpp-language"
66
---
77
# C++ Conformance improvements, behavior changes, and bug fixes in Visual Studio 2019
@@ -616,7 +616,7 @@ C++20 has deprecated the usual arithmetic conversions on operands, where:
616616

617617
For more information, see [P1120R0](https://wg21.link/p1120r0).
618618

619-
In Visual Studio 2019 version 16.2 and later, the following code produces a level 4 warning when the **`/std:c++latest`** compiler option is enabled (**`/std:c++20`** starting in Visual Studio 2019 version 16.11):
619+
In Visual Studio 2019 version 16.2 and later, the following code produces a level 4 C5054 warning when the **`/std:c++latest`** compiler option is enabled (**`/std:c++20`** starting in Visual Studio 2019 version 16.11):
620620

621621
```cpp
622622
enum E1 { a };
@@ -636,7 +636,7 @@ int main() {
636636
}
637637
```
638638

639-
Using a binary operation between an enumeration and a floating-point type is now a warning when the **`/std:c++latest`** compiler option is enabled (**`/std:c++20`** starting in Visual Studio 2019 version 16.11):
639+
Using a binary operation between an enumeration and a floating-point type is now a level 1 C5055 warning when the **`/std:c++latest`** compiler option is enabled (**`/std:c++20`** starting in Visual Studio 2019 version 16.11):
640640

641641
```cpp
642642
enum E1 { a };
@@ -656,7 +656,7 @@ int main() {
656656

657657
### Equality and relational comparisons of arrays
658658

659-
Equality and relational comparisons between two operands of array type are deprecated in C++20 ([P1120R0](https://wg21.link/p1120r0)). In other words, a comparison operation between two arrays (despite rank and extent similarities) is now a warning. Starting in Visual Studio 2019 version 16.2, the following code produces C5056 when the **`/std:c++latest`** compiler option is enabled (**`/std:c++20`** starting in Visual Studio 2019 version 16.11):
659+
Equality and relational comparisons between two operands of array type are deprecated in C++20 ([P1120R0](https://wg21.link/p1120r0)). In other words, a comparison operation between two arrays (despite rank and extent similarities) is now a warning. Starting in Visual Studio 2019 version 16.2, the following code produces level 1 warning C5056 when the **`/std:c++latest`** compiler option is enabled (**`/std:c++20`** starting in Visual Studio 2019 version 16.11):
660660

661661
```cpp
662662
int main() {

0 commit comments

Comments
 (0)