From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 431B43858C52; Thu, 2 Feb 2023 21:05:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 431B43858C52 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1675371929; bh=Ebz/GVr9rcDhTMbTTyUE3Nr/5vYneX6QObMc2bwJxGw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=wxnfgZlZy2l/aUrtscGSxmTb7KljqS5JkzKLDNFr9lHBuiDXPP961+pLI2hsu51fR nLmfz5oGejUxk8lNaBMKOv7xbQTYLtAoCXZmECUriY/p9cyjpSi+mCOX6lnOyFbGsM D7b4ewEM7+V3LdB1bv8c7skHoNVCgGoPyhh+wbtg= From: "eteran at alum dot rit.edu" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/108645] Change in behavior, std::accumulate doesn't always work as expected in C++20 builds Date: Thu, 02 Feb 2023 21:05:29 +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: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: eteran at alum dot rit.edu 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=3D108645 --- Comment #1 from Evan Teran --- To further experiment, i factored out `std::accumulate`: ``` #include #include #include #include void print_v(const char *rem, const std::vector &v) { std::cout << rem; for (const std::string &s : v) std::cout << '"' << s << '"' << ' '; std::cout << '\n'; } int main() { std::vector v =3D {"this", "_", "is", "_", "an", "_", "example"}; print_v("Old contents of the vector: ", v); std::string concat; auto first =3D std::make_move_iterator(v.begin()); auto last =3D std::make_move_iterator(v.end()); for (; first !=3D last; ++first) { #if __cplusplus >=3D 202002L concat =3D std::move(concat) + *first; #else concat =3D concat + *first; #endif } print_v("New contents of the vector: ", v); std::cout << "Concatenated as string: " << '"' << concat << '"' << '\n'; } ``` Which results in the same behavior, so it appears to be that the: ``` basic_string operator+(basic_string &&, basic_string &&) ``` Overload doesn't steal the guts of the rhs at all? But the=20 ``` basic_string operator+(const basic_string &, basic_string &&) ``` overload does?=