diff options
author | Adam Cozzette <acozzette@gmail.com> | 2018-06-18 11:38:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-18 11:38:06 -0700 |
commit | 885be9c9828514595f2f1d24c45aec620b739730 (patch) | |
tree | 090287264d31e390bfe5475f87965148c38bdeaf /src | |
parent | b0a8220e92ce7eaccb3042efa123e17b4d0719e9 (diff) |
Work around MSVC issue with std::atomic initialization (#4777)
* Work around MSVC issue with std::atomic initialization
MSVC seems to have a bug where it does not use constant initialization
for std::atomic, which ends up causing crashes during initialization.
This change introduces a workaround by putting the std::atomic inside a
union, which causes the compiler to use constant initialization for it.
* Added an AppVeyor test for static linking with MSVC
Diffstat (limited to 'src')
-rw-r--r-- | src/google/protobuf/generated_message_util.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/google/protobuf/generated_message_util.h b/src/google/protobuf/generated_message_util.h index c26e3e52..706df383 100644 --- a/src/google/protobuf/generated_message_util.h +++ b/src/google/protobuf/generated_message_util.h @@ -335,7 +335,16 @@ struct LIBPROTOBUF_EXPORT SCCInfoBase { kRunning = 1, kUninitialized = -1, // initial state }; +#ifndef _MSC_VER std::atomic<int> visit_status; +#else + // MSVC doesnt make std::atomic constant initialized. This union trick + // makes it so. + union { + int visit_status_to_make_linker_init; + std::atomic<int> visit_status; + }; +#endif int num_deps; void (*init_func)(); // This is followed by an array of num_deps |