From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 3D4D13858292; Mon, 18 Dec 2023 12:04:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D4D13858292 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1702901077; bh=COyW2vIPfGPCHGKfqlgzGYj2Tx4NE4HFUaCQ25YvKeA=; h=From:To:Subject:Date:From; b=mDLSryfcxtkO1wXU6LhnjSS3jS0LyeSjWQ1dLFuUUdRHtHYwkzq1ivDDU1UJpxLUo 2CVTBeZzBWBvxvGxAAoRkzCPt9Y663MLDqRW18Nl02jNhBoIPXSavyKL1D15x8EiTx jIC2CWrgc2B8K1McUWcLgkKLsfMvMFMOQNid8ePs= From: "m.cencora at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/113064] New: assignement from temporary sometimes invokes copy-assign instead of move-assign operator Date: Mon, 18 Dec 2023 12:04:36 +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: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: m.cencora at gmail 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=3D113064 Bug ID: 113064 Summary: assignement from temporary sometimes invokes copy-assign instead of move-assign operator Product: gcc Version: 13.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: m.cencora at gmail dot com Target Milestone: --- Following code fails to compile on any gcc version with any selected langua= ge version. Works with clang. When invoking the conversion operator the problem does not occur. Also the mere existence of second overloaded conversion operator is problematic. Even though this conversion operator does not participate in overload resolution due to being && qualified. I marked it as deleted to show that this is not the overload being chosen by compiler but just declaring it normally is enough to trigger the bug. Compilation fails with error: : In function 'void test()': :31:10: error: use of deleted function 'no_copy& no_copy::operator=3D(const no_copy&)' 31 | nc =3D f; | ^ :9:14: note: declared here 9 | no_copy& operator=3D(const no_copy&) =3D delete; | ^~~~~~~~ Compiler returned: 1 // test.cpp struct no_copy { no_copy() =3D default; no_copy(const no_copy&) =3D delete; no_copy(no_copy&&); no_copy& operator=3D(const no_copy&) =3D delete; no_copy& operator=3D(no_copy&&); }; struct foo { operator no_copy() & { return no_copy(); } #ifndef WORKAROUND1 operator no_copy&&() && =3D delete; #endif }; void test() { foo f; no_copy nc; #ifndef WORKAROUND2 nc =3D f; #else nc =3D f.operator bar(); #endif }=