According to the C++23 standard, what is the output of this program?
#include <iostream>
#include <typeinfo>
struct A {};
int main()
{
std::cout<< (&typeid(A) == &typeid(A));
}typeid result?typeid(A) refer the same object?The program is unspecified / implementation defined
The result of a
typeidexpression is an lvalue of static typeconst std::type_info(...).
and §[expr.unary.op]¶3:
The operand of the unary
&operator shall be an lvalue of some typeT. The result is a prvalue.— (...)
— Otherwise, the result has type “pointer to
T” and points to the designated object (...).
So we're comparing two pointers to const std::type_info.
There is no guarantee that the same std::type_info instance will be referred to by all evaluations of the typeid expression on the same type, although std::type_info::hash_code of those type_info objects would be identical, as would be their std::type_index.
(For more info on hash_code(), see §[type.info]¶6: "hash_code() (...) shall return the same value for any two type_info objects which compare equal".)
(For more info on type_index equality, see §[type.index.members] and §[type.info].)