Skip to content

Commit 47a3fb8

Browse files
author
Colin Robertson
committed
Add warning C4388, update 16.7 warnings
1 parent 40846a7 commit 47a3fb8

7 files changed

+149
-31
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
title: "Compiler Warning (level 4) C4388"
3+
description: "Microsoft C/C++ compiler warning C4388, its causes and resolution."
4+
ms.date: 10/16/2020
5+
f1_keywords: ["C4388"]
6+
helpviewer_keywords: ["C4388"]
7+
---
8+
# Compiler Warning (level 4) C4388
9+
10+
> '*token*' : signed/unsigned mismatch
11+
12+
Using the *token* operator to compare a **`signed`** and a larger **`unsigned`** number required the compiler to convert the **`signed`** value to the larger **`unsigned`** type.
13+
14+
## Remarks
15+
16+
One way to fix this warning is if you cast one of the two types when you compare **`signed`** and larger **`unsigned`** types.
17+
18+
This warning is off by default. You can use [/Wall](../../build/reference/compiler-option-warning-level.md) or **`/w44388`** to enable it on the command line as a level 4 warning. Or, use [`#pragma warning(default:4388)`](../../preprocessor/warning.md) in your source file. For more information, see [Compiler warnings that are off by default](../../preprocessor/compiler-warnings-that-are-off-by-default.md).
19+
20+
## Example
21+
22+
This sample generates C4388 and shows how to fix it:
23+
24+
```cpp
25+
// C4388.cpp
26+
// compile with: cl /EHsc /W4 C4388.cpp
27+
#pragma warning(default: 4388)
28+
29+
int main() {
30+
unsigned long long uc = 0;
31+
int c = 0;
32+
unsigned long long c2 = c; // implicit conversion
33+
34+
if (uc < c) // C4388
35+
uc = 0;
36+
37+
if (uc < (unsigned long long)(c)) // OK
38+
uc = 0;
39+
40+
if (uc < c2) // Also OK
41+
uc = 0;
42+
}
43+
```
44+
45+
## See also
46+
47+
[Compiler Warning (Level 3) C4018](compiler-warning-level-3-c4018.md)\
48+
[Compiler Warning (Level 4) C4389](compiler-warning-level-4-c4389.md)
Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,44 @@
11
---
22
title: "Compiler Warning (level 3) C4018"
3-
ms.date: "11/04/2016"
3+
description: "Microsoft C/C++ compiler warning C4018, its causes and resolution."
4+
ms.date: 10/16/2020
45
f1_keywords: ["C4018"]
56
helpviewer_keywords: ["C4018"]
6-
ms.assetid: 6e8cbb04-d914-4319-b431-cbc2fbe40eb1
77
---
88
# Compiler Warning (level 3) C4018
99

10-
'expression' : signed/unsigned mismatch
10+
> '*token*' : signed/unsigned mismatch
1111
12-
Comparing a signed and unsigned number required the compiler to convert the signed value to unsigned.
12+
Using the *token* operator to compare **`signed`** and **`unsigned`** numbers required the compiler to convert the **`signed`** value to **`unsigned`**.
1313

14-
This warning may be fixed if you cast one of the two types when testing signed and unsigned types.
14+
## Remarks
1515

16-
The following sample generates C4018:
16+
One way to fix this warning is if you cast one of the two types when you compare **`signed`** and **`unsigned`** types.
17+
18+
## Example
19+
20+
This sample generates C4018 and shows how to fix it:
1721

1822
```cpp
1923
// C4018.cpp
20-
// compile with: /W3
24+
// compile with: cl /EHsc /W4 C4018.cpp
2125
int main() {
22-
unsigned int uc = 0;
23-
int c = 0;
24-
unsigned int c2 = 0;
26+
unsigned int uc = 0;
27+
int c = 0;
28+
unsigned int c2 = c; // implicit conversion
29+
30+
if (uc < c) // C4018
31+
uc = 0;
2532

26-
if (uc < c) uc = 0; // C4018
33+
if (uc < unsigned(c)) // OK
34+
uc = 0;
2735

28-
// OK
29-
if (uc == c2) uc = 0;
36+
if (uc < c2) // Also OK
37+
uc = 0;
3038
}
3139
```
40+
41+
## See also
42+
43+
[Compiler Warning (Level 4) C4388](c4388.md)\
44+
[Compiler Warning (Level 4) C4389](compiler-warning-level-4-c4389.md)
Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,49 @@
11
---
22
title: "Compiler Warning (level 4) C4389"
3-
ms.date: "11/04/2016"
3+
description: "Microsoft C/C++ compiler warning C4389, its causes and resolution."
4+
ms.date: 10/16/2020
45
f1_keywords: ["c4389"]
56
helpviewer_keywords: ["C4389"]
6-
ms.assetid: fc0e3a8e-f766-437c-b7f1-e61abb2a8765
77
---
88
# Compiler Warning (level 4) C4389
99

10-
'operator' : signed/unsigned mismatch
10+
> '*equality-operator*' : signed/unsigned mismatch
1111
12-
An operation involved signed and unsigned variables. This could result in a loss of data.
12+
An **`==`** or **`!=`** operation involved **`signed`** and **`unsigned`** variables. This could result in a loss of data.
13+
14+
## Remarks
15+
16+
One way to fix this warning is if you cast one of the two types when you compare **`signed`** and **`unsigned`** types.
17+
18+
## Example
1319

1420
The following sample generates C4389:
1521

1622
```cpp
1723
// C4389.cpp
18-
// compile with: /W4
19-
#pragma warning(default: 4389)
24+
// compile with: cl /EHsc /W4 C4389.cpp
2025

2126
int main()
2227
{
2328
int a = 9;
2429
unsigned int b = 10;
30+
int result = 0;
31+
2532
if (a == b) // C4389
26-
return 0;
33+
result = 1;
2734
else
28-
return 0;
29-
};
35+
result = 2;
36+
37+
if (unsigned(a) == b) // OK
38+
result = 3;
39+
else
40+
result = 4;
41+
42+
return result;
43+
}
3044
```
45+
46+
## See also
47+
48+
[Compiler Warning C4018](compiler-warning-level-3-c4018.md)\
49+
[Compiler Warning (Level 4) C4388](c4388.md)

docs/error-messages/compiler-warnings/compiler-warnings-by-compiler-version.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: "Compiler Warnings by compiler version"
3-
ms.date: "04/22/2019"
3+
description: "Table of Microsoft C/C++ compiler warnings by compiler version."
4+
ms.date: 10/18/2020
45
helpviewer_keywords: ["warnings, by compiler version", "cl.exe compiler, setting warning options"]
56
---
67
# Compiler Warnings by compiler version
@@ -36,13 +37,34 @@ These versions of the compiler introduced new warnings:
3637
| Visual Studio 2019 version 16.4 | 19.24.28314.0 |
3738
| Visual Studio 2019 version 16.5 | 19.25.28610.0 |
3839
| Visual Studio 2019 version 16.6 | 19.26.28805.0 |
40+
| Visual Studio 2019 version 16.7 | 19.26.29112.0 |
3941

4042
You can specify only the major number, the major and minor numbers, or the major, minor, and build numbers to the **`/Wv`** option. The compiler reports all warnings that match versions that begin with the specified number. It suppresses all warnings for versions greater than the specified number. For example, **`/Wv:17`** reports warnings introduced in or before any version of Visual Studio 2012, and suppresses warnings introduced by any compiler from Visual Studio 2013 (version 18) or later. To suppress warnings introduced in Visual Studio 2015 update 2 and later, you can use **`/Wv:19.00.23506`**. Use **`/Wv:19.11`** to report the warnings introduced in any version of Visual Studio before Visual Studio 2017 version 15.5, but suppress warnings introduced in Visual Studio 2017 version 15.5 and later.
4143

4244
The following sections list the warnings introduced by each version of Visual C++ that you can suppress by using the **`/Wv`** compiler option. The **`/Wv`** option can't suppress warnings that aren't listed, which predate the specified versions of the compiler.
4345

4446
::: moniker range=">= vs-2019"
4547

48+
## Warnings introduced in Visual Studio 2019 version 16.7 (compiler version 19.27.29112.0)
49+
50+
These warnings and all warnings in later versions are suppressed by using the compiler option **`/Wv:19.26`**.
51+
52+
| Warning | Message |
53+
|--|--|
54+
| C5207 | `the simple requirement asserts the validity of expression 'e->id'. Did you mean '{ e } -> id'? You can suppress the warning using '{ e->id }'` |
55+
| C5209 | `the C++20 syntax for an init-capture has changed to '& ...opt identifier initializer'` |
56+
| C5210 | `'name' is not a valid header unit reference; ignoring` |
57+
| C5212 | `'name' is not a valid named reference; treating as reference to file` |
58+
| C5213 | `'name' named reference is treated as a named partition but the name is not specified; treating as reference to file` |
59+
| C5214 | `applying 'modifier' to an operand with a volatile qualified type is deprecated in C++20` |
60+
| C5215 | `'name' a function parameter with a volatile qualified type is deprecated in C++20` |
61+
| C5216 | `'name' a volatile qualified return type is deprecated in C++20` |
62+
| C5217 | `a structured binding declaration that includes volatile is deprecated in C++20` |
63+
| C5218 | `destroying delete may not behave as intended when non-conforming switches '/Zc:sizedDealloc-' or '/Zc:alignedNew-' are used` |
64+
| C5219 | `implicit conversion from 'type-1' to 'type-2', possible loss of data` |
65+
| C5220 | `'name': a non-static data member with a volatile qualified type no longer implies%$N that compiler generated copy/move constructors and copy/move assignment operators are not trivial` |
66+
| C5221 | `xfg::rename is deprecated.` |
67+
4668
## Warnings introduced in Visual Studio 2019 version 16.6 (compiler version 19.26.28805.0)
4769

4870
These warnings and all warnings in later versions are suppressed by using the compiler option **`/Wv:19.25`**.

docs/error-messages/compiler-warnings/compiler-warnings-c4200-through-c4399.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
22
title: "Compiler warnings C4200 Through C4399"
3-
ms.date: "04/21/2019"
4-
f1_keywords: ["C4203", "C4277", "C4279", "C4298", "C4299", "C4301", "C4303", "C4314", "C4315", "C4317", "C4318", "C4321", "C4322", "C4323", "C4327", "C4328", "C4330", "C4338", "C4352", "C4362", "C4367", "C4370", "C4380", "C4387", "C4388"]
5-
ms.assetid: 170248db-7bf2-4823-92d9-437b04c1290d
3+
description: "Table of Microsoft C/C++ compiler warnings C4200 through C4389."
4+
ms.date: 10/18/2020
5+
f1_keywords: ["C4203", "C4277", "C4279", "C4298", "C4299", "C4301", "C4303", "C4314", "C4315", "C4317", "C4318", "C4321", "C4322", "C4323", "C4327", "C4328", "C4330", "C4338", "C4352", "C4362", "C4367", "C4370", "C4380", "C4387"]
66
---
7-
# Compiler warnings C4200 Through C4399
7+
# Compiler warnings C4200 through C4399
88

99
The articles in this section of the documentation explain a subset of the warning messages that are generated by the compiler.
1010

@@ -162,7 +162,7 @@ The articles in this section of the documentation explain a subset of the warnin
162162
|[Compiler warning (level 1) C4383](../../error-messages/compiler-warnings/compiler-warning-level-1-c4383.md)|'*instance_dereference_operator*': the meaning of dereferencing a handle can change, when a user-defined '*instance_dereference_operator*' operator exists; write the operator as a static function to be explicit about the operand|
163163
|[Compiler warning (level 1) C4384](../../error-messages/compiler-warnings/compiler-warning-level-1-c4384.md)|#pragma 'make_public' should only be used at global scope|
164164
|Compiler warning (level 3) C4387|'*alternative*': was considered|
165-
|Compiler warning (level 4) C4388|'*expression*': signed/unsigned mismatch|
165+
|[Compiler warning (level 4) C4388](./c4388.md))|'*expression*': signed/unsigned mismatch|
166166
|[Compiler warning (level 4) C4389](../../error-messages/compiler-warnings/compiler-warning-level-4-c4389.md)|'*operator*': signed/unsigned mismatch|
167167
|[Compiler warning (level 3) C4390](../../error-messages/compiler-warnings/compiler-warning-level-3-c4390.md)|';': empty controlled statement found; is this the intent?|
168168
|[Compiler warning (level 1) C4391](../../error-messages/compiler-warnings/compiler-warning-level-1-c4391.md)|'*function_signature*': incorrect return type for intrinsic function, expected '*type*'|

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
---
22
title: "Compiler warnings C4800 Through C5999"
3-
ms.date: "04/21/2019"
3+
description: "Table of Microsoft C/C++ compiler warnings C4800 through C5999."
4+
ms.date: 10/18/2020
45
f1_keywords: ["C4808", "C4809", "C4825", "C4827", "C4837", "C4841", "C4842", "C4843", "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", "C5033", "C5034", "C5035", "C5036", "C5037", "C5039", "C5040", "C5041", "C5042", "C5043", "C5044", "C5047", "C5048", "C5049", "C5050", "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"]
5-
helpviewer_keywords: ["C4808", "C4809", "C4825", "C4827", "C4837", "C4841", "C4842", "C4843", "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", "C5033", "C5034", "C5035", "C5036", "C5037", "C5039", "C5040", "C5041", "C5042", "C5043", "C5044", "C5047", "C5048", "C5049", "C5050", "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"]
6+
helpviewer_keywords: ["C4808", "C4809", "C4825", "C4827", "C4837", "C4841", "C4842", "C4843", "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", "C5033", "C5034", "C5035", "C5036", "C5037", "C5039", "C5040", "C5041", "C5042", "C5043", "C5044", "C5047", "C5048", "C5049", "C5050", "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"]
67
---
7-
# Compiler warnings C4800 Through C5999
8+
# Compiler warnings C4800 through C5999
89

910
The articles in this section of the documentation explain a subset of the warning messages that are generated by the compiler.
1011

@@ -188,6 +189,19 @@ The articles in this section of the documentation explain a subset of the warnin
188189
| Compiler warning C5206 | deduced return types for coroutines is a non-standard extension |
189190
| Compiler warning C5207 | the simple requirement asserts the validity of expression '`e->id`'. Did you mean '`{ e } -> id`'? You can suppress the warning using '`{ e->id }`' |
190191
| [Compiler warning (level 1) C5208](c5208.md) | unnamed class used in `typedef` name cannot declare members other than non-static data members, member enumerations, or member classes |
192+
| Compiler warning C5209 | the C++20 syntax for an init-capture has changed to '& ...opt identifier initializer' |
193+
| Compiler warning C5210 | '*name*' is not a valid header unit reference; ignoring |
194+
| Compiler warning C5212 | '*name*' is not a valid named reference; treating as reference to file |
195+
| Compiler warning C5213 | '*name*' named reference is treated as a named partition but the name is not specified; treating as reference to file |
196+
| Compiler warning C5214 | applying '*modifier*' to an operand with a volatile qualified type is deprecated in C++20 |
197+
| Compiler warning C5215 | '*name*' a function parameter with a volatile qualified type is deprecated in C++20 |
198+
| Compiler warning C5216 | '*name*' a volatile qualified return type is deprecated in C++20 |
199+
| Compiler warning C5217 | a structured binding declaration that includes volatile is deprecated in C++20 |
200+
| Compiler warning C5218 | destroying delete may not behave as intended when non-conforming switches '`/Zc:sizedDealloc-`' or '`/Zc:alignedNew-`' are used |
201+
| Compiler warning C5219 | implicit conversion from '*type-1*' to '*type-2*', possible loss of data |
202+
| Compiler warning C5220 | '*name*': a non-static data member with a volatile qualified type no longer implies that compiler generated copy/move constructors and copy/move assignment operators are not trivial |
203+
| Compiler warning C5221 | `xfg::rename` is deprecated. |
204+
191205

192206
## See also
193207

docs/error-messages/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3629,6 +3629,8 @@
36293629
href: compiler-warnings/compiler-warning-level-1-c4383.md
36303630
- name: Compiler warning (level 1) C4384
36313631
href: compiler-warnings/compiler-warning-level-1-c4384.md
3632+
- name: Compiler warning (level 4) C4388
3633+
href: compiler-warnings/c4388.md
36323634
- name: Compiler warning (level 4) C4389
36333635
href: compiler-warnings/compiler-warning-level-4-c4389.md
36343636
- name: Compiler warning (level 3) C4390

0 commit comments

Comments
 (0)