Skip to content

Commit be4a530

Browse files
authored
Merge pull request #1798 from corob-msft/cr-c2131
Add C2131 for DevDiv bug 803789
2 parents c2d6535 + 18b3162 commit be4a530

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@
232232
## [Compiler Error C2128](compiler-error-c2128.md)
233233
## [Compiler Error C2129](compiler-error-c2129.md)
234234
## [Compiler Error C2130](compiler-error-c2130.md)
235+
## [Compiler Error C2131](compiler-error-c2131.md)
235236
## [Compiler Error C2132](compiler-error-c2132.md)
236237
## [Compiler Error C2133](compiler-error-c2133.md)
237238
## [Compiler Error C2134](compiler-error-c2134.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: "Compiler Error C2131"
3+
ms.date: "02/28/2019"
4+
f1_keywords: ["C2131"]
5+
helpviewer_keywords: ["C2131"]
6+
---
7+
# Compiler Error C2131
8+
9+
> expression did not evaluate to a constant
10+
11+
An expression declared as **const** or **constexpr** didn't evaluate to a constant at compile time. The compiler must be able to determine the value of the expression at the point it's used.
12+
13+
## Example
14+
15+
This example shows a way to cause error C2131, and how to fix it.
16+
17+
```cpp
18+
// c2131.cpp
19+
// compile by using: cl /EHsc /W4 /c c2131.cpp
20+
21+
struct test
22+
{
23+
static const int array_size; // To fix, init array_size here.
24+
int size_array[array_size]; // C2131
25+
};
26+
27+
const int test::array_size = 42;
28+
```
29+
30+
```Output
31+
c2131.cpp
32+
c2131.cpp(7): error C2131: expression did not evaluate to a constant
33+
c2131.cpp(7): note: failure was caused by non-constant arguments or reference to a non-constant symbol
34+
c2131.cpp(7): note: see usage of 'array_size'
35+
```
36+
37+
## See also
38+
39+
[const](../../cpp/const-cpp.md)<br/>
40+
[constexpr](../../cpp/constexpr-cpp.md)<br/>

docs/error-messages/compiler-errors-1/compiler-errors-c2100-through-c2199.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Compiler Errors C2100 through C2199"
33
ms.date: "11/17/2017"
4-
f1_keywords: ["C2119", "C2123", "C2125", "C2126", "C2127", "C2131", "C2136", "C2176", "C2187", "C2189"]
4+
f1_keywords: ["C2119", "C2123", "C2125", "C2126", "C2127", "C2136", "C2176", "C2187", "C2189"]
55
helpviewer_keywords: ["C2119", "C2123", "C2125", "C2126", "C2127", "C2131", "C2136", "C2176", "C2187", "C2189"]
66
ms.assetid: 1ccab076-0954-4386-b959-d3112a6793ae
77
---
@@ -46,7 +46,7 @@ The articles in this section of the documentation explain a subset of the error
4646
|[Compiler Error C2128](compiler-error-c2128.md)|'*function*': alloc_text/same_seg applicable only to functions with C linkage|
4747
|[Compiler Error C2129](compiler-error-c2129.md)|static function '*identifier*' declared but not defined|
4848
|[Compiler Error C2130](compiler-error-c2130.md)|#line expected a string containing the filename, found '*token*'|
49-
|Compiler Error C2131|expression did not evaluate to a constant|
49+
|[Compiler Error C2131](compiler-error-c2131.md)|expression did not evaluate to a constant|
5050
|[Compiler Error C2132](compiler-error-c2132.md)|syntax error: unexpected identifier|
5151
|[Compiler Error C2133](compiler-error-c2133.md)|'*identifier*': unknown size|
5252
|[Compiler Error C2134](compiler-error-c2134.md)|'*function*': call does not result in a constant expression|

0 commit comments

Comments
 (0)