Commit b6de7b80 by Derek Mauro Committed by Copybara-Service

Make `ABSL_ATTRIBUTE_NO_UNIQUE_ADDRESS` work on MSVC

https://devblogs.microsoft.com/cppblog/msvc-cpp20-and-the-std-cpp20-switch/#c20-no_unique_address
MSVC disables [[no_unique_address]] by default because of ABI
compatibility. Since Abseil does not claim ABI compatibility in
mixed-mode builds, we can offer it unconditionally.

Fixes #1418

PiperOrigin-RevId: 518894036
Change-Id: If7653e65703b335783f11d296de7e32fc35d4fc6
parent 0a1e03a5
...@@ -787,7 +787,15 @@ ...@@ -787,7 +787,15 @@
// For code that is assured to only build with C++20 or later, prefer using // For code that is assured to only build with C++20 or later, prefer using
// the standard attribute `[[no_unique_address]]` directly instead of this // the standard attribute `[[no_unique_address]]` directly instead of this
// macro. // macro.
#if ABSL_HAVE_CPP_ATTRIBUTE(no_unique_address) //
// https://devblogs.microsoft.com/cppblog/msvc-cpp20-and-the-std-cpp20-switch/#c20-no_unique_address
// Current versions of MSVC have disabled `[[no_unique_address]]` since it
// breaks ABI compatibility, but offers `[[msvc::no_unique_address]]` for
// situations when it can be assured that it is desired. Since Abseil does not
// claim ABI compatibility in mixed builds, we can offer it unconditionally.
#if defined(_MSC_VER) && _MSC_VER >= 1929
#define ABSL_ATTRIBUTE_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
#elif ABSL_HAVE_CPP_ATTRIBUTE(no_unique_address)
#define ABSL_ATTRIBUTE_NO_UNIQUE_ADDRESS [[no_unique_address]] #define ABSL_ATTRIBUTE_NO_UNIQUE_ADDRESS [[no_unique_address]]
#else #else
#define ABSL_ATTRIBUTE_NO_UNIQUE_ADDRESS #define ABSL_ATTRIBUTE_NO_UNIQUE_ADDRESS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment