public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/103600] Cannot use typeid result in constant expressions Date: Tue, 07 Dec 2021 13:23:25 +0000 [thread overview] Message-ID: <bug-103600-4-GQjGGUPS1K@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-103600-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103600 Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |hubicka at gcc dot gnu.org, | |jakub at gcc dot gnu.org, | |jason at gcc dot gnu.org --- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> --- We handle e.g. constexpr auto x = &typeid(int) == &typeid(int); or int a, b; constexpr auto y = &a == &b; The former by the (cmp @0 @0) folding in match.pd, the latter by the address_compare match.pd patterns. But, we already punt on e.g. template <int N> inline int a = N; constexpr auto c = &a<0> == &a<1>; because address_compare -> equal_address_to punts on those, decl_binds_to_current_def_p is false (they are comdat and can end up being defined from some other TU etc.). And similarly it punts in the &typeid(int) == &typeid(long) case, neither _ZTIi nor _ZTIl are defined in the current TU (both are defined in libstdc++) and the code attempts to play safe, say if the actual definitions would be aliases of each other etc. I guess at least for constexpr evaluation we want to have some C++ rules, both for typeid vars - dunno if we can rely on the get_tinfo_decl_direct created vars to be always different if they aren't the same VAR_DECL, or if we need to e.g. compute the name and compare those, or for stuff like inline vars or variable templates. And the question is if cxx_eval_binary_expression should for EQ_EXPR/NE_EXPR repeat what the match.pd address_compare simplification does with its own address_compare, or if it should temporarily set some langhook and let address_compare use that langhook to handle the special cases, or if a langhook should handle some of those cases always for C++. Another case is the typeid(int) == typeid(long) comparison, operator== is I think bool operator==(const type_info& __arg) const _GLIBCXX_NOEXCEPT { return ((__name == __arg.__name) || (__name[0] != '*' && __builtin_strcmp (__name, __arg.__name) == 0)); } so we'd need to be able to constant fold during constexpr evaluation typeid(int).__name to &_ZTSi when the typeinfo isn't defined locally and handle &_ZTSwhatever similarly to &_ZTIwhatever, but further we even need to constant fold reading from those strings even when they aren't local..
next prev parent reply other threads:[~2021-12-07 13:23 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-12-07 9:38 [Bug c++/103600] New: " redi at gcc dot gnu.org 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 [this message] 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-GQjGGUPS1K@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).