libstdc++: Implement P1328 "Making std::type_info::operator== constexpr"
authorJonathan Wakely <jwakely@redhat.com>
Wed, 5 Jan 2022 14:25:37 +0000 (14:25 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Wed, 5 Jan 2022 14:43:01 +0000 (14:43 +0000)
commit3633cc54284450433b81f0340483e15df1a49a3c
tree8999cf5da81331352168bc23b5c930a1e90822d0
parent096228d84e9238d97fe115623126373f5b67bdc1
libstdc++: Implement P1328 "Making std::type_info::operator== constexpr"

This feature is present in the C++23 draft.

With Jakub's recent front-end changes we can implement constexpr
equality by comparing the addresses of std::type_info objects. We do not
need string comparisons, because for constant evaluation cases we know
we aren't dealing with std::type_info objects defined in other
translation units.

The ARM EABI requires that the type_info::operator== function can be
defined out-of-line (and suggests that should be the default), but to be
a constexpr function it must be defined inline (at least for C++23
mode). To meet these conflicting requirements we make the inline version
of operator== call a new __equal function when called at runtime. That
is an alias for the non-inline definition of operator== defined in
libsupc++.

libstdc++-v3/ChangeLog:

* config/abi/pre/gnu.ver (GLIBCXX_3.4.30): Export new symbol for
ARM EABI.
* include/bits/c++config (_GLIBCXX23_CONSTEXPR): Define.
* include/std/version (__cpp_lib_constexpr_typeinfo): Define.
* libsupc++/tinfo.cc: Add #error to ensure non-inline definition
is emitted.
(type_info::__equal): Define alias symbol.
* libsupc++/typeinfo (type_info::before): Combine different
implementations into one.
(type_info::operator==): Likewise. Use address equality for
constant evaluation. Call __equal for targets that require the
definition to be non-inline.
* testsuite/18_support/type_info/constexpr.cc: New test.
libstdc++-v3/config/abi/pre/gnu.ver
libstdc++-v3/include/bits/c++config
libstdc++-v3/include/std/version
libstdc++-v3/libsupc++/tinfo.cc
libstdc++-v3/libsupc++/typeinfo
libstdc++-v3/testsuite/18_support/type_info/constexpr.cc [new file with mode: 0644]