From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 949113858D1E; Fri, 17 Nov 2023 16:53:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 949113858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1700240011; bh=HX/unQLpP4NdmhB5Farg2t8tH3KhIhATJcFEnEiFsAg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=d8sXE0tdvIfml0QYY46Q78jijXdYWPD0/Ns0ihXCQkOWHAYcDu+5OuJYWSOW4/w+3 z7K3wXOdp8q+lUUcnSn0F5W5GJEWF1Dr5h1+qsJPVwpekWzaZCWFsIK6G/xo4VR+fS KJkMW+/kfKatHQuL8sozAGLMByq/bk47Bmo/5fQM= From: "barry.revzin at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/112591] variant allows for creating multiple empty objects at same address Date: Fri, 17 Nov 2023 16:53:31 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.1.0 X-Bugzilla-Keywords: ABI 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: Message-ID: In-Reply-To: References: 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 --- Comment #1 from Barry Revzin --- Basically, in C++17, Sub looks like this: struct Sub17 : Empty { aligned_membuf storage; unsigned char index; }; But in C++20 it turns into: struct Sub20 : Empty { union { Empty storage; }; unsigned char index; }; sizeof(Sub17) =3D=3D 2 because of the empty base optimization, but sizeof(S= ub20) =3D=3D 3 because now the language understands that storage is an Empty and thus ne= eds a distinct address from the Empty base class.=