Give basic_memory_buffer allocator [[no_unique_address]] (#3485)

This allows stateless allocators to take up no space while still avoiding the empty base class optimization.
This commit is contained in:
Minty-Meeo
2023-06-13 03:22:19 -05:00
committed by GitHub
parent 5dbe0ff954
commit c86fe0b8d3

View File

@ -79,6 +79,18 @@
# endif # endif
#endif #endif
#ifndef FMT_NO_UNIQUE_ADDRESS
# if FMT_CPLUSPLUS >= 202002L
# if FMT_HAS_CPP_ATTRIBUTE(no_unique_address)
# define FMT_NO_UNIQUE_ADDRESS [[no_unique_address]]
# elif FMT_MSC_VERSION >= 1929 // VS2019 v16.10 and later
# define FMT_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
# endif
# else
# define FMT_NO_UNIQUE_ADDRESS
# endif
#endif
#if FMT_GCC_VERSION || defined(__clang__) #if FMT_GCC_VERSION || defined(__clang__)
# define FMT_VISIBILITY(value) __attribute__((visibility(value))) # define FMT_VISIBILITY(value) __attribute__((visibility(value)))
#else #else
@ -920,7 +932,7 @@ class basic_memory_buffer final : public detail::buffer<T> {
T store_[SIZE]; T store_[SIZE];
// Don't inherit from Allocator avoid generating type_info for it. // Don't inherit from Allocator avoid generating type_info for it.
Allocator alloc_; FMT_NO_UNIQUE_ADDRESS Allocator alloc_;
// Deallocate memory allocated by the buffer. // Deallocate memory allocated by the buffer.
FMT_CONSTEXPR20 void deallocate() { FMT_CONSTEXPR20 void deallocate() {