[libcxx-commits] [PATCH] D65667: [libcxx] Avoid destructor call for error_category singletons
Chris Bowler via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Mon May 2 14:04:28 PDT 2022
cebowleratibm added inline comments.
================
Comment at: libcxx/src/future.cpp:65
{
- static __future_error_category __f;
- return __f;
+#if defined(_LIBCPP_ERROR_CATEGORY_DEFINE_LEGACY_INLINE_FUNCTIONS)
+ union FutureErrorHelper {
----------------
ldionne wrote:
> Is there a reason why you can't simply use the `#else` branch all the time, and never define `_LIBCPP_ERROR_CATEGORY_DEFINE_LEGACY_INLINE_FUNCTIONS` in this translation unit (the same applies to other changes)?
>
> My memory is blurry from being on vacation, but I think the intent of my D123519 was that you could always assume that `error_category` is `constexpr` friendly when building the library.
If that is the case then I think I'm misunderstanding how things work.
>From __config:
```
#elif _LIBCPP_ABI_VERSION == 1
# if !defined(_LIBCPP_OBJECT_FORMAT_COFF)
// Enable compiling copies of now inline methods into the dylib to support
// applications compiled against older libraries. This is unnecessary with
// COFF dllexport semantics, since dllexport forces a non-inline definition
// of inline functions to be emitted anyway. Our own non-inline copy would
// conflict with the dllexport-emitted copy, so we disable it.
# define _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS
# endif
```
so there are at least some library builds that will define `_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS`, and when it is, the definition of error_category will not have a constexpr constructor:
```
class _LIBCPP_TYPE_VIS error_category
{
public:
virtual ~error_category() _NOEXCEPT;
#if defined(_LIBCPP_ERROR_CATEGORY_DEFINE_LEGACY_INLINE_FUNCTIONS)
error_category() noexcept;
#else
_LIBCPP_INLINE_VISIBILITY
_LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT = default;
#endif
```
So the #if / #else I added are meant to be symmetric to the #if / #else in the error_category definition.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D65667/new/
https://reviews.llvm.org/D65667
More information about the libcxx-commits
mailing list