From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4B3053858023; Tue, 7 Dec 2021 09:38:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4B3053858023 From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/103600] New: Cannot use typeid result in constant expressions Date: Tue, 07 Dec 2021 09:38:27 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Dec 2021 09:38:27 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103600 Bug ID: 103600 Summary: Cannot use typeid result in constant expressions Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: rejects-valid Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- This should compile: #include #if __cpp_lib_constexpr_typeinfo constexpr bool b =3D typeid(int) =3D=3D typeid(long); #else constexpr bool b =3D &typeid(int) =3D=3D &typeid(long); #endif But GCC trunk (12.0.0 20211125) says: ti.C:5:33: error: '(((const std::type_info*)(& _ZTIi)) =3D=3D ((const std::type_info*)(& _ZTIl)))' is not a constant expression 5 | constexpr bool b =3D &typeid(int) =3D=3D &typeid(long); | ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ This blocks http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p1328r1.html (Making std::type_info::operator=3D=3D constexpr)=20 With the library changes in place compiling with -std=3Dgnu++23 gives: ti.C:3:32: in 'constexpr' expansion of '((const std::type_info*)(& _ZTIi))->std::type_info::operator=3D=3D(_ZTIl)' ti.C:3:46: error: accessing value of '_ZTIi' through a 'const std::type_inf= o' glvalue in a constant expression 3 | constexpr bool b =3D typeid(int) =3D=3D typeid(long); | ^ Using clang++ -std=3Dc++2b the same patched libstdc++ code gives: ti.C:3:16: error: constexpr variable 'b' must be initialized by a constant expression constexpr bool b =3D typeid(int) =3D=3D typeid(long); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/jwakely/gcc/latest/lib/gcc/x86_64-pc-linux-gnu/12.0.0/../../../../inc= lude/c++/12.0.0/typeinfo:195:9: note: read of object 'typeid(int).__name' whose value is not known if (__name =3D=3D __arg.__name) ^ ti.C:3:32: note: in call to '&typeid(int)->operator=3D=3D(typeid(long))' constexpr bool b =3D typeid(int) =3D=3D typeid(long); ^ Which presumably means that the RTTI for built-in types (defined in libsupc++/fundamental_type_info.cc) needs to be made visible during constant evaluation.=