One can define a constexpr
pointer on std::type_info
object of any class T
. Does the language allows one to compare such pointers for equality in compile-time?
For example:
#include <typeinfo>
template <typename T>
inline constexpr auto * pType = &typeid(T);
int main() {
static_assert( pType<int> == pType<int> );
static_assert( pType<int> != pType<char> );
}
The question arises, since Clang accepts it, but GCC returns the error:
error: non-constant condition for static assertion
8 | static_assert( pType<int> != pType<char> );
| ~~~~~~~~~~~^~~~~~~~~~~~~~
<source>:8:31: error: '(((const std::type_info*)(& _ZTIi)) != ((const std::type_info*)(& _ZTIc)))' is not a constant expression
This is a GCC bug: 85428
By the way, pType<int> == pType<int>
is not always guaranteed.