[libcxx-commits] [PATCH] D65667: [libcxx] Avoid destructor call for error_category singletons

Hubert Tong via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jun 23 18:09:24 PDT 2022


hubert.reinterpretcast added inline comments.


================
Comment at: libcxx/src/ios.cpp:62
+    _LIBCPP_NO_DESTROY constinit
+    static IostreamErrorHelper s;
+    return s.iostream_error_category;
----------------
cebowleratibm wrote:
> hubert.reinterpretcast wrote:
> > ldionne wrote:
> > > Actually, since those are `constinit`, I think we could even define them at file scope and skip the function-local static. Thoughts?
> > That makes sense. It does have an advantage in cases where `_LIBCPP_NO_DESTROY` is not effective.
> If `_LIBCPP_NO_DESTROY` is not effective, doesn't that mean that the user will pay the startup to register the atexit destruction, even if the category singleton is never used?  I think the benefit of the static local remains: that you're not paying for it unless it's used.  If `_LIBCPP_NO_DESTROY` is supported then there's no benefit to using static locals.  Are we ok imposing the load time cost when the library is built without `_LIBCPP_NO_DESTROY` support?
It's a trade-off between one-time startup cost versus dealing with the guard for every call.


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