From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 07599386F421; Tue, 29 Dec 2020 18:05:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 07599386F421 From: "b.stanimirov at abv dot bg" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/98473] New: std::vector::insert(pos, first, last) doesn't compile for T which has a deleted assignment operator Date: Tue, 29 Dec 2020 18:05:22 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new 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: b.stanimirov at abv dot bg 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 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: Tue, 29 Dec 2020 18:05:23 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98473 Bug ID: 98473 Summary: std::vector::insert(pos, first, last) doesn't compile for T which has a deleted assignment operator Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: b.stanimirov at abv dot bg Target Milestone: --- Create a class `X` which is copy-constructible but not copy-assignable ``` struct X { X(); X(const X&); X& operator=3D(const X&) =3D delete; // !! X(X&&) noexcept; X& operator=3D(X&&) noexcept; int data =3D 54; }; ``` Have vectors of X `a` and `b`. Try to add all elements of b at the front of= a: ``` void add_to_front(std::vector& a, const std::vector& b) { a.insert(a.begin(), b.begin(), b.end()); } ``` Live demo: https://godbolt.org/z/K1WT8n It doesn't compile. My guess is that code which will never get invoked, sti= ll needs to compile (or, worse yet, copy assignment does get invoked?!) The only way to achieve the desired behavior efficiently is to use a custom vector implementation. There is a stackoverflow question which has some workarounds *with worse performance*: https://stackoverflow.com/questions/65489039/how-to-efficiently-insert-mult= iple-copy-constructible-but-not-copy-assignable-el This does compile and work on msvc, so a compile-time check for the copy-assignment code is possible. As pointed out in the stackoverflow thread, copy-assignability is not listed here: https://en.cppreference.com/w/cpp/container/vector/insert#Parameters This looks like a bug in libstdc++ (as opposed to a omission by the standar= d)=