From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D2DF4394740F; Wed, 4 Aug 2021 16:13:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D2DF4394740F From: "gcc at mattwhitlock dot name" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/58040] Cannot take address-of public using-declaration of member from protected base class Date: Wed, 04 Aug 2021 16:13:37 +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: 4.8.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gcc at mattwhitlock dot name X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: fabien 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: Wed, 04 Aug 2021 16:13:37 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D58040 --- Comment #8 from Matt Whitlock --- Maybe this example will demonstrate it more clearly. /* begin example */ class PublicBase { public: void pub_base_pub_memb(); protected: void pub_base_prot_memb(); }; class ProtectedBase { public: void prot_base_pub_memb(); protected: void prot_base_prot_memb(); }; class Derived : public PublicBase, protected ProtectedBase { public: using PublicBase::pub_base_pub_memb; using PublicBase::pub_base_prot_memb; using ProtectedBase::prot_base_pub_memb; using ProtectedBase::prot_base_prot_memb; }; void (Derived::*pub_base_pub_memb)() =3D &Derived::pub_base_pub_memb; void (Derived::*pub_base_prot_memb)() =3D &Derived::pub_base_prot_memb; void (Derived::*prot_base_pub_memb)() =3D &Derived::prot_base_pub_memb; // = ERROR void (Derived::*prot_base_prot_memb)() =3D &Derived::prot_base_prot_memb; // ERROR void func(Derived *d) { d->Derived::pub_base_pub_memb(); d->Derived::pub_base_prot_memb(); d->Derived::prot_base_pub_memb(); // OK d->Derived::prot_base_prot_memb(); // OK auto pub_base_pub_memb =3D &Derived::pub_base_pub_memb; auto pub_base_prot_memb =3D &Derived::pub_base_prot_memb; auto prot_base_pub_memb =3D &Derived::prot_base_pub_memb; // OK auto prot_base_prot_memb =3D &Derived::prot_base_prot_memb; // OK (d->*pub_base_pub_memb)(); (d->*pub_base_prot_memb)(); (d->*prot_base_pub_memb)(); // ERROR (d->*prot_base_prot_memb)(); // ERROR } /* end example */ As you can see, it is possible to call all four member functions directly u= sing their qualified names, but it is not possible to assign the addresses of the members from the protected base into variables whose type is pointer to mem= ber function of the derived class, nor is it possible to call the members of the protected base indirectly through pointers to member function of the derived class. Maybe this is a defect of the language? It's certainly an asymmetry and a surprise.=