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 libstdc++/103240] New: std::type_info::before gives wrong answer for ARM EABI Date: Mon, 15 Nov 2021 00:20:33 +0000 [thread overview] Message-ID: <bug-103240-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103240 Bug ID: 103240 Summary: std::type_info::before gives wrong answer for ARM EABI Product: gcc Version: 12.0 Status: UNCONFIRMED Keywords: ABI Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: redi at gcc dot gnu.org Target Milestone: --- Target: arm*-*-*gnueabi This passes on x86_64 but fails on armv7hl: // f1.C #include <typeinfo> namespace { struct S { }; } std::type_info const& t1 = typeid(S); // f2.C #include <typeinfo> #include <cassert> extern std::type_info const& t1; namespace { struct S { }; } std::type_info const& t2 = typeid(S); int main() { if (t1 == t2) { assert( !t1.before(t2) ); assert( !t2.before(t1) ); } else { assert( t1.before(t2) || t2.before(t1) ); } } $ g++ f1.C f2.C $ ./a.out a.out: f2.C:22: int main(): Assertion `t1.before(t2) || t2.before(t1)' failed. qemu: uncaught target signal 6 (Aborted) - core dumped Aborted (core dumped) The problem is in libsupc++/tinfo2.cc bool type_info::before (const type_info &arg) const _GLIBCXX_NOEXCEPT { #if __GXX_MERGED_TYPEINFO_NAMES return name () < arg.name (); #else return (name ()[0] == '*') ? name () < arg.name () : __builtin_strcmp (name (), arg.name ()) < 0; #endif } This should have been fixed like operator== was in r179236 so that it checks __name[0] not name()[0], otherwise the '*' is skipped and so is never found there. That means we do a strcmp comparison of the mangled names, even when the '*' says the types must be compared by pointer address. In the testcase the two structs have the same mangled name, even though they are distinct types (due to the unnamed namespaces). The string comparison therefore returns 0, and so neither type is "before" the other, despite being distinct types.
next reply other threads:[~2021-11-15 0:20 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-11-15 0:20 redi at gcc dot gnu.org [this message] 2021-11-15 0:21 ` [Bug libstdc++/103240] " redi at gcc dot gnu.org 2021-11-15 0:36 ` redi at gcc dot gnu.org 2021-11-17 17:22 ` cvs-commit at gcc dot gnu.org 2021-11-17 17:42 ` redi at gcc dot gnu.org 2021-11-23 21:17 ` cvs-commit at gcc dot gnu.org 2023-04-29 16:15 ` frankhb1989 at gmail dot com 2023-04-29 18:01 ` frankhb1989 at gmail dot com 2023-05-02 16:56 ` redi at gcc dot gnu.org 2023-05-04 10:31 ` frankhb1989 at gmail dot com 2023-05-04 11:04 ` redi at gcc dot gnu.org 2023-05-05 16:28 ` frankhb1989 at gmail dot com
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-103240-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).