Skip to content

Commit 2f9ac8f

Browse files
authored
Merge pull request #802 from corob-msft/cr-update-c2482
Update for VS2017 version of C2482
2 parents 127bad3 + 38da587 commit 2f9ac8f

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,25 @@ ms.workload: ["cplusplus"]
1414
---
1515
# Compiler Error C2482
1616

17-
>'*identifier*' : dynamic initialization of 'thread' data not allowed
17+
>'*identifier*' : dynamic initialization of 'thread' data not allowed in managed/WinRT code
1818
19-
This error message is obsolete in Visual Studio 2015 and later versions. In previous versions, variables declared by using the `thread` attribute cannot be initialized with an expression that requires run-time evaluation. A static expression is required to initialize `thread` data.
19+
## Remarks
20+
21+
In managed or WinRT code, variables declared by using the [__declspec(thread)](../../cpp/thread.md) storage class modifier attribute or the [thread_local](../../cpp/storage-classes-cpp.md#thread_local) storage class specifier cannot be initialized with an expression that requires evaluation at run-time. A static expression is required to initialize `__declspec(thread)` or `thread_local` data in these runtime environments.
2022

2123
## Example
2224

23-
The following sample generates C2482 in Visual Studio 2013 and earlier:
25+
The following sample generates C2482 in managed (**/clr**) and in WinRT (**/ZW**) code:
2426

2527
```cpp
2628
// C2482.cpp
27-
// compile with: /c
29+
// For managed example, compile with: cl /EHsc /c /clr C2482.cpp
30+
// For WinRT example, compile with: cl /EHsc /c /ZW C2482.cpp
2831
#define Thread __declspec( thread )
29-
Thread int tls_i = tls_i; // C2482
32+
Thread int tls_i1 = tls_i1; // C2482
3033

3134
int j = j; // OK in C++; C error
32-
Thread int tls_i = sizeof( tls_i ); // Okay in C and C++
35+
Thread int tls_i2 = sizeof( tls_i2 ); // Okay in C and C++
3336
```
37+
38+
To fix this issue, initialize thread-local storage by using a constant, **constexpr**, or static expression. Perform any thread-specific initialization separately.

0 commit comments

Comments
 (0)