From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 39223385840C; Wed, 1 Dec 2021 15:46:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 39223385840C From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/96074] Associative containers never propagate allocator on copy assignment Date: Wed, 01 Dec 2021 15:46:22 +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: 11.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID 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: resolution bug_status 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Dec 2021 15:46:22 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96074 Jonathan Wakely changed: What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |INVALID Status|ASSIGNED |RESOLVED --- Comment #2 from Jonathan Wakely --- Your test allocator has a bug. You do not override the is_always_equal trait from the base class, which means you inherit std::allocator::is_always_e= qual which is defined to be std::true_type. So the associative containers elide = the propagation: if (_Alloc_traits::_S_propagate_on_copy_assign()) { auto& __this_alloc =3D this->_M_get_Node_allocator(); auto& __that_alloc =3D __x._M_get_Node_allocator(); if (!_Alloc_traits::_S_always_equal() && __this_alloc !=3D __that_alloc) { // Replacement allocator cannot free existing storage, we need // to erase nodes first. clear(); std::__alloc_on_copy(__this_alloc, __that_alloc); } } If I add this to the primary template and the partial specialization then a= ll tests pass (including the commented-out one for std::stringbuf): using is_always_equal =3D std::false_type; You have been bitten by LWG 3170: https://cplusplus.github.io/LWG/issue3170 std::allocator::is_always_equal is deprecated for precisely this reason (it's a very annoying trap) but it's still there in C++20, so you need to override it. Closing, as the libstdc++ containers are already correct.=