Skip to content

Commit

Permalink
Give basic_memory_buffer allocator [[no_unique_address]]
Browse files Browse the repository at this point in the history
This allows stateless allocators to take up no space while still avoiding the empty base class optimization.
  • Loading branch information
Minty-Meeo committed Jun 13, 2023
1 parent de0757b commit 5419877
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@
# 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__)
# define FMT_VISIBILITY(value) __attribute__((visibility(value)))
#else
Expand Down Expand Up @@ -920,7 +932,7 @@ class basic_memory_buffer final : public detail::buffer<T> {
T store_[SIZE];

// 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.
FMT_CONSTEXPR20 void deallocate() {
Expand Down

0 comments on commit 5419877

Please sign in to comment.