Skip to content

Add possible workaround to compiler-error-c2603.md #44

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

Closed
wants to merge 4 commits into from
Closed
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
30 changes: 29 additions & 1 deletion docs/error-messages/compiler-errors-2/compiler-error-c2603.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,32 @@ extern inline void f1() {
static C C17,C18,C19,C20,C21,C22,C23,C24,C25,C26,C27,C28,C29,C30,C31,C32;
static C C33; // C2603 Comment this line out to avoid error
}
```
```

### Possible workarounds:

*Visual Studio 2013:*

In Visual Studio 2013, if you require the statics to be accessible within their block scope, one potential way to avoid this issue may be to enclose the statics in a lambda that is immediately invoked.

For example:

```
struct C { C() {} };
extern inline void f1() {
[&]() {
static C C1,C2,C3,C4,C5,C6,C7,C8,C9,C10,C11,C12,C14,C15,C16;
static C C17,C18,C19,C20,C21,C22,C23,C24,C25,C26,C27,C28,C29,C30,C31,C32;
static C C33;
}();
}
```

*Visual Studio 2015 and newer:*

In C++11, a static local variable initialization is guaranteed to be thread-safe; a feature sometimes called "magic statics". This is the default starting with Visual Studio 2015. The thread-safe statics feature can be disabled by using the /Zc:threadSafeInit- compiler flag.

One potential cause for this error in Visual Studio 2015 and newer versions is the disabling of thread safe static initialization via the /Zc:threadSafeInit- compiler flag. If you are encountering this error, consider whether or not this flag is necessary for your application, and remove it if possible.