public inbox for libstdc++-cvs@sourceware.org help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-6265] libstdc++: Improvements to standard error category objects (part deux) Date: Wed, 5 Jan 2022 15:29:43 +0000 (GMT) [thread overview] Message-ID: <20220105152943.9D739385842E@sourceware.org> (raw) https://gcc.gnu.org/g:096228d84e9238d97fe115623126373f5b67bdc1 commit r12-6265-g096228d84e9238d97fe115623126373f5b67bdc1 Author: Jonathan Wakely <jwakely@redhat.com> Date: Wed Sep 22 13:56:21 2021 +0100 libstdc++: Improvements to standard error category objects (part deux) In r12-3860 the error categories in <system_error> were made final and immortal, but I missed the categories for <future> and <ios>. This makes the same changes to those. libstdc++-v3/ChangeLog: * src/c++11/cxx11-ios_failure.cc (io_error_category): Define class and virtual functions as 'final'. (io_category_instance): Use constinit union to make the object immortal. * src/c++11/future.cc (future_error_category): Define class and virtual functions as 'final'. (future_category_instance): Use constinit union. Diff: --- libstdc++-v3/src/c++11/cxx11-ios_failure.cc | 25 +++++++++++++++---------- libstdc++-v3/src/c++11/future.cc | 26 ++++++++++++++++---------- 2 files changed, 31 insertions(+), 20 deletions(-) diff --git a/libstdc++-v3/src/c++11/cxx11-ios_failure.cc b/libstdc++-v3/src/c++11/cxx11-ios_failure.cc index 5a151b6ec5c..ba4b1413bf9 100644 --- a/libstdc++-v3/src/c++11/cxx11-ios_failure.cc +++ b/libstdc++-v3/src/c++11/cxx11-ios_failure.cc @@ -44,14 +44,15 @@ namespace { - struct io_error_category : std::error_category + struct io_error_category final : std::error_category { - virtual const char* - name() const noexcept + const char* + name() const noexcept final { return "iostream"; } _GLIBCXX_DEFAULT_ABI_TAG - virtual std::string message(int __ec) const + std::string + message(int __ec) const final { std::string __msg; switch (std::io_errc(__ec)) @@ -67,13 +68,17 @@ namespace } }; - const io_error_category& - __io_category_instance() noexcept + struct constant_init { - static const io_error_category __ec{}; - return __ec; - } + union { + unsigned char unused; + io_error_category cat; + }; + constexpr constant_init() : cat() { } + ~constant_init() { /* do nothing, union member is not destroyed */ } + }; + __constinit constant_init io_category_instance{}; } // namespace namespace std _GLIBCXX_VISIBILITY(default) @@ -82,7 +87,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION const error_category& iostream_category() noexcept - { return __io_category_instance(); } + { return io_category_instance.cat; } ios_base::failure::failure(const string& __str) : system_error(io_errc::stream, __str) { } diff --git a/libstdc++-v3/src/c++11/future.cc b/libstdc++-v3/src/c++11/future.cc index c5423931eb3..488ff17a1e6 100644 --- a/libstdc++-v3/src/c++11/future.cc +++ b/libstdc++-v3/src/c++11/future.cc @@ -27,14 +27,15 @@ namespace { - struct future_error_category : public std::error_category + struct future_error_category final : public std::error_category { - virtual const char* - name() const noexcept + const char* + name() const noexcept final { return "future"; } _GLIBCXX_DEFAULT_ABI_TAG - virtual std::string message(int __ec) const + std::string + message(int __ec) const final { std::string __msg; switch (std::future_errc(__ec)) @@ -59,12 +60,17 @@ namespace } }; - const future_error_category& - __future_category_instance() noexcept + struct constant_init { - static const future_error_category __fec{}; - return __fec; - } + union { + unsigned char unused; + future_error_category cat; + }; + constexpr constant_init() : cat() { } + ~constant_init() { /* do nothing, union member is not destroyed */ } + }; + + __constinit constant_init future_category_instance{}; } namespace std _GLIBCXX_VISIBILITY(default) @@ -76,7 +82,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { _GLIBCXX_THROW_OR_ABORT(future_error(make_error_code(future_errc(__i)))); } const error_category& future_category() noexcept - { return __future_category_instance(); } + { return future_category_instance.cat; } future_error::~future_error() noexcept { }
reply other threads:[~2022-01-05 15:29 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220105152943.9D739385842E@sourceware.org \ --to=redi@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ --cc=libstdc++-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).