From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id E42B83858296; Wed, 7 Jun 2023 19:40:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E42B83858296 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686166827; bh=/mdUbrgaOCTGWrwPwjFXVmI/jpP2u/jE21g75ShT7cA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jQ+t51DwotNbaloIuFldPTsbexs+QoAFlWklSU2suoh+vBIpxyuzorTib0d8iBXu3 ekcjswqox/rYzqQPxPePi4/MTG2Mv0Y6wcAnJFzJJaXw9hzGsBhgYawKF3qajygUGU oOeZtZ/OolCK1t7XX3v8CEt6VUFhrOaEOHNO8lzw= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/110158] Cannot use union with std::string inside in constant expression Date: Wed, 07 Jun 2023 19:40:27 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 13.1.0 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: pinskia at gcc dot gnu.org 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=3D110158 --- Comment #1 from Andrew Pinski --- Here is a slightly reduced testcase (for a slightly different issue still dealing with unions): ``` struct str1 { // bool a; char *var; union { char t[15]; int allocated; }; constexpr str1() : var(new char[2]) { t[0] =3D 0; } constexpr ~str1() {if (var !=3D t) delete[] var; } }; typedef str1 str; constexpr bool f1() { str t{}; return true; } static_assert( f1() ); constexpr bool f() { union U{ str s; constexpr ~U(){ s.~str(); } } u{}; return true; } static_assert( f() ); ```=