From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 8AB363858C2D; Tue, 12 Apr 2022 09:07:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8AB363858C2D From: "feildel+gccbugzilla@corona-renderer.com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/94061] defaulted member operator <=> defined as deleted if a base has protected member operator <=> Date: Tue, 12 Apr 2022 09:07:13 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 10.0 X-Bugzilla-Keywords: rejects-valid X-Bugzilla-Severity: normal X-Bugzilla-Who: feildel+gccbugzilla@corona-renderer.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: 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: Tue, 12 Apr 2022 09:07:13 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94061 --- Comment #4 from Baudouin Feildel --- We also ran into this issue with operator=3D=3D(). This behavior might be e= xplained by some implementation detail of the generated code for the operator, but we believe it is wrong because it is inconsistent, see the following example (https://godbolt.org/z/f4EjojExh): struct Base { protected: Base() =3D default; bool operator=3D=3D(const Base& other) const =3D default; }; struct Child : Base { int i =3D 0; Child() =3D default; bool operator=3D=3D(const Child& other) const =3D default; }; int main()=20 { Child a1; Child b1; return a1 =3D=3D b1; } Here calling protected constructor in defaulted ctor is totally fine. But trying to do the same with comparison operator fails with the following compiler error: : In function 'int main()': :17:18: error: use of deleted function 'constexpr bool Child::operator=3D=3D(const Child&) const' 17 | return a1 =3D=3D b1; | ^~ :10:10: note: 'constexpr bool Child::operator=3D=3D(const Child&) c= onst' is implicitly deleted because the default definition would be ill-formed: 10 | bool operator=3D=3D(const Child& other) const =3D default; | ^~~~~~~~ :10:10: error: 'bool Base::operator=3D=3D(const Base&) const' is pr= otected within this context :4:10: note: declared protected here 4 | bool operator=3D=3D(const Base& other) const =3D default; | ^~~~~~~~ This behavior is unfortunate and make it very difficult to use defaulted operator=3D=3D when you have a common base class that should not be compara= ble. See this other example: https://godbolt.org/z/v78r1nYr9.=