From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A38EE3858C78; Tue, 19 Mar 2024 06:27:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A38EE3858C78 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1710829657; bh=AfwxcVm/b6rbnmZYqfNgTi66FhchSjV/J2h7vbpJp+k=; h=From:To:Subject:Date:From; b=KhUI1EiGLdXGo2gpKdC/gAoFKQh1c4AkPwqnP2bLQjRdvS+P6V/YD1HC9oBEkE6lN n6k7kN6Ele+9FhuYGned12q57RcOODKLLsGuYzBwIoJ4DraeM76dhoirloflFuidO3 7UhZIohNeb4hj7luSgRz8CO2rKPgvVDoSpK6gBQM= From: "de34 at live dot cn" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/114388] New: Behavioral change of typeid on xvalues since GCC 9 Date: Tue, 19 Mar 2024 06:27:36 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 9.5.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: de34 at live dot cn 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 keywords bug_severity priority component assigned_to reporter target_milestone 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=3D114388 Bug ID: 114388 Summary: Behavioral change of typeid on xvalues since GCC 9 Product: gcc Version: 9.5.0 Status: UNCONFIRMED Keywords: wrong-code Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: de34 at live dot cn Target Milestone: --- IIUC this program behaves differently in C++98 and C++11 due to WG21 N3055 (https://wg21.link/n3055): ``` #include #include struct B { virtual ~B() { std::puts("~B"); } }; struct D : B {}; struct WrapB { B b; }; struct WrapD { D d; }; int main() { typeid(true ? WrapB().b : WrapD().d); } ``` Before C++11/N3055, the operand of the typeid expression shouldn't be evalu= ated because it's a rvalue. But since C++11 it should be evaluated because it's a glvalue of a polymorphic class type. It's curious that GCC behaves consistently on this in C++98 and C++11 modes. Per https://godbolt.org/z/7oGdjdMK7, it seems that GCC 8 (and former versio= ns) applied the C++98 rules to C++11 and later modes, and GCC 9 (and later veri= ons) applied the C++11 rules to C++98 mode. For later versions, I'm not sure whether this is a bug (in C++98 mode) or an intentional backporting.=