public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.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 [thread overview] Message-ID: <bug-103600-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103600 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 <typeinfo> #if __cpp_lib_constexpr_typeinfo constexpr bool b = typeid(int) == typeid(long); #else constexpr bool b = &typeid(int) == &typeid(long); #endif But GCC trunk (12.0.0 20211125) says: ti.C:5:33: error: '(((const std::type_info*)(& _ZTIi)) == ((const std::type_info*)(& _ZTIl)))' is not a constant expression 5 | constexpr bool b = &typeid(int) == &typeid(long); | ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~ This blocks http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p1328r1.html (Making std::type_info::operator== constexpr) With the library changes in place compiling with -std=gnu++23 gives: ti.C:3:32: in 'constexpr' expansion of '((const std::type_info*)(& _ZTIi))->std::type_info::operator==(_ZTIl)' ti.C:3:46: error: accessing value of '_ZTIi' through a 'const std::type_info' glvalue in a constant expression 3 | constexpr bool b = typeid(int) == typeid(long); | ^ Using clang++ -std=c++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 = typeid(int) == typeid(long); ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~ /home/jwakely/gcc/latest/lib/gcc/x86_64-pc-linux-gnu/12.0.0/../../../../include/c++/12.0.0/typeinfo:195:9: note: read of object 'typeid(int).__name' whose value is not known if (__name == __arg.__name) ^ ti.C:3:32: note: in call to '&typeid(int)->operator==(typeid(long))' constexpr bool b = typeid(int) == 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.
next reply other threads:[~2021-12-07 9:38 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-12-07 9:38 redi at gcc dot gnu.org [this message] 2021-12-07 9:51 ` [Bug c++/103600] " pinskia at gcc dot gnu.org 2021-12-07 9:52 ` pinskia at gcc dot gnu.org 2021-12-07 10:01 ` redi at gcc dot gnu.org 2021-12-07 13:23 ` jakub at gcc dot gnu.org 2021-12-07 13:47 ` redi at gcc dot gnu.org 2021-12-07 16:44 ` jakub at gcc dot gnu.org 2021-12-08 0:30 ` redi at gcc dot gnu.org 2022-01-03 10:24 ` cvs-commit at gcc dot gnu.org 2022-01-03 10:34 ` jakub at gcc dot gnu.org 2022-01-06 14:49 ` ppalka at gcc dot gnu.org 2022-11-03 13:29 ` ppalka at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-103600-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).