public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "xgao at nvidia dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/110594] New: std::variant's converting constructor does not resolve alternative correctly Date: Sat, 08 Jul 2023 07:03:13 +0000 [thread overview] Message-ID: <bug-110594-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110594 Bug ID: 110594 Summary: std::variant's converting constructor does not resolve alternative correctly Product: gcc Version: 13.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: xgao at nvidia dot com Target Milestone: --- Created attachment 55502 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55502&action=edit minimum repro According to https://en.cppreference.com/w/cpp/utility/variant/variant, I would expect the attached program to output: int64_t: 1 variant is int However, I am getting: int64_t: 1 variant is complex gcc-9 seems to have the correct behavior for the attached program, however, the implementation of std::variant in gcc-9 has another problem that the following example in that cppreference.com page does not work: std::variant<float, long, double> z = 0; // OK, holds long // float and double are not candidates Thanks to the help of jjsjann123 (https://github.com/jjsjann123), this is potentially related to the SFINAE in the "variant" header: // Helper used to check for valid conversions that don't involve narrowing. template<typename _Ti> struct _Arr { _Ti _M_x[1]; }; seems that this will block int64_t from being selected as shown in https://godbolt.org/z/Gcr4j53rd. However, the following code is totally valid: int64_t x[] = {size_t(1)}; so probably that SFINAE might be wrong.
next reply other threads:[~2023-07-08 7:03 UTC|newest] Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-07-08 7:03 xgao at nvidia dot com [this message] 2023-07-08 7:22 ` [Bug libstdc++/110594] " redi at gcc dot gnu.org 2023-07-08 7:25 ` redi 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-110594-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).