可以比较 std::type_info 上的指针在常量表达式中是否相等吗?

Fed*_*dor 5 c++ typeid language-lawyer constexpr c++17

可以在任何类的对象constexpr上定义一个指针。该语言是否允许在编译时比较此类指针是否相等?std::type_infoT

例如:

#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> );
} 
Run Code Online (Sandbox Code Playgroud)

问题出现了,因为 Clang 接受它,但 GCC 返回错误:

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
Run Code Online (Sandbox Code Playgroud)

演示: https: //gcc.godbolt.org/z/9broYrEn7

xsk*_*xzr 5

这是一个 GCC 错误:85428

顺便说一句,pType<int> == pType<int> 并不总是有保证