[libcxx-commits] [PATCH] D143447: [libc++] Implement P1328R1 constexpr std::type_info::operator==
Aaron Ballman via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Feb 7 07:13:18 PST 2023
aaron.ballman added a comment.
Precommit CI looks like it perhaps has some relevant failures that need to be addressed.
================
Comment at: libcxx/include/typeinfo:110-111
bool operator==(const type_info& __arg) const _NOEXCEPT {
+ // When evaluated in a constant espression, both type infos simply can't come
+ // from different translation units, so it is sufficient to compare their addresses.
+ if (__libcpp_is_constant_evaluated()) {
----------------
================
Comment at: libcxx/include/typeinfo:342
{
+ // When evaluated in a constant espression, both type infos simply can't come
+ // from different translation units, so it is sufficient to compare their addresses.
----------------
================
Comment at: libcxx/test/std/language.support/support.rtti/type.info/type_info.equal.pass.cpp:11
+//
+// bool operator==(const type_info& rhs) const noexcept; // constexpr since C++23
+
----------------
Mordante wrote:
> Can you add a test for `noexcept` too?
I'd also like a test for typeid of a polymorphic type since that's special. e.g.,
```
#include <typeinfo>
struct Base {
virtual void func() {}
};
struct Derived : Base {
virtual void func() {}
};
static constexpr Derived D;
constexpr const Base &get_it() {
return D;
}
static_assert(typeid(get_it()) == typeid(Derived));
```
(or something similar)
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D143447/new/
https://reviews.llvm.org/D143447
More information about the libcxx-commits
mailing list