Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/error-messages/compiler-warnings/c4834.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ To turn off the warning for an entire project in the Visual Studio IDE:

## Example

This sample generates C4834, and shows four ways to fix it:
This example generates C4834, and shows four ways to fix it:

```cpp
// C4834.cpp
Expand Down
2 changes: 1 addition & 1 deletion docs/error-messages/compiler-warnings/c4841.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
description: "Learn more about: Compiler Warning (level 4) C4841"
title: "Compiler Warning (level 4) C4841"
description: "Learn more about: Compiler Warning (level 4) C4841"
ms.date: 05/03/2021
f1_keywords: ["C4841"]
helpviewer_keywords: ["C4841"]
Expand Down
4 changes: 2 additions & 2 deletions docs/error-messages/compiler-warnings/c4843.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
description: "Learn more about: Compiler Warning (level 4) C4843"
title: "Compiler Warning (level 4) C4843"
description: "Learn more about: Compiler Warning (level 4) C4843"
ms.date: 05/03/2021
f1_keywords: ["C4843"]
helpviewer_keywords: ["C4843"]
Expand All @@ -17,7 +17,7 @@ This warning is new in Visual Studio 2017 version 15.5. For information on how t

## Example

This sample shows several **`catch`** statements that cause C4843:
This example shows several **`catch`** statements that cause C4843:

```cpp
// C4843_warning.cpp
Expand Down
8 changes: 4 additions & 4 deletions docs/error-messages/compiler-warnings/c4866.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
description: "Learn more about: Compiler Warning (level 4) C4866"
title: "Compiler Warning (Level 4) C4866"
ms.date: "09/30/2018"
description: "Learn more about: Compiler Warning (level 4) C4866"
ms.date: 09/30/2018
f1_keywords: ["C4866"]
helpviewer_keywords: ["C4866"]
---
Expand All @@ -25,11 +25,11 @@ This warning was introduced in Visual Studio 2017 version 15.9 as a result of co

To resolve this warning, first consider whether left-to-right evaluation of the operator elements is necessary, such as when evaluation of the elements might produce order-dependent side-effects. In many cases, the order in which elements are evaluated does not have an observable effect.

If the order of evaluation must be left-to-right, consider whether you can pass the elements by **`const`** reference instead. This change eliminates the warning in the following code sample.
If the order of evaluation must be left-to-right, consider whether you can pass the elements by **`const`** reference instead. This change eliminates the warning in the following code example.

## Example

This sample generates C4866, and shows a way to fix it:
This example generates C4866, and shows a way to fix it:

```cpp
// C4866.cpp
Expand Down
11 changes: 6 additions & 5 deletions docs/error-messages/compiler-warnings/compiler-warning-c4867.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
---
description: "Learn more about: Compiler Warning C4867"
title: "Compiler Warning C4867"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Warning C4867"
ms.date: 11/04/2016
f1_keywords: ["C4867"]
helpviewer_keywords: ["C4867"]
ms.assetid: 8a257d70-c3a7-462d-b285-e57c952a8bf7
---
# Compiler Warning C4867

'function': function call missing argument list; use 'call' to create a pointer to member
> 'function': function call missing argument list; use 'call' to create a pointer to member

## Remarks

A pointer to member function was initialized incorrectly.

Expand All @@ -18,7 +19,7 @@ This warning is always issued as an error. Use the [warning](../../preprocessor/

## Example

The following sample generates C4867.
The following example generates C4867.

```cpp
// C4867.cpp
Expand Down
11 changes: 6 additions & 5 deletions docs/error-messages/compiler-warnings/compiler-warning-c4868.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
---
description: "Learn more about: Compiler Warning (level 4) C4868"
title: "Compiler Warning C4868"
ms.date: "10/26/2017"
description: "Learn more about: Compiler Warning (level 4) C4868"
ms.date: 10/26/2017
f1_keywords: ["C4868"]
helpviewer_keywords: ["C4868"]
ms.assetid: fc6aa7e5-34dd-4ec2-88bd-16e430361dc7
---
# Compiler Warning (level 4) C4868

> '_file_(*line_number*)' compiler may not enforce left-to-right evaluation order in braced initializer list

## Remarks

The elements of a braced initializer list are to be evaluated in left-to-right order. There are two cases in which the compiler is unable to guarantee this order: the first is when some of the elements are objects passed by value; the second is when compiling with `/clr` and some of the elements are fields of objects or are array elements. When the compiler can't guarantee left-to-right evaluation it emits warning C4868.

This warning can be generated as a result of compiler conformance work that was done for Visual Studio 2015 Update 2. Code that compiled prior to Visual Studio 2015 Update 2 can now generate C4868.
Expand All @@ -18,11 +19,11 @@ This warning is off by default. Use `/Wall` to activate this warning.

To resolve this warning, first consider whether left-to-right evaluation of the initializer list elements is necessary, such as when evaluation of the elements might produce order-dependent side-effects. In many cases, the order in which elements are evaluated does not have an observable effect.

If the order of evaluation must be left-to-right, consider if it's possible to pass the elements by **`const`** reference instead. A change such as this eliminates the warning in the following code sample.
If the order of evaluation must be left-to-right, consider if it's possible to pass the elements by **`const`** reference instead. A change such as this eliminates the warning in the following code example.

## Example

This sample generates C4868, and shows a way to fix it:
This example generates C4868, and shows a way to fix it:

```cpp
// C4868.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
description: "Learn more about: Compiler Warning C4936"
title: "Compiler Warning C4936"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Warning C4936"
ms.date: 11/04/2016
f1_keywords: ["C4936"]
helpviewer_keywords: ["C4936"]
ms.assetid: 6676de35-bf1b-4d0b-a70f-b5734130336c
---
# Compiler Warning C4936

Expand All @@ -22,7 +21,7 @@ C4936 is always issued as an error. You can disable C4936 with the [warning](..

## Example

The following sample generates C4936:
The following example generates C4936:

```cpp
// C4936.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
---
description: "Learn more about: Compiler Warning (level 1) C4835"
title: "Compiler Warning (level 1) C4835"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Warning (level 1) C4835"
ms.date: 11/04/2016
f1_keywords: ["C4835"]
helpviewer_keywords: ["C4835"]
ms.assetid: d2e44c62-7b0e-4a45-943d-97903e27ed9d
---
# Compiler Warning (level 1) C4835

'variable' : the initializer for exported data will not be run until managed code is first executed in the host assembly
> 'variable' : the initializer for exported data will not be run until managed code is first executed in the host assembly

## Remarks

When accessing data between managed components, it is recommended that you not use native C++ import and export mechanisms. Instead, declare your data members inside a managed type and reference the metadata with `#using` in the client. For more information, see [#using Directive](../../preprocessor/hash-using-directive-cpp.md).

## Examples

The following sample generates C4835.
The following example generates C4835.

```cpp
// C4835.cpp
Expand All @@ -26,7 +27,7 @@ __declspec(dllexport) int m = f(); // C4835
__declspec(dllexport) int *p = &n; // C4835
```

The following sample consumes the component built in the previous sample, showing that the value of the variables is not as expected.
The following example consumes the component built in the previous example, showing that the value of the variables is not as expected.

```cpp
// C4835_b.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
---
description: "Learn more about: Compiler Warning (level 1) C4838"
title: "Compiler Warning (level 1) C4838"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Warning (level 1) C4838"
ms.date: 11/04/2016
f1_keywords: ["C4838"]
helpviewer_keywords: ["C4838"]
ms.assetid: fea07924-5feb-4ed4-99b5-1a8c41d28db6
---
# Compiler Warning (level 1) C4838

conversion from 'type_1' to 'type_2' requires a narrowing conversion
> conversion from 'type_1' to 'type_2' requires a narrowing conversion

## Remarks

An implicit narrowing conversion was found when using aggregate or list initialization.

The C language allows implicit narrowing conversions in assignments and initialization, and C++ follows suit, even though unexpected narrowing is a cause of many code errors. To make code safer, the C++ standard requires a diagnostic message when a narrowing conversion occurs in an initialization list. In Visual C++, the diagnostic is [Compiler Error C2397](../../error-messages/compiler-errors-1/compiler-error-c2397.md) when using the uniform initialization syntax supported beginning in Visual Studio 2015. The compiler generates warning C4838 when using the list or aggregate initialization syntax supported by Visual Studio 2013.

A narrowing conversion can be okay when you know the possible range of converted values can fit in the target. In this case, you know more than the compiler does. If you make a narrowing conversion intentionally, make your intentions explicit by using a static cast. Otherwise, this warning message almost always indicates that you have a bug in your code. You can fix it by making sure the objects you initialize have types that are large enough to handle the inputs.

The following sample generates C4838 and shows one way to fix it:
## Example

The following example generates C4838 and shows one way to fix it:

```cpp
// C4838.cpp -- C++ narrowing conversion diagnostics
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
---
description: "Learn more about: Compiler Warning (level 1) C4900"
title: "Compiler Warning (level 1) C4900"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Warning (level 1) C4900"
ms.date: 11/04/2016
f1_keywords: ["C4900"]
helpviewer_keywords: ["C4900"]
ms.assetid: 826997ec-0803-4794-ad35-bb463f679658
---
# Compiler Warning (level 1) C4900

intermediate language mismatch between 'tool1' version 'version1' and 'tool2' version 'version2'
> intermediate language mismatch between 'tool1' version 'version1' and 'tool2' version 'version2'

## Remarks

The intermediate language used in *tool1* and *tool2* did not match. Check that the most current version of each tool has been installed.
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
---
description: "Learn more about: Compiler Warning (level 1) C4905"
title: "Compiler Warning (level 1) C4905"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Warning (level 1) C4905"
ms.date: 11/04/2016
f1_keywords: ["C4905"]
helpviewer_keywords: ["C4905"]
ms.assetid: 40240bf4-b14e-4c22-aeb2-52f2851532f6
---
# Compiler Warning (level 1) C4905

wide string literal cast to 'LPSTR'
> wide string literal cast to 'LPSTR'

## Remarks

The compiler detected an unsafe cast. The cast did succeed, but you should use a conversion routine.

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.

## Example

The following sample generates C4905.
The following example generates C4905.

```cpp
// C4905.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
---
description: "Learn more about: Compiler Warning (level 1) C4906"
title: "Compiler Warning (level 1) C4906"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Warning (level 1) C4906"
ms.date: 11/04/2016
f1_keywords: ["C4906"]
helpviewer_keywords: ["C4906"]
ms.assetid: 05318e74-799b-412a-9dce-f02b8161d762
---
# Compiler Warning (level 1) C4906

string literal cast to 'LPWSTR'
> string literal cast to 'LPWSTR'

## Remarks

The compiler detected an unsafe cast. The cast did succeed, but you should use a conversion routine.

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.

## Example

The following sample generates C4906:
The following example generates C4906:

```cpp
// C4906.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
---
description: "Learn more about: Compiler Warning (level 1) C4910"
title: "Compiler Warning (level 1) C4910"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Warning (level 1) C4910"
ms.date: 11/04/2016
f1_keywords: ["C4910"]
helpviewer_keywords: ["C4910"]
ms.assetid: 67963560-fbca-4ca7-93db-06beaf7055f0
---
# Compiler Warning (level 1) C4910

'\<identifier>' : '__declspec(dllexport)' and 'extern' are incompatible on an explicit instantiation
> '\<identifier>' : '__declspec(dllexport)' and 'extern' are incompatible on an explicit instantiation

## Remarks

The explicit template instantiation named *\<identifier>* is modified by both the `__declspec(dllexport)` and **`extern`** keywords. However, these keywords are mutually exclusive. The `__declspec(dllexport)` keyword means instantiate the template class, while the **`extern`** keyword means do not automatically instantiate the template class.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
---
description: "Learn more about: Compiler Warning (level 1) C4912"
title: "Compiler Warning (level 1) C4912"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Warning (level 1) C4912"
ms.date: 11/04/2016
f1_keywords: ["C4912"]
helpviewer_keywords: ["C4912"]
ms.assetid: ba1f1a66-8c20-4792-9ac8-43e49f729ae2
---
# Compiler Warning (level 1) C4912

'attribute': attribute has undefined behavior on a nested UDT
> 'attribute': attribute has undefined behavior on a nested UDT

## Remarks

Attributes that apply to nested UDTs (user-defined type, which could be a typedef, union, or struct) may be ignored.

## Example

The following code shows how this warning would be generated:

```cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
---
description: "Learn more about: Compiler Warning (level 1) C4917"
title: "Compiler Warning (level 1) C4917"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Warning (level 1) C4917"
ms.date: 11/04/2016
f1_keywords: ["C4917"]
helpviewer_keywords: ["C4917"]
ms.assetid: c05e2610-4a5d-4f4b-a99b-c15fd7f1d5f1
---
# Compiler Warning (level 1) C4917

'declarator' : a GUID can only be associated with a class, interface or namespace
> 'declarator' : a GUID can only be associated with a class, interface or namespace

## Remarks

A user-defined structure other than [class](../../cpp/class-cpp.md), [interface](../../cpp/interface.md), or [namespace](../../cpp/namespaces-cpp.md) cannot have a GUID.

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.

## Example

The following code sample generates C4917:
The following code example generates C4917:

```cpp
// C4917.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
---
description: "Learn more about: Compiler Warning (level 1) C4920"
title: "Compiler Warning (level 1) C4920"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Warning (level 1) C4920"
ms.date: 11/04/2016
f1_keywords: ["C4920"]
helpviewer_keywords: ["C4920"]
ms.assetid: 1e501f2e-93c1-4d27-a4fa-54fc86271ae7
---
# Compiler Warning (level 1) C4920

enum enum member member=value already seen in enum enum as member=value
> enum enum member member=value already seen in enum enum as member=value

## Remarks

If a .tlb that you pass to #import has the same symbol defined in two or more enums, this warning indicates that subsequent identical symbols are ignored and will be commented out in the .tlh file.

## Example

Assuming a .tlb that contains:

```
Expand All @@ -27,7 +30,7 @@ library MyLib
};
```

the following samples generates C4920,
the following example generates C4920,

```cpp
// C4920.cpp
Expand Down
Loading