From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CC3F33858422; Wed, 23 Nov 2022 21:34:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC3F33858422 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669239298; bh=Oyh6c2t0bKMFzLVqLwiwlts5sjqV6axxwgXfd+445/c=; h=From:To:Subject:Date:From; b=D3U0yx9SKW2QmfjGq/PTZw5Or44XomnbFIdIO+gu/YgDpaB1Za7oQBZUvy3+mxgt2 Vap2eOwmJqHZUqTP4ZyfMb6gQ+ZFVBOpX3IfeBvnim8L8WQiUtaKTIROuuYVGwcNnI LOgG7lSxJ2Bdm2JVw2vOavugnDgwzShNhCRRZWs4= From: "chgros at synopsys dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107850] New: std::erase_if (map) forces predicate to takes a const value_type Date: Wed, 23 Nov 2022 21:34:58 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: chgros at synopsys 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=3D107850 Bug ID: 107850 Summary: std::erase_if (map) forces predicate to takes a const value_type Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: chgros at synopsys dot com Target Milestone: --- g++11 will compile this program, but g++ 12.1.0 will not, because it compla= ins that the predicate cannot take a const. The standard definition of erase_if (reproduced here for comparison purpose= s) indicates that g++11 is right in this case; this is a regression. #include #include using namespace std; template int erase_if_by_std(map &c, Pred pred) { auto original_size =3D c.size(); for (auto i =3D c.begin(), last =3D c.end(); i !=3D last; ) { if (pred(*i)) { i =3D c.erase(i); } else { ++i; } } return original_size - c.size(); } int main(int argc, char const * const *argv) { auto pred =3D [&](pair &p) { if(p.first.size() =3D=3D 2) { return true; } else { p.second.resize(3); return false; } }; map m; erase_if_by_std(m, pred); std::erase_if(m, pred); }=