[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
Tue Mar 29 07:14:06 PDT 2022


cebowleratibm added a comment.
Herald added a project: All.

I was writing a revision of this patch but hit a problem:

  class _LIBCPP_TYPE_VIS error_category
  {
  public:
      virtual ~error_category() _NOEXCEPT;
  
  #if defined(_LIBCPP_BUILDING_LIBRARY) && \
      defined(_LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS)
      error_category() _NOEXCEPT;
  #else
      _LIBCPP_INLINE_VISIBILITY
      _LIBCPP_CONSTEXPR_AFTER_CXX11 error_category() _NOEXCEPT = default;
  #endif
  ...

When _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS is defined the non-constexpr error_category constructor causes a problem with the _LIBCPP_CONSTINIT singleton objects:

  llvm-project/libcxx/src/ios.cpp:59:25: error: constexpr constructor never produces a constant expression [-Winvalid-constexpr]
       constexpr explicit IostreamErrorHelper()

It seems we would need a new CONSTINIT macro that doesn't get defined when _LIBCPP_DEPRECATED_ABI_LEGACY_LIBRARY_DEFINITIONS_FOR_INLINE_FUNCTIONS is defined and when libc++ is stuck on these legacy definitions then the singleton ctor calls can't be bypassed.  It's a shame given that we know the constructor doesn't do anything meaningful.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65667/new/

https://reviews.llvm.org/D65667



More information about the libcxx-commits mailing list