From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6A307385840D; Tue, 29 Aug 2023 13:21:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6A307385840D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693315287; bh=lx30sz+2zrYOny9yZnTSmCQW1UD+ooxgTKtn4hmX6Xo=; h=From:To:Subject:Date:From; b=Mv3L61GTDv32hVRzcN1l0gdGJNqeGtpMu28Vz2Y65mks9Dyt6TQkZA+W7H/ox5GCE WHldWqXF69wzksaxsc33mrdBTerh6istuF/QwaXZM8ELbuQzfYiU2Oan1WUHRX3Q3r FH3XoOejl7nyF5qo2tmsDmS67xF2CUuoepuRkQck= From: "nathanieloshead at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/111226] New: constexpr doesn't detect change of union to empty member Date: Tue, 29 Aug 2023 13:21:26 +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: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: nathanieloshead at gmail 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 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=3D111226 Bug ID: 111226 Summary: constexpr doesn't detect change of union to empty member Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: nathanieloshead at gmail dot com Target Milestone: --- While working on a patch for PR101631, I found that the following code is currently incorrectly handled by GCC: (https://godbolt.org/z/1YevacMK3) struct Empty {}; union U { int x; Empty e; }; constexpr int foo() { U u{ 10 }; u.e =3D {}; return u.x; // incorrectly accepted, even pre-C++20 } constexpr auto y =3D foo(); constexpr Empty bar() { U u{ 10 }; u.e =3D {}; return u.e; // incorrectly errors, thinks active member is still 'x' } constexpr auto x =3D bar(); The cause seems to be that the zero-sized trivial assignment is removed in call.cc (since PR43075) and after constant folding is no longer in the tree that the constexpr handling machinery receives.=