abseil-cpp
abseil-cpp copied to clipboard
Does not compile on windows (MSVC)
As known, (see https://github.com/abseil/abseil-cpp/blob/master/absl/base/internal/atomic_hook.h#L139, https://github.com/abseil/abseil-cpp/issues/659, etc.), MSVC does not provide a constinit std::atomic<T*>.
But, both https://github.com/abseil/abseil-cpp/blob/master/absl/strings/internal/cordz_handle.cc#L27 and https://github.com/abseil/abseil-cpp/blob/master/absl/strings/internal/cordz_info.cc#L41 attempt to define a ABSL_CONST_INIT object which contain a std::atomic (https://github.com/abseil/abseil-cpp/blob/master/absl/strings/internal/cordz_handle.h#L90, https://github.com/abseil/abseil-cpp/blob/master/absl/strings/internal/cordz_info.h#L196).
This makes absl not compilable with the latest MSVC.
I see a macro ABSL_INTERNAL_CORDZ_ENABLED https://github.com/abseil/abseil-cpp/blob/72ec15a317a74cccf03a62f749f3ab28206be069/absl/strings/internal/cordz_functions.h#L47, which is false for MSVC; does this mean cordz_info and cordz_handle are not even needed, as a simple 'fix'? Or do we need a different workaround?
absl\strings\internal\cordz_info.cc:41:44: error: variable does not have a constant initializer
ABSL_CONST_INIT CordzInfo::List CordzInfo::global_list_{absl::kConstInit};
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
absl\strings\internal\cordz_info.cc:41:1: note: required by 'require_constant_initialization' attribute here
ABSL_CONST_INIT CordzInfo::List CordzInfo::global_list_{absl::kConstInit};
^~~~~~~~~~~~~~~
absl/base/attributes.h:714:27: note: expanded from macro 'ABSL_CONST_INIT'
#define ABSL_CONST_INIT [[clang::require_constant_initialization]]
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...xxatomic:207:21: note: cast that performs the conversions of a reinterpret_cast is not allowed in a constant expression
: _Atomic_address{(_ATOMIC_UINT)_Right}
^
abseil-cpp\absl/strings/internal/cordz_info.h:196:56: note: in call to 'atomic(nullptr)'
std::atomic<CordzInfo*> head ABSL_GUARDED_BY(mutex){nullptr};
Please completely fill out the bug report form: https://github.com/abseil/abseil-cpp/blob/master/.github/ISSUE_TEMPLATE/00-bug_report.md
There is a good reason why we ask for this. I don't doubt anything you wrote, but our MSVC build is working. I have a feeling that you are actually using clang-cl, not MSVC.
Sorry yes; it will take me a bit to untangle a reproducible command, this is from deep within some CI.
However, it seems like the same concept as https://github.com/abseil/abseil-cpp/issues/659 (which you also helped fix 😄 ); seems like if #659 was causing compilation errors, this must too for the same reason?
(edit: accidentally clicked "close and comment" instead of "comment", sorry for the noise)
I have the same issue with clang-cl v15 when compiling e.g. absl/container/internal/raw_hash_set_test.cc:
In file included from absl/container/internal/raw_hash_set_test.cc:51:
In file included from .\absl/log/log.h:190:
In file included from .\absl/log/internal/log_impl.h:19:
In file included from .\absl/log/internal/log_message.h:40:
.\absl/log/internal/nullguard.h(37,10): error: an attribute list cannot appear here
ABSL_DLL ABSL_CONST_INIT extern const std::array<char, 7> kCharNull;
^~~~~~~~~~~~~~~
.\absl/base/attributes.h(714,25): note: expanded from macro 'ABSL_CONST_INIT'
#define ABSL_CONST_INIT [[clang::require_constant_initialization]]
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from absl/container/internal/raw_hash_set_test.cc:51:
In file included from .\absl/log/log.h:190:
In file included from .\absl/log/internal/log_impl.h:19:
In file included from .\absl/log/internal/log_message.h:40:
.\absl/log/internal/nullguard.h(38,10): error: an attribute list cannot appear here
ABSL_DLL ABSL_CONST_INIT extern const std::array<signed char, 7>
^~~~~~~~~~~~~~~
.\absl/base/attributes.h(714,25): note: expanded from macro 'ABSL_CONST_INIT'
#define ABSL_CONST_INIT [[clang::require_constant_initialization]]
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from absl/container/internal/raw_hash_set_test.cc:51:
In file included from .\absl/log/log.h:190:
In file included from .\absl/log/internal/log_impl.h:19:
In file included from .\absl/log/internal/log_message.h:40:
.\absl/log/internal/nullguard.h(40,10): error: an attribute list cannot appear here
ABSL_DLL ABSL_CONST_INIT extern const std::array<unsigned char, 7>
^~~~~~~~~~~~~~~
.\absl/base/attributes.h(714,25): note: expanded from macro 'ABSL_CONST_INIT'
#define ABSL_CONST_INIT [[clang::require_constant_initialization]]
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 errors generated.
Since I have -DABSL_CONSUME_DLL in my CFLAGS, the 1st error above expands to:
namespace log_internal
{
__declspec (dllimport) [[clang::require_constant_initialization]] extern const std::array<char, 7> kCharNull;
@gvanem - I think this is a different issue.
I think the code just needs to change from ABSL_DLL ABSL_CONST_INIT to ABSL_CONST_INIT ABSL_DLL. I will make that change.