Skip to content

Commit 0f98680

Browse files
Merge pull request #5012 from MicrosoftDocs/main638481943700200737sync_temp
For protected branch, push strategy should use PR and merge to target branch method to work around git push error
2 parents 27a46ce + 48093af commit 0f98680

23 files changed

+295
-300
lines changed

docs/code-quality/c6031.md

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
---
22
title: Warning C6031
33
description: "Describes C++ Code Analysis warning C6031 and how to resolve it."
4-
ms.date: 10/04/2022
4+
ms.date: 4/5/2024
55
f1_keywords: ["C6031", "RETVAL_IGNORED_FUNC_COULD_FAIL", "__WARNING_RETVAL_IGNORED_FUNC_COULD_FAIL"]
66
helpviewer_keywords: ["C6031"]
7-
ms.assetid: 59e1ef0a-b3ca-4ffa-bcb3-ad2bd22ece22
87
---
98
# Warning C6031
109

@@ -16,44 +15,48 @@ Warning C6031 indicates the caller doesn't check a function's return value for f
1615

1716
In general, it isn't safe to assume that calls to functions requiring disk, network, memory, or other resources will succeed. The caller should always check the return value and handle error cases appropriately. Also consider using the `_Must_inspect_result_` annotation, which checks that the value is examined in a useful way.
1817

18+
This warning applies to both C and C++ code.
19+
1920
Code analysis name: `RETVAL_IGNORED_FUNC_COULD_FAIL`
2021

2122
## Example
2223

2324
The following code generates warning C6031:
2425

25-
```cpp
26+
```c
2627
#include <stdio.h>
27-
void f( )
28+
int main()
2829
{
29-
fopen( "test.c", "r" ); // C4996, C6031 return value ignored
30+
fopen("test.c", "r"); // C4996, C6031 return value ignored
3031
// code ...
3132
}
3233
```
3334

3435
To correct this warning, check the return value of the function as shown in the following code:
3536

36-
```cpp
37+
```c
3738
#include <stdio.h>
38-
void f( )
39+
int main()
3940
{
40-
FILE *stream;
41-
if ( (stream = fopen( "test.c", "r" )) == NULL )
41+
FILE* stream;
42+
if ((stream = fopen("test.c", "r")) == NULL)
43+
{
4244
return;
45+
}
4346
// code ...
4447
}
4548
```
4649

4750
The following code uses safe function `fopen_s` to correct this warning:
4851

49-
```cpp
52+
```c
5053
#include <stdio.h>
51-
void f( )
54+
int main()
5255
{
53-
FILE *stream;
56+
FILE* stream;
5457
errno_t err;
5558

56-
if ( (err = fopen_s( &stream, "test.c", "r" )) !=0 )
59+
if ((err = fopen_s(&stream, "test.c", "r")) != 0)
5760
{
5861
// code ...
5962
}
@@ -64,23 +67,30 @@ This warning is also generated if the caller ignores the return value of a funct
6467

6568
```cpp
6669
#include <sal.h>
67-
_Check_return_ bool func();
70+
_Check_return_ bool func()
71+
{
72+
return true;
73+
}
6874

69-
void test_f()
75+
int main()
7076
{
71-
func(); // Warning C6031
77+
func();
7278
}
7379
```
7480

7581
To correct the previous warning, check the return value as shown in the following code:
7682

7783
```cpp
7884
#include <sal.h>
79-
_Check_return_ bool func();
85+
_Check_return_ bool func()
86+
{
87+
return true;
88+
}
8089

81-
void test_f()
90+
int main()
8291
{
83-
if ( func() ) {
92+
if (func())
93+
{
8494
// code ...
8595
}
8696
}
@@ -91,10 +101,12 @@ In cases where it's necessary to ignore the return value of a function, assign t
91101
```cpp
92102
#include <tuple>
93103
#include <ctime>
104+
#include <cstdlib>
94105
#include <stdio.h>
95-
void f()
106+
107+
int main()
96108
{
97-
std::srand(static_cast(std::time(nullptr))); // set initial seed value to system clock
109+
std::srand(static_cast<unsigned int>(std::time(nullptr))); // set initial seed value to system clock
98110
std::ignore = std::rand(); // Discard the first result as the few random results are always small.
99111
// ...
100112
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
description: "Learn more about: Compiler Warning (level 3) C4371"
3-
title: "Compiler Warning (level 3) C4371"
2+
description: "Learn more about: Compiler Warning (level 3, off) C4371"
3+
title: "Compiler Warning (level 3, off) C4371"
44
ms.date: "01/31/2018"
55
f1_keywords: ["C4371"]
66
helpviewer_keywords: ["C4371"]
@@ -9,6 +9,6 @@ helpviewer_keywords: ["C4371"]
99

1010
> '*classname*': layout of class may have changed from a previous version of the compiler due to better packing of member '*member*'
1111
12-
If your code relies on a particular memory layout for a class, warning C4371 tells you that the layout created by the current compiler may be different from the layout generated by previous versions of the compiler. This may be significant for serialization operations or operating system interfaces that rely on a particular memory layout. In most other cases, this warning is safe to ignore.
12+
Warning C4371 tells you that the layout created by the current compiler may be different from the layout generated by previous versions of the compiler. This difference may be significant for serialization operations or operating system interfaces that rely on a particular memory layout. In most other cases, this warning is safe to ignore.
1313

1414
Warning C4371 is off by default. For more information, see [Compiler Warnings That Are Off By Default](../../preprocessor/compiler-warnings-that-are-off-by-default.md).

docs/error-messages/compiler-warnings/c4388.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
2-
title: "Compiler Warning (level 4) C4388"
3-
description: "Microsoft C/C++ compiler warning C4388, its causes and resolution."
2+
title: "Compiler Warning (level 4, off) C4388"
3+
description: "Learn more about: Compiler Warning (level 4, off) C4388"
44
ms.date: 10/16/2020
55
f1_keywords: ["C4388"]
66
helpviewer_keywords: ["C4388"]
77
---
8-
# Compiler Warning (level 4) C4388
8+
# Compiler Warning (level 4, off) C4388
99

1010
> '*token*' : signed/unsigned mismatch
1111

docs/error-messages/compiler-warnings/compiler-warning-c4335.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
---
2-
description: "Learn more about: Compiler Warning C4335"
3-
title: "Compiler Warning C4335"
2+
description: "Learn more about: Compiler Warning (level 1) C4335"
3+
title: "Compiler Warning(level 1) C4335"
44
ms.date: "11/04/2016"
55
f1_keywords: ["C4335"]
66
helpviewer_keywords: ["C4335"]
7-
ms.assetid: e66467ad-a10b-4438-8c7c-e8e8d11d39bb
87
---
9-
# Compiler Warning C4335
8+
# Compiler Warning (level 1) C4335
109

11-
Mac file format detected: please convert the source file to either DOS or UNIX format
10+
> Mac file format detected: please convert the source file to either DOS or UNIX format
1211
13-
The line termination character of the first line of a source file is Macintosh style ('\r') as opposed to UNIX ('\n') or DOS ('\r\n').
12+
The line termination character of the first line of a source file is the old Macintosh style ('\r') as opposed to UNIX ('\n') or DOS ('\r\n').
1413

15-
This warning is always issued as an error. See [warning](../../preprocessor/warning.md) pragma for information about how to disable this warning. Also, this warning is only issued once per compiland. Therefore, if there are multiple `#include` directives that specify files in Macintosh format, C4335 will only be issued once.
14+
This warning is only issued once per translation unit. Therefore, if there are multiple `#include` directives that specify files in Macintosh format, C4335 is emitted once.
1615

1716
One way to generate files in Macintosh format is by using the **Advanced Save Options** (on the **File** menu) in Visual Studio.
1817

docs/error-messages/compiler-warnings/compiler-warning-c4368.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
---
2-
description: "Learn more about: Compiler Warning C4368"
3-
title: "Compiler Warning C4368"
2+
description: "Learn more about: Compiler Warning (level 1, Error) C4368"
3+
title: "Compiler Warning (level 1, Error) C4368"
44
ms.date: "11/04/2016"
55
f1_keywords: ["C4368"]
66
helpviewer_keywords: ["C4368"]
7-
ms.assetid: cb85bcee-fd3d-4aa5-b626-2324f07a4f1b
87
---
9-
# Compiler Warning C4368
8+
# Compiler Warning (level 1, Error) C4368
109

11-
cannot define 'member' as a member of managed 'type': mixed types are not supported
10+
> cannot define 'member' as a member of managed 'type': mixed types are not supported
1211
13-
You cannot embed a native data member in a CLR type.
12+
You can't embed a native data member in a managed type.
1413

15-
You can, however, declare a pointer to a native type and control its lifetime in the constructor and destructor and finalizer of your managed class. For more information see [Destructors and finalizers](../../dotnet/how-to-define-and-consume-classes-and-structs-cpp-cli.md#BKMK_Destructors_and_finalizers).
14+
You can, however, declare a pointer to a native type and control its lifetime in the constructor and destructor and finalizer of your managed class. For more information, see [Destructors and finalizers](../../dotnet/how-to-define-and-consume-classes-and-structs-cpp-cli.md#BKMK_Destructors_and_finalizers).
1615

1716
This warning is always issued as an error. Use the [warning](../../preprocessor/warning.md) pragma to disable C4368.
1817

docs/error-messages/compiler-warnings/compiler-warning-c4394.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
---
2-
description: "Learn more about: Compiler Warning C4394"
3-
title: "Compiler Warning C4394"
2+
description: "Learn more about: Compiler Warning (level 1, Error) C4394"
3+
title: "Compiler Warning (level 1, Error) C4394"
44
ms.date: "11/04/2016"
55
f1_keywords: ["C4394"]
66
helpviewer_keywords: ["C4394"]
7-
ms.assetid: 5de94de0-17e3-4e7c-92f4-5c3c1b825120
87
---
9-
# Compiler Warning C4394
8+
# Compiler Warning (level 1, Error) C4394
109

11-
'function' : per-appdomain symbol should not be marked with __declspec(dllexport)
10+
> 'function' : per-appdomain symbol should not be marked with __declspec(dllexport)
1211
13-
A function marked with the [appdomain](../../cpp/appdomain.md) **`__declspec`** modifier is compiled to MSIL (not to native), and export tables ([export](../../windows/attributes/export.md) **`__declspec`** modifier) are not supported for managed functions.
12+
A function marked with the [appdomain](../../cpp/appdomain.md) **`__declspec`** modifier is compiled to MSIL (not native), and export tables ([export](../../windows/attributes/export.md) **`__declspec`** modifier) aren't supported for managed functions.
1413

1514
You can declare a managed function to have public accessibility. For more information, see [Type visibility](../../dotnet/how-to-define-and-consume-classes-and-structs-cpp-cli.md#BKMK_Type_visibility) and [Member visibility](../../dotnet/how-to-define-and-consume-classes-and-structs-cpp-cli.md#BKMK_Member_visibility).
1615

17-
C4394 is always issued as an error. You can turn off this warning with the `#pragma warning` or **/wd**; see [warning](../../preprocessor/warning.md) or [/w, /W0, /W1, /W2, /W3, /W4, /w1, /w2, /w3, /w4, /Wall, /wd, /we, /wo, /Wv, /WX (Warning Level)](../../build/reference/compiler-option-warning-level.md) for more information.
16+
C4394 is always issued as an error. You can turn off this warning or change its level with `#pragma warning` or **/wd**. For more information, see [warning](../../preprocessor/warning.md) or [/w, /W0, /W1, /W2, /W3, /W4, /w1, /w2, /w3, /w4, /Wall, /wd, /we, /wo, /Wv, /WX (Warning Level)](../../build/reference/compiler-option-warning-level.md).
1817

1918
## Example
2019

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
---
2-
description: "Learn more about: Compiler Warning (level 1) C4264"
3-
title: "Compiler Warning (level 1) C4264"
2+
description: "Learn more about: Compiler Warning (level 4, off) C4264"
3+
title: "Compiler Warning (level 4, off) C4264"
44
ms.date: "11/04/2016"
55
f1_keywords: ["C4264"]
66
helpviewer_keywords: ["C4264"]
7-
ms.assetid: 315a13c1-ca54-4a90-9d2b-dd996463af5d
87
---
9-
# Compiler Warning (level 1) C4264
8+
# Compiler Warning (level 4, off) C4264
109

11-
'virtual_function' : no override available for virtual member function from base 'class'; function is hidden
10+
> 'virtual_function' : no override available for virtual member function from base 'class'; function is hidden
1211
1312
C4264 is always generated after [C4263](../../error-messages/compiler-warnings/compiler-warning-level-4-c4263.md).
1413

15-
This warning is off by default. See [Compiler Warnings That Are Off by Default](../../preprocessor/compiler-warnings-that-are-off-by-default.md) for more information.
14+
This warning is off by default. For more information, see [Compiler Warnings That Are Off by Default](../../preprocessor/compiler-warnings-that-are-off-by-default.md).

docs/error-messages/compiler-warnings/compiler-warning-level-1-c4392.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
---
2-
description: "Learn more about: Compiler Warning (level 1) C4392"
3-
title: "Compiler Warning (level 1) C4392"
2+
description: "Learn more about: Compiler Warning (level 1, Error) C4392"
3+
title: "Compiler Warning (level 1, Error) C4392"
44
ms.date: "11/04/2016"
55
f1_keywords: ["C4392"]
66
helpviewer_keywords: ["C4392"]
7-
ms.assetid: 817806ad-06a6-4b9e-8355-e25687c782dc
87
---
9-
# Compiler Warning (level 1) C4392
8+
# Compiler Warning (level 1, Error) C4392
109

11-
'signature' : incorrect number of arguments for intrinsic function, expected 'number' arguments
10+
> 'signature' : incorrect number of arguments for intrinsic function, expected 'number' arguments
1211
13-
A function declaration for a compiler intrinsic had the wrong number of arguments. The resulting image may not run correctly.
12+
A function declaration for a compiler intrinsic had the wrong number of arguments. The resulting image may not run correctly. To fix this warning, either correct the declaration or delete the declaration and `#include` the appropriate header file.
1413

15-
To fix this warning, either correct the declaration or delete the declaration and simply #include the appropriate header file.
14+
This warning is always issued as an error. Use the [warning](../../preprocessor/warning.md) pragma to disable or change the warning level.
1615

1716
The following sample generates C4392:
1817

docs/error-messages/compiler-warnings/compiler-warning-level-1-c4399.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
---
2-
description: "Learn more about: Compiler Warning (level 1) C4399"
3-
title: "Compiler Warning (level 1) C4399"
2+
description: "Learn more about: Compiler Warning (level 1, Error) C4399"
3+
title: "Compiler Warning (level 1, Error) C4399"
44
ms.date: "11/04/2016"
55
f1_keywords: ["C4399"]
66
helpviewer_keywords: ["C4399"]
77
ms.assetid: f58d9ba7-71a0-4c3b-b26f-f946dda8af30
88
---
9-
# Compiler Warning (level 1) C4399
9+
# Compiler Warning (level 1, Error) C4399
1010

1111
> '*symbol*' : per-process symbol should not be marked with __declspec(dllimport) when compiled with /clr:pure
1212
1313
## Remarks
1414

1515
The **/clr:pure** compiler option is deprecated in Visual Studio 2015 and unsupported in Visual Studio 2017.
1616

17-
Data from a native image or an image with native and CLR constructs can not be imported into a pure image. To resolve this warning, compile with **/clr** (not **/clr:pure**) or delete `__declspec(dllimport)`.
17+
Data from a native image or an image with native and common language runtime (CLR) constructs can't be imported into a pure image. To resolve this warning, compile with **/clr** (not **/clr:pure**) or delete `__declspec(dllimport)`.
18+
19+
This warning can be issued as an error. Use the [warning](../../preprocessor/warning.md) pragma to disable or change the warning level.
1820

1921
## Example
2022

docs/error-messages/compiler-warnings/compiler-warning-level-3-c4265.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
---
2-
description: "Learn more about: Compiler Warning (level 3) C4265"
3-
title: "Compiler Warning (level 3) C4265"
2+
description: "Learn more about: Compiler Warning (level 3, off) C4265"
3+
title: "Compiler Warning (level 3, off) C4265"
44
ms.date: "11/04/2016"
55
f1_keywords: ["C4265"]
66
helpviewer_keywords: ["C4265"]
7-
ms.assetid: 20547159-6f30-4cc4-83aa-927884c8bb4c
87
---
9-
# Compiler Warning (level 3) C4265
8+
# Compiler Warning (level 3, off) C4265
109

11-
'class' : class has virtual functions, but destructor is not virtual
10+
> 'class' : class has virtual functions, but destructor is not virtual
1211
1312
When a class has virtual functions but a nonvirtual destructor, objects of the type might not be destroyed properly when the class is destroyed through a base class pointer.
1413

15-
This warning is off by default. See [Compiler Warnings That Are Off by Default](../../preprocessor/compiler-warnings-that-are-off-by-default.md) for more information.
14+
This warning is off by default. For more information, see [Compiler Warnings That Are Off by Default](../../preprocessor/compiler-warnings-that-are-off-by-default.md).
1615

1716
The following sample generates C4265:
1817

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
---
2-
description: "Learn more about: Compiler Warning (level 3) C4278"
3-
title: "Compiler Warning (level 3) C4278"
2+
description: "Learn more about: Compiler Warning (level 3 and level 4) C4278"
3+
title: "Compiler Warning (level 3 and level 4) C4278"
44
ms.date: "08/27/2018"
55
f1_keywords: ["C4278"]
66
helpviewer_keywords: ["C4278"]
7-
ms.assetid: 4b6053fb-df62-4c04-b6c8-c011759557b8
87
---
9-
# Compiler Warning (level 3) C4278
8+
# Compiler Warning (level 3 and level 4) C4278
109

1110
> '*identifier*': identifier in type library '*tlb*' is already a macro; use the 'rename' qualifier
1211
13-
When using [#import](../../preprocessor/hash-import-directive-cpp.md), an identifier in the typelib you are importing is attempting to declare an identifier *identifier*. However, this is already a valid symbol.
14-
15-
Use the `#import` **rename** attribute to assign an alias to the symbol in the type library.
12+
The [`#import`](../../preprocessor/hash-import-directive-cpp.md) is attempting to import an identifier into the translation unit. However, there's already a symbol with that name. Use the `#import` **rename** attribute to assign an alias to the symbol in the type library.

docs/error-messages/compiler-warnings/compiler-warning-level-3-c4287.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
---
2-
description: "Learn more about: Compiler Warning (level 3) C4287"
3-
title: "Compiler Warning (level 3) C4287"
2+
description: "Learn more about: Compiler Warning (level 3, off) C4287"
3+
title: "Compiler Warning (level 3, off) C4287"
44
ms.date: "11/04/2016"
55
f1_keywords: ["C4287"]
66
helpviewer_keywords: ["C4287"]
7-
ms.assetid: 1bf3bff8-6402-4d06-95ba-431678a790a7
87
---
9-
# Compiler Warning (level 3) C4287
8+
# Compiler Warning (level 3, off) C4287
109

11-
'operator' : unsigned/negative constant mismatch
10+
> 'operator' : unsigned/negative constant mismatch
1211
1312
An unsigned variable was used in an operation with a negative number.
1413

15-
This warning is off by default. See [Compiler Warnings That Are Off by Default](../../preprocessor/compiler-warnings-that-are-off-by-default.md) for more information.
14+
This warning is off by default. For more information, see [Compiler Warnings That Are Off by Default](../../preprocessor/compiler-warnings-that-are-off-by-default.md).
1615

1716
## Example
1817

docs/error-messages/compiler-warnings/compiler-warning-level-3-c4359.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
---
2-
description: "Learn more about: Compiler Warning (level 3) C4359"
3-
title: "Compiler Warning (level 3) C4359"
2+
description: "Learn more about: Compiler Warning (level 1 and level 3) C4359"
3+
title: "Compiler Warning (level 1 and level 3) C4359"
44
ms.date: "11/04/2016"
55
f1_keywords: ["C4359"]
66
helpviewer_keywords: ["C4359"]
7-
ms.assetid: d8fe993c-ef82-45a0-a43d-c29f9d1bacdb
87
---
9-
# Compiler Warning (level 3) C4359
8+
# Compiler Warning (level 1 and level 3) C4359
109

11-
'type': actual alignment (8) is greater than the value specified in __declspec(align())
10+
> 'type': actual alignment (8) is greater than the value specified in __declspec(align())
1211
13-
The alignment specified for a type is less than the alignment of the type of one of its data members. For more information, see [align](../../cpp/align-cpp.md).
12+
The alignment specified for a type is less than the alignment of the type of one of its data members. For more information, see [align](../../cpp/align-cpp.md).
1413

1514
## Example
1615

0 commit comments

Comments
 (0)