-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Give basic_memory_buffer allocator [[no_unique_address]] #3485
Conversation
Following the advice from https://devblogs.microsoft.com/cppblog/msvc-cpp20-and-the-std-cpp20-switch/ on how to use [[msvc::no_unique_address]]. Attempting to use it in standards prior to C++20 works, but emits a warning, so I opted to only enable this when FMT_CPLUSPLUS >= 202002L. Alternatively, a pragma warning disable for MSVC can be put around the allocator for basic_memory_buffer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR
include/fmt/core.h
Outdated
#ifndef FMT_NO_UNIQUE_ADDRESS | ||
# if FMT_HAS_CPP20_ATTRIBUTE(no_unique_address) | ||
# define FMT_NO_UNIQUE_ADDRESS [[no_unique_address]] | ||
# elif FMT_MSC_VERSION >= 1929 && FMT_CPLUSPLUS >= 202002L // VS2019 v16.10 and later | ||
# define FMT_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] | ||
# else | ||
# define FMT_NO_UNIQUE_ADDRESS | ||
# endif | ||
#endif | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move to format.h
where it is used.
include/fmt/core.h
Outdated
#define FMT_HAS_CPP20_ATTRIBUTE(attribute) \ | ||
(FMT_CPLUSPLUS >= 202002L && FMT_HAS_CPP_ATTRIBUTE(attribute)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this for a single check esp. since MSVC requires special handling. Let's just inline in the call site.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it not be better to create this feature now, in the event that the other C++20 attributes (likely, unlikely) are desired in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is little value in these variations of FMT_HAS_CPP_ATTRIBUTE
so let's just inline.
This allows stateless allocators to take up no space while still avoiding the empty base class optimization.
96054f4
to
5419877
Compare
Thanks |
This allows stateless allocators to take up no space while still avoiding the empty base class optimization.