From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3F51F3858C54; Wed, 7 Jun 2023 15:22:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F51F3858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686151373; bh=vDrq9gFuEKLBnhskvKODCoFAM9IiLgqA4k5XSytggQY=; h=From:To:Subject:Date:From; b=loZVb2isXy5KinmdVWBYYJNBwHnVBS0+UAeZF0rkvMqQ1k9DiUx91UTgHPDOOGZyh oEV33VzRueM9uJ922JdZy96/Qq4VUomQ7BKSXb0Eo/SKiifAlHUHzqWo89IBi4xCBa t2PTRQx0YIBut8eKi5YOrgVzFI2FiGmDC3HsX84o= From: "fchelnokov at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/110158] New: Cannot use union with std::string inside in constant expression Date: Wed, 07 Jun 2023 15:22:52 +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: fchelnokov 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=3D110158 Bug ID: 110158 Summary: Cannot use union with std::string inside in constant expression Product: gcc Version: 13.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: fchelnokov at gmail dot com Target Milestone: --- This program constexpr bool f() { union U{ std::string s; constexpr ~U(){ s.~basic_string(); } } u{}; return true; } static_assert( f() ); is accepted in MSVC and Clang with libc++. But in GCC it produces the error: error: non-constant condition for static assertion in 'constexpr' expansion of 'f()' in 'constexpr' expansion of '(& u)->f()::U::~U()' in 'constexpr' expansion of '((f()::U*)this)->f()::U::s.std::__cxx11::basic_string::~basic_string= ()' /opt/compiler-explorer/gcc-13.1.0/include/c++/13.1.0/bits/basic_string.h:80= 3:19: in 'constexpr' expansion of '((std::__cxx11::basic_string*)this)->std::__cxx11::basic_string::_M_dispose()' error: accessing 'std::__cxx11::basic_string::::_M_allocated_capacity' member instead of initialized 'std::__cxx11::basic_string::::_M_local_buf' member in constant expression Online demo: https://gcc.godbolt.org/z/bbf4Yo3v9=