summaryrefslogtreecommitdiff
path: root/absl/base
diff options
context:
space:
mode:
authorGravatar Derek Mauro <dmauro@google.com>2023-03-23 10:12:38 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2023-03-23 10:13:24 -0700
commitb6de7b80325514018d38de2c4dee1254258c4b31 (patch)
tree7bf4b7050a7665a151608a969c3c80fda8d3e686 /absl/base
parent0a1e03a5f664fc8e2ab88cf2035b34fef651105a (diff)
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
Diffstat (limited to 'absl/base')
-rw-r--r--absl/base/attributes.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/absl/base/attributes.h b/absl/base/attributes.h
index 91bf954b..a6572d08 100644
--- a/absl/base/attributes.h
+++ b/absl/base/attributes.h
@@ -787,7 +787,15 @@
// 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
// 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]]
#else
#define ABSL_ATTRIBUTE_NO_UNIQUE_ADDRESS