c++/10841: rejects valid explicit conversion to/from pointers-to-member of private base

[email protected]
Newsgroups gmane.comp.gcc.prs
Message-ID <[email protected]>
>Number:         10841
>Category:       c++
>Synopsis:       rejects valid explicit conversion to/from pointers-to-member of private base
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    unassigned
>State:          open
>Class:          rejects-legal
>Submitter-Id:   net
>Arrival-Date:   Sun May 18 05:16:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Shane Beasley
>Release:        gcc version 3.3 20030415 (Debian prerelease)
>Organization:
>Environment:
Linux v2.4.19 (Debian) on Intel x86-compatible
>Description:
Section 5.4, paragraph 7, of ISO/IEC 14882:1998 (ISO C++) allows C-style cast notation to convert a pointer-to-member of a derived class to a pointer-to-member of a unambiguous non-virtual base class or vice versa, regardless of the accessibility of the base class.

GCC 3.3 emits the following diagnostic:

<stdin>: In function `int main()':
<stdin>:9: error: `main()::Base' is an inaccessible base of `main()::Derived'
<stdin>:10: error: `main()::Base' is an inaccessible base of `main()::Derived'
>How-To-Repeat:
int main () {
  class Base { public: int i, j, k; };
  class Derived : private Base { public: int m, n, p; };

  Derived derived;
  Base &base = (Base &)derived;

  // neither line compiles; 5.4p7 allows both
  base.*((int Base::*)&Derived::n) = 0xdeadbeef;
  derived.*((int Derived::*)&Base::j) = 0xc0decafe;
}
>Fix:
Do not check for accessibility of the base class if C-style cast notation is used.
>Release-Note:
>Audit-Trail:
>Unformatted:
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.