]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: Improvements to standard error category objects
authorJonathan Wakely <jwakely@redhat.com>
Wed, 22 Sep 2021 12:56:21 +0000 (13:56 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 23 Sep 2021 15:07:38 +0000 (16:07 +0100)
commitdd396a321be5099536af36e64454c1fcf9d67e12
treec51599a9c7c74eb56cd05af63a2c40f9f066cf25
parentce01e2e64c340dadb55a8a24c545a13e654804d4
libstdc++: Improvements to standard error category objects

This ensures that the objects returned by std::generic_category() and
std::system_category() are initialized before any code starts executing,
and are not destroyed at the end of the program. This means it is always
safe to access them, even during startup and termination. See LWG 2992
and P1195R0 for further discussion of this.

Additionally, make the types of those objects final, which might
potentially allow additional devirtualization opportunities. The types
are not visible to users, so there is no way they can derive from them,
so making them final has no semantic change.

Finally, add overrides for equivalent(int, const error_condition&) to
those types, to avoid the second virtual call that would be performed by
the base class definition of the function. Because we know what
default_error_condition(int) does for the derived type, we don't need to
make a virtual call.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:

* src/c++11/system_error.cc (generic_error_category): Define
class and virtual functions as 'final'.
(generic_error_category::equivalent(int, const error_condition&)):
Override.
(system_error_category): Define class and virtual functions as
'final'.
(system_error_category::equivalent(int, const error_condition&)):
Override.
(generic_category_instance, system_category_instance): Use
constinit union to make the objects immortal.
libstdc++-v3/src/c++11/system_error.cc