From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D059C3857C59; Tue, 25 Oct 2022 10:18:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D059C3857C59 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666693126; bh=FPSAjCfXatYp90jy0ZoFYua/NHIH8kOumos92MaurX0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=pS6vI61EC8CMEwQGN5cdid/lL+m1q4uaKtLykJgBXyCh/oTY6JGaYJP3n7rZuUGO4 nKY0v+yPE3KAQCkp99erWX44xsQVA9aTzsLMjrcdtuljLE2rzyUP7ehntxXLV47zxj PQp69dvNo1nW8AXt0lCQrF9OrtI9NtDBrpwvjLZI= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/107376] regex executor requires allocator to be default constructible Date: Tue, 25 Oct 2022 10:18:45 +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.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: redi at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_status assigned_to 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=3D107376 Jonathan Wakely changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu= .org --- Comment #1 from Jonathan Wakely --- Thanks for the report. The patch is necessary, but not sufficient. We should probably have used the same allocator for _M_rep_count but doing = that now would be an ABI break. We should definitely have used the same allocator for _M_states, and for its _ResultsVec members, which would also be an ABI break, but we can mitigate = that with: --- a/libstdc++-v3/include/bits/regex_executor.tcc +++ b/libstdc++-v3/include/bits/regex_executor.tcc @@ -124,9 +124,10 @@ namespace __detail break; std::fill_n(_M_states._M_visited_states, _M_nfa.size(), false); auto __old_queue =3D std::move(_M_states._M_match_queue); + auto __alloc =3D _M_cur_results.get_allocator(); for (auto& __task : __old_queue) { - _M_cur_results =3D std::move(__task.second); + _M_cur_results =3D _ResultsVec(std::move(__task.second), __al= loc); _M_dfs(__match_mode, __task.first); } if (__match_mode =3D=3D _Match_mode::_Prefix) With this change and the original patch suggestion, _M_cur_results always h= as the same allocator as _M_results and so _Executor::_M_handle_accept won't replace the allocator in _M_results when assigning the new results to it. We could also use the same allocator for the local vector here: bool _Executor<_BiIter, _Alloc, _TraitsT, __dfs_mode>:: _M_lookahead(_StateIdT __next) { // Backreferences may refer to captured content. // We may want to make this faster by not copying, // but let's not be clever prematurely. _ResultsVec __what(_M_cur_results); Or we can rely on select_on_container_copy_construction() to do "the right thing". Users of non-propagating allocators would probably prefer that, but= it means that matching with std::pmr::match_results will always use new/delete= for allocating intermediate results. But that's just one of the costs of the PMR design.=