Skip to content

Structure error references in range [C2431, C2460] #5589

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 8 additions & 5 deletions docs/error-messages/compiler-errors-1/compiler-error-c2431.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
---
description: "Learn more about: Compiler Error C2431"
title: "Compiler Error C2431"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C2431"
ms.date: 11/04/2016
f1_keywords: ["C2431"]
helpviewer_keywords: ["C2431"]
ms.assetid: 88a5b648-c89f-47d1-a20e-63231ab4f0f7
---
# Compiler Error C2431

illegal index register in 'identifier'
> illegal index register in 'identifier'

## Remarks

The ESP register is scaled or used as both index and base register. The SIB encoding for the x86 processor does not allow either.

The following sample generates C2431:
## Example

The following example generates C2431:

```cpp
// C2431.cpp
Expand Down
13 changes: 8 additions & 5 deletions docs/error-messages/compiler-errors-1/compiler-error-c2432.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
---
description: "Learn more about: Compiler Error C2432"
title: "Compiler Error C2432"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C2432"
ms.date: 11/04/2016
f1_keywords: ["C2432"]
helpviewer_keywords: ["C2432"]
ms.assetid: 0e3326e8-cab1-45a5-b48d-61edd33793e8
---
# Compiler Error C2432

illegal reference to 16-bit data in 'identifier'
> illegal reference to 16-bit data in 'identifier'

## Remarks

A 16-bit register is used as an index or base register. The compiler does not support referencing 16-bit data. 16-bit registers cannot be used as index or base registers when compiling for 32-bit code.

The following sample generates C2432:
## Example

The following example generates C2432:

```cpp
// C2432.cpp
Expand Down
2 changes: 2 additions & 0 deletions docs/error-messages/compiler-errors-1/compiler-error-c2433.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ helpviewer_keywords: ["C2433"]

> '*identifier*': '*modifier*' not permitted on data declarations

## Remarks

The **`friend`**, **`virtual`**, and **`inline`** modifiers cannot be used for data declarations.

## Example
Expand Down
7 changes: 3 additions & 4 deletions docs/error-messages/compiler-errors-1/compiler-error-c2434.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
description: "Learn more about: Compiler Error C2434"
title: "Compiler Error C2434"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C2434"
ms.date: 11/04/2016
f1_keywords: ["C2434"]
helpviewer_keywords: ["C2434"]
ms.assetid: 01329e26-7c74-4219-b74f-69e3a40c9738
---
# Compiler Error C2434

Expand All @@ -18,7 +17,7 @@ It is not possible to dynamically initialize a per-process variable under **/clr

## Example

The following sample generates C2434. To fix this issue, use constants to initialize `process` variables.
The following example generates C2434. To fix this issue, use constants to initialize `process` variables.

```cpp
// C2434.cpp
Expand Down
7 changes: 3 additions & 4 deletions docs/error-messages/compiler-errors-1/compiler-error-c2435.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
description: "Learn more about: Compiler Error C2435"
title: "Compiler Error C2435"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C2435"
ms.date: 11/04/2016
f1_keywords: ["C2435"]
helpviewer_keywords: ["C2435"]
ms.assetid: be6aa8f8-579b-42ea-bdd8-2d01393646ad
---
# Compiler Error C2435

Expand All @@ -20,7 +19,7 @@ For more information, see [appdomain](../../cpp/appdomain.md) and [process](../.

## Example

The following sample generates C2435:
The following example generates C2435:

```cpp
// C2435.cpp
Expand Down
13 changes: 8 additions & 5 deletions docs/error-messages/compiler-errors-1/compiler-error-c2436.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
---
description: "Learn more about: Compiler Error C2436"
title: "Compiler Error C2436"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C2436"
ms.date: 11/04/2016
f1_keywords: ["C2436"]
helpviewer_keywords: ["C2436"]
ms.assetid: ca4cc813-bc1d-4c0a-9a2c-3a5fe673d084
---
# Compiler Error C2436

'identifier' : member function or nested class in constructor initializer list
> 'identifier' : member function or nested class in constructor initializer list

## Remarks

Member functions or local classes in the constructor initializer list cannot be initialized.

The following sample generates C2436:
## Example

The following example generates C2436:

```cpp
// C2436.cpp
Expand Down
13 changes: 8 additions & 5 deletions docs/error-messages/compiler-errors-1/compiler-error-c2437.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
---
description: "Learn more about: Compiler Error C2437"
title: "Compiler Error C2437"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C2437"
ms.date: 11/04/2016
f1_keywords: ["C2437"]
helpviewer_keywords: ["C2437"]
ms.assetid: 2d2b3c6c-856a-4b27-ae10-64813b3e5483
---
# Compiler Error C2437

'identifier' : already initialized
> 'identifier' : already initialized

## Remarks

An object can be initialized only once.

The following sample generates C2437:
## Example

The following example generates C2437:

```cpp
// C2437.cpp
Expand Down
13 changes: 8 additions & 5 deletions docs/error-messages/compiler-errors-1/compiler-error-c2438.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
---
description: "Learn more about: Compiler Error C2438"
title: "Compiler Error C2438"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C2438"
ms.date: 11/04/2016
f1_keywords: ["C2438"]
helpviewer_keywords: ["C2438"]
ms.assetid: 3a0ab3ba-d0e4-4d8f-971d-e503397cc827
---
# Compiler Error C2438

'identifier' : cannot initialize static class data via constructor
> 'identifier' : cannot initialize static class data via constructor

## Remarks

A constructor is used to initialize a static member of a class. Static members must be initialized in a definition outside the class declaration.

The following sample generates C2438:
## Example

The following example generates C2438:

```cpp
// C2438.cpp
Expand Down
9 changes: 5 additions & 4 deletions docs/error-messages/compiler-errors-1/compiler-error-c2439.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
---
description: "Learn more about: Compiler Error C2439"
title: "Compiler Error C2439"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C2439"
ms.date: 11/04/2016
f1_keywords: ["C2439"]
helpviewer_keywords: ["C2439"]
ms.assetid: 3c5dbe5c-b7d3-4bb0-8619-92f6e280461e
---
# Compiler Error C2439

'identifier' : member could not be initialized
> 'identifier' : member could not be initialized

## Remarks

A class, structure, or union member cannot be initialized.

Expand Down
24 changes: 12 additions & 12 deletions docs/error-messages/compiler-errors-1/compiler-error-c2440.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ no-loc: ["struct", "const"]
> '*initializing*' : cannot convert from '*type1*' to '*type2*'\
> '*conversion*' : cannot convert from '*type1*' to '*type2*'

The compiler can't implicitly convert from *`type1`* to *`type2`*, or can't use the specified cast or conversion operator.

## Remarks

The compiler can't implicitly convert from *`type1`* to *`type2`*, or can't use the specified cast or conversion operator.

The compiler generates C2440 when it can't convert from one type to another, either implicitly or by using the specified cast or conversion operator. There are many ways to generate this error. We've listed some common ones in the Examples section.

## Examples

### C++ string literals are `const`

C2440 can be caused if you attempt to initialize a non-const `char*` (or `wchar_t*`) by using a string literal in C++ code, when the compiler conformance option [`/Zc:strictStrings`](../../build/reference/zc-strictstrings-disable-string-literal-type-conversion.md) is set. In C, the type of a string literal is array of **`char`**, but in C++, it's array of `const char`. This sample generates C2440:
C2440 can be caused if you attempt to initialize a non-const `char*` (or `wchar_t*`) by using a string literal in C++ code, when the compiler conformance option [`/Zc:strictStrings`](../../build/reference/zc-strictstrings-disable-string-literal-type-conversion.md) is set. In C, the type of a string literal is array of **`char`**, but in C++, it's array of `const char`. This example generates C2440:

```cpp
// C2440s.cpp
Expand All @@ -40,7 +40,7 @@ int main() {

### C++20 `u8` literals are `const char8_t`

In C++20 or under [`/Zc:char8_t`](../../build/reference/zc-char8-t.md), a UTF-8 literal character or string (such as `u8'a'` or `u8"String"`) is of type `const char8_t` or `const char8_t[N]`, respectively. This sample shows how compiler behavior changes between C++17 and C++20:
In C++20 or under [`/Zc:char8_t`](../../build/reference/zc-char8-t.md), a UTF-8 literal character or string (such as `u8'a'` or `u8"String"`) is of type `const char8_t` or `const char8_t[N]`, respectively. This example shows how compiler behavior changes between C++17 and C++20:

```cpp
// C2440u8.cpp
Expand All @@ -60,7 +60,7 @@ int main() {

### Pointer to member

You may see C2440 if you attempt to convert a pointer to member to `void*`. The next sample generates C2440:
You may see C2440 if you attempt to convert a pointer to member to `void*`. The next example generates C2440:

```cpp
// C2440.cpp
Expand All @@ -83,7 +83,7 @@ public:

### Cast of undefined type

The compiler emits C2440 if you attempt to cast from a type that's only forward declared but not defined. This sample generates C2440:
The compiler emits C2440 if you attempt to cast from a type that's only forward declared but not defined. This example generates C2440:

```cpp
// c2440a.cpp
Expand All @@ -98,7 +98,7 @@ Base * func(Derived * d) {

### Incompatible calling convention

The C2440 errors on lines 15 and 16 of the next sample are qualified with the `Incompatible calling conventions for UDT return value` message. A *UDT* is a user-defined type, such as a class, struct, or union. These kinds of incompatibility errors are caused when the calling convention of a UDT specified in the return type of a forward declaration conflicts with the actual calling convention of the UDT and when a function pointer is involved.
The C2440 errors on lines 15 and 16 of the next example are qualified with the `Incompatible calling conventions for UDT return value` message. A *UDT* is a user-defined type, such as a class, struct, or union. These kinds of incompatibility errors are caused when the calling convention of a UDT specified in the return type of a forward declaration conflicts with the actual calling convention of the UDT and when a function pointer is involved.

In the example, first there are forward declarations for a struct and for a function that returns the struct. The compiler assumes that the struct uses the C++ calling convention. Next is the struct definition, which uses the C calling convention by default. Because the compiler doesn't know the calling convention of the struct until it finishes reading the entire struct, the calling convention for the struct in the return type of `get_c2` is also assumed to be C++.

Expand Down Expand Up @@ -163,7 +163,7 @@ int main() {

### User-defined conversions

C2440 can also occur for an incorrect use of a user-defined conversion. For example, when a conversion operator has been defined as **`explicit`**, the compiler can't use it in an implicit conversion. For more information about user-defined conversions, see [User-Defined Conversions (C++/CLI)](../../dotnet/user-defined-conversions-cpp-cli.md)). This sample generates C2440:
C2440 can also occur for an incorrect use of a user-defined conversion. For example, when a conversion operator has been defined as **`explicit`**, the compiler can't use it in an implicit conversion. For more information about user-defined conversions, see [User-Defined Conversions (C++/CLI)](../../dotnet/user-defined-conversions-cpp-cli.md)). This example generates C2440:

```cpp
// C2440d.cpp
Expand All @@ -187,7 +187,7 @@ int main() {

### `System::Array` creation

C2440 can also occur if you try to create an instance of an array in C++/CLI whose type is a <xref:System.Array>. For more information, see [Arrays](../../extensions/arrays-cpp-component-extensions.md). The next sample generates C2440:
C2440 can also occur if you try to create an instance of an array in C++/CLI whose type is a <xref:System.Array>. For more information, see [Arrays](../../extensions/arrays-cpp-component-extensions.md). The next example generates C2440:

```cpp
// C2440e.cpp
Expand All @@ -202,7 +202,7 @@ int main() {

### Attributes

C2440 can also occur because of changes in the attributes feature. The following sample generates C2440.
C2440 can also occur because of changes in the attributes feature. The following example generates C2440.

```cpp
// c2440f.cpp
Expand All @@ -218,7 +218,7 @@ The Microsoft C++ compiler no longer allows the [`const_cast` operator](../../cp

To resolve this C2440, use the correct cast operator. For more information, see [Casting operators](../../cpp/casting-operators.md).

This sample generates C2440:
This example generates C2440:

```cpp
// c2440g.cpp
Expand All @@ -237,7 +237,7 @@ int main() {

C2440 can occur because of conformance changes to the compiler in Visual Studio 2015 Update 3. Previously, the compiler incorrectly treated certain distinct expressions as the same type when identifying a template match for a **`static_cast`** operation. Now the compiler distinguishes the types correctly, and code that relied on the previous **`static_cast`** behavior is broken. To fix this issue, change the template argument to match the template parameter type, or use a **`reinterpret_cast`** or C-style cast.

This sample generates C2440:
This example generates C2440:

```cpp
// c2440h.cpp
Expand Down
7 changes: 3 additions & 4 deletions docs/error-messages/compiler-errors-1/compiler-error-c2441.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
---
description: "Learn more about: Compiler Error C2441"
title: "Compiler Error C2441"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C2441"
ms.date: 11/04/2016
f1_keywords: ["C2441"]
helpviewer_keywords: ["C2441"]
ms.assetid: ffbd6573-777a-48dd-892f-5cf4a758dcab
---
# Compiler Error C2441

Expand All @@ -22,7 +21,7 @@ For more information, see [process](../../cpp/process.md) and [/clr (Common Lang

## Example

The following sample generates C2441.
The following example generates C2441.

```cpp
// C2441.cpp
Expand Down
13 changes: 8 additions & 5 deletions docs/error-messages/compiler-errors-1/compiler-error-c2443.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
---
description: "Learn more about: Compiler Error C2443"
title: "Compiler Error C2443"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C2443"
ms.date: 11/04/2016
f1_keywords: ["C2443"]
helpviewer_keywords: ["C2443"]
ms.assetid: 315330d5-24bc-4193-a531-0642095be58f
---
# Compiler Error C2443

operand size conflict
> operand size conflict

## Remarks

The instruction requires operands to be the same size.

The following sample generates C2443:
## Example

The following example generates C2443:

```cpp
// C2443.cpp
Expand Down
9 changes: 5 additions & 4 deletions docs/error-messages/compiler-errors-1/compiler-error-c2444.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
---
description: "Learn more about: Compiler Error C2444"
title: "Compiler Error C2444"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C2444"
ms.date: 11/04/2016
f1_keywords: ["C2444"]
helpviewer_keywords: ["C2444"]
ms.assetid: 6339ed82-caad-45d3-a8ff-6c746589fd03
---
# Compiler Error C2444

'identifier' : used ANSI prototype, found 'type', expected '{' or ';'
> 'identifier' : used ANSI prototype, found 'type', expected '{' or ';'

## Remarks

The function prototype is followed by a type.

Expand Down
9 changes: 5 additions & 4 deletions docs/error-messages/compiler-errors-1/compiler-error-c2446.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
---
description: "Learn more about: Compiler Error C2446"
title: "Compiler Error C2446"
ms.date: "11/04/2016"
description: "Learn more about: Compiler Error C2446"
ms.date: 11/04/2016
f1_keywords: ["C2446"]
helpviewer_keywords: ["C2446"]
ms.assetid: 4f70dd11-6baf-4b92-9a08-f88f65ffa199
---
# Compiler Error C2446

'operator' : no conversion from 'type1' to 'type2'
> 'operator' : no conversion from 'type1' to 'type2'

## Remarks

The compiler cannot convert `type1` to `type2`. The conversion may not make sense because it violates C/C++ semantics.
Loading