From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 99A3F3858C60; Sat, 8 Jul 2023 07:03:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 99A3F3858C60 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688799794; bh=NMhRIjx7ULHAvTBMYjp0M9WLuKjHJMZGESSC4nhksQ0=; h=From:To:Subject:Date:From; b=UbTTYGDg2IKu5TvZ7bdeqUOcAXl2RY2mt7zNO1ZvsfhMuqHsZxxjTRpPlxVgoB3ZU LMlKDIoGZu0aYE4i4w1czsAzSoMCbc+z+F6aAetklzmyHP3ihZ3+7Zran+XQFXeyrA ZPv01Oo2ACRfl/GqUgQ9wzADGqg7V42kRIyNqr+8= From: "xgao at nvidia dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.1.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: xgao at nvidia dot com 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 bug_severity priority component assigned_to reporter target_milestone attachments.created 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110594 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=3D55502&action=3Dedit minimum repro According to https://en.cppreference.com/w/cpp/utility/variant/variant, I w= ould 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 follow= ing example in that cppreference.com page does not work: std::variant z =3D 0; // OK, holds long // float and double are not candid= ates 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 narrowin= g. template 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 val= id: int64_t x[] =3D {size_t(1)}; so probably that SFINAE might be wrong.=