Skip to content

Commit ca335d0

Browse files
Merge pull request #5589 from Rageking8/structure-error-references-in-range-c2431-c2460
Structure error references in range [C2431, C2460]
2 parents eef9a97 + 1ca65a6 commit ca335d0

24 files changed

+163
-114
lines changed

docs/error-messages/compiler-errors-1/compiler-error-c2431.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
---
2-
description: "Learn more about: Compiler Error C2431"
32
title: "Compiler Error C2431"
4-
ms.date: "11/04/2016"
3+
description: "Learn more about: Compiler Error C2431"
4+
ms.date: 11/04/2016
55
f1_keywords: ["C2431"]
66
helpviewer_keywords: ["C2431"]
7-
ms.assetid: 88a5b648-c89f-47d1-a20e-63231ab4f0f7
87
---
98
# Compiler Error C2431
109

11-
illegal index register in 'identifier'
10+
> illegal index register in 'identifier'
11+
12+
## Remarks
1213

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

15-
The following sample generates C2431:
16+
## Example
17+
18+
The following example generates C2431:
1619

1720
```cpp
1821
// C2431.cpp

docs/error-messages/compiler-errors-1/compiler-error-c2432.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
---
2-
description: "Learn more about: Compiler Error C2432"
32
title: "Compiler Error C2432"
4-
ms.date: "11/04/2016"
3+
description: "Learn more about: Compiler Error C2432"
4+
ms.date: 11/04/2016
55
f1_keywords: ["C2432"]
66
helpviewer_keywords: ["C2432"]
7-
ms.assetid: 0e3326e8-cab1-45a5-b48d-61edd33793e8
87
---
98
# Compiler Error C2432
109

11-
illegal reference to 16-bit data in 'identifier'
10+
> illegal reference to 16-bit data in 'identifier'
11+
12+
## Remarks
1213

1314
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.
1415

15-
The following sample generates C2432:
16+
## Example
17+
18+
The following example generates C2432:
1619

1720
```cpp
1821
// C2432.cpp

docs/error-messages/compiler-errors-1/compiler-error-c2433.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ helpviewer_keywords: ["C2433"]
99

1010
> '*identifier*': '*modifier*' not permitted on data declarations
1111
12+
## Remarks
13+
1214
The **`friend`**, **`virtual`**, and **`inline`** modifiers cannot be used for data declarations.
1315

1416
## Example

docs/error-messages/compiler-errors-1/compiler-error-c2434.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
---
2-
description: "Learn more about: Compiler Error C2434"
32
title: "Compiler Error C2434"
4-
ms.date: "11/04/2016"
3+
description: "Learn more about: Compiler Error C2434"
4+
ms.date: 11/04/2016
55
f1_keywords: ["C2434"]
66
helpviewer_keywords: ["C2434"]
7-
ms.assetid: 01329e26-7c74-4219-b74f-69e3a40c9738
87
---
98
# Compiler Error C2434
109

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

1918
## Example
2019

21-
The following sample generates C2434. To fix this issue, use constants to initialize `process` variables.
20+
The following example generates C2434. To fix this issue, use constants to initialize `process` variables.
2221

2322
```cpp
2423
// C2434.cpp

docs/error-messages/compiler-errors-1/compiler-error-c2435.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
---
2-
description: "Learn more about: Compiler Error C2435"
32
title: "Compiler Error C2435"
4-
ms.date: "11/04/2016"
3+
description: "Learn more about: Compiler Error C2435"
4+
ms.date: 11/04/2016
55
f1_keywords: ["C2435"]
66
helpviewer_keywords: ["C2435"]
7-
ms.assetid: be6aa8f8-579b-42ea-bdd8-2d01393646ad
87
---
98
# Compiler Error C2435
109

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

2120
## Example
2221

23-
The following sample generates C2435:
22+
The following example generates C2435:
2423

2524
```cpp
2625
// C2435.cpp

docs/error-messages/compiler-errors-1/compiler-error-c2436.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
---
2-
description: "Learn more about: Compiler Error C2436"
32
title: "Compiler Error C2436"
4-
ms.date: "11/04/2016"
3+
description: "Learn more about: Compiler Error C2436"
4+
ms.date: 11/04/2016
55
f1_keywords: ["C2436"]
66
helpviewer_keywords: ["C2436"]
7-
ms.assetid: ca4cc813-bc1d-4c0a-9a2c-3a5fe673d084
87
---
98
# Compiler Error C2436
109

11-
'identifier' : member function or nested class in constructor initializer list
10+
> 'identifier' : member function or nested class in constructor initializer list
11+
12+
## Remarks
1213

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

15-
The following sample generates C2436:
16+
## Example
17+
18+
The following example generates C2436:
1619

1720
```cpp
1821
// C2436.cpp

docs/error-messages/compiler-errors-1/compiler-error-c2437.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
---
2-
description: "Learn more about: Compiler Error C2437"
32
title: "Compiler Error C2437"
4-
ms.date: "11/04/2016"
3+
description: "Learn more about: Compiler Error C2437"
4+
ms.date: 11/04/2016
55
f1_keywords: ["C2437"]
66
helpviewer_keywords: ["C2437"]
7-
ms.assetid: 2d2b3c6c-856a-4b27-ae10-64813b3e5483
87
---
98
# Compiler Error C2437
109

11-
'identifier' : already initialized
10+
> 'identifier' : already initialized
11+
12+
## Remarks
1213

1314
An object can be initialized only once.
1415

15-
The following sample generates C2437:
16+
## Example
17+
18+
The following example generates C2437:
1619

1720
```cpp
1821
// C2437.cpp

docs/error-messages/compiler-errors-1/compiler-error-c2438.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
---
2-
description: "Learn more about: Compiler Error C2438"
32
title: "Compiler Error C2438"
4-
ms.date: "11/04/2016"
3+
description: "Learn more about: Compiler Error C2438"
4+
ms.date: 11/04/2016
55
f1_keywords: ["C2438"]
66
helpviewer_keywords: ["C2438"]
7-
ms.assetid: 3a0ab3ba-d0e4-4d8f-971d-e503397cc827
87
---
98
# Compiler Error C2438
109

11-
'identifier' : cannot initialize static class data via constructor
10+
> 'identifier' : cannot initialize static class data via constructor
11+
12+
## Remarks
1213

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

15-
The following sample generates C2438:
16+
## Example
17+
18+
The following example generates C2438:
1619

1720
```cpp
1821
// C2438.cpp

docs/error-messages/compiler-errors-1/compiler-error-c2439.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
---
2-
description: "Learn more about: Compiler Error C2439"
32
title: "Compiler Error C2439"
4-
ms.date: "11/04/2016"
3+
description: "Learn more about: Compiler Error C2439"
4+
ms.date: 11/04/2016
55
f1_keywords: ["C2439"]
66
helpviewer_keywords: ["C2439"]
7-
ms.assetid: 3c5dbe5c-b7d3-4bb0-8619-92f6e280461e
87
---
98
# Compiler Error C2439
109

11-
'identifier' : member could not be initialized
10+
> 'identifier' : member could not be initialized
11+
12+
## Remarks
1213

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

docs/error-messages/compiler-errors-1/compiler-error-c2440.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ no-loc: ["struct", "const"]
1111
> '*initializing*' : cannot convert from '*type1*' to '*type2*'\
1212
> '*conversion*' : cannot convert from '*type1*' to '*type2*'
1313
14-
The compiler can't implicitly convert from *`type1`* to *`type2`*, or can't use the specified cast or conversion operator.
15-
1614
## Remarks
1715

16+
The compiler can't implicitly convert from *`type1`* to *`type2`*, or can't use the specified cast or conversion operator.
17+
1818
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.
1919

2020
## Examples
2121

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

24-
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:
24+
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:
2525

2626
```cpp
2727
// C2440s.cpp
@@ -40,7 +40,7 @@ int main() {
4040

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

43-
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:
43+
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:
4444

4545
```cpp
4646
// C2440u8.cpp
@@ -60,7 +60,7 @@ int main() {
6060

6161
### Pointer to member
6262

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

6565
```cpp
6666
// C2440.cpp
@@ -83,7 +83,7 @@ public:
8383
8484
### Cast of undefined type
8585
86-
The compiler emits C2440 if you attempt to cast from a type that's only forward declared but not defined. This sample generates C2440:
86+
The compiler emits C2440 if you attempt to cast from a type that's only forward declared but not defined. This example generates C2440:
8787
8888
```cpp
8989
// c2440a.cpp
@@ -98,7 +98,7 @@ Base * func(Derived * d) {
9898

9999
### Incompatible calling convention
100100

101-
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.
101+
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.
102102

103103
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++.
104104

@@ -163,7 +163,7 @@ int main() {
163163

164164
### User-defined conversions
165165

166-
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:
166+
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:
167167

168168
```cpp
169169
// C2440d.cpp
@@ -187,7 +187,7 @@ int main() {
187187
188188
### `System::Array` creation
189189
190-
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:
190+
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:
191191
192192
```cpp
193193
// C2440e.cpp
@@ -202,7 +202,7 @@ int main() {
202202

203203
### Attributes
204204

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

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

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

221-
This sample generates C2440:
221+
This example generates C2440:
222222

223223
```cpp
224224
// c2440g.cpp
@@ -237,7 +237,7 @@ int main() {
237237
238238
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.
239239
240-
This sample generates C2440:
240+
This example generates C2440:
241241
242242
```cpp
243243
// c2440h.cpp

0 commit comments

Comments
 (0)