From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5F1723858425; Fri, 17 Nov 2023 16:02:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5F1723858425 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1700236969; bh=qDTa71OGUkroG3yc7EQXTmAeBLkKfY+vN3P7V9ha+uM=; h=From:To:Subject:Date:From; b=yCwJj99f+AAVmcMoyL7kS0PZYt53aGtMrHucY1ZhWfiq3Xjkg+khW1QSzCFq+lwR5 iAKhjHvPdQGwouw4b4JzvYgHva1GgSBOZ2VxrbfuSHFrOFfcCRmSCvn+LLTxKGZ6el T1dm5JL97AoBFXx6EpuJ2OXVluH1Dzil6IyI7vjQ= From: "barry.revzin at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/112591] New: variant allows for creating multiple empty objects at same address Date: Fri, 17 Nov 2023 16:02:49 +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.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: barry.revzin 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=3D112591 Bug ID: 112591 Summary: variant allows for creating multiple empty objects at same address Product: gcc Version: 13.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: barry.revzin at gmail dot com Target Milestone: --- Consider: #include #include struct Empty { ~Empty() {} }; struct Sub : Empty { std::variant e; }; int main() { Sub v; Empty* base =3D &v; Empty* obj =3D &std::get(v.e); std::cout << "base=3D" << (void*)base << " obj=3D" << (void*)obj << " matches=3D" << (base =3D=3D obj) << '\n'; } In C++17 mode on trunk, base and obj have the same address. In C++20 mode up through 11.4, they have the same address. Since 12.1, they= do not. If Empty were trivially destructible, they never have the same address.=