From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 19E4E3858C42; Wed, 22 Nov 2023 11:22:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 19E4E3858C42 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1700652138; bh=qWqMFBPXQEVPomhdgcID6WVQ71pbsJsDranbNeLpNbw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=tMY3Rj1d0B2g7tymcfXCsATMYO7Chje95rejLN8cwCNLYpBZW7bbOWyOJoXPCST0/ Z8oK7vskgRg56MyB+ogjWIngnhWJNBeh6OACR5EAR099yiwBblTKuLD5MlZ5hdyO+O hOi2tO3YkIf2mkqZ22eQZy3KKgQzLXvc9BbJmxMs= From: "miro.palmu at helsinki dot fi" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/112642] ranges::fold_left tries to access inactive union member of string in constant expression Date: Wed, 22 Nov 2023 11:22:16 +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.2.1 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: miro.palmu at helsinki dot fi X-Bugzilla-Status: NEW 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=3D112642 --- Comment #7 from Miro Palmu --- (In reply to Jonathan Wakely from comment #6) > The examples in comment 4 do compile using libstdc++ on clang, if you use > libstdc++ headers from after sept 29 (for trunk) or oct 21 (for gcc-13). I was testing this on compiler explorer on clang 17.0.1 and it used gcc-13.= 2.0 libstdc++. Also tried it locally with clang 16.0.6 with gcc-13.2.1 libstdc++ Output: $ cat prog.cpp=20 #include #include int main() { [](std::string s =3D {}) consteval { std::string ss{ std::move(s) }; }(); } $ clang prog.cpp -std=3Dc++2b -stdlib=3Dlibstdc++ prog.cpp:4:5: error: call to consteval function 'main()::(anonymous class)::operator()' is not a constant expression [](std::string s =3D {}) consteval { ^ /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13= .2.1/bits/stl_construct.h:97:14: note: construction of subobject of member '_M_local_buf' of union with no active member is not allowed in a constant expression { return ::new((void*)__location) _Tp(std::forward<_Args>(__args)...); } ^ /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13= .2.1/bits/char_traits.h:272:6: note: in call to 'construct_at(&ss.._M_local_buf[0], s.._M_local_buf[0])' std::construct_at(__s1 + __i, __s2[__i]); ^ /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13= .2.1/bits/char_traits.h:443:11: note: in call to 'copy(&ss.._M_local_buf[0], &s.._M_local_buf[0], 1)' return __gnu_cxx::char_traits::copy(__s1, __s2, __n); ^ /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/13.2.1/../../../../include/c++/13= .2.1/bits/basic_string.h:672:6: note: in call to 'copy(&ss.._M_local_buf[0], &s.._M_local_buf[0], 1)' traits_type::copy(_M_local_buf, __str._M_local_buf, ^ prog.cpp:5:21: note: in call to 'basic_string(s)' std::string ss{ std::move(s) }; ^ prog.cpp:4:5: note: in call to '&[](std::string s) { std::string ss{std::move(s)}; }->operator()({{{{}}, &s.._M_local_buf[0]}, 0, {._M_local_buf =3D {0, 0, 0,= 0, 0, 0, 0, 0, 0, 0, ...}}})' [](std::string s =3D {}) consteval { ^ 1 error generated.=