delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/07/06/15:42:48

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00,SPF_PASS
X-Spam-Check-By: sourceware.org
Message-ID: <4A52539B.2020702@googlemail.com>
Date: Mon, 06 Jul 2009 20:42:19 +0100
From: Paul Bibbings <paul DOT bibbings AT googlemail DOT com>
User-Agent: Thunderbird 2.0.0.22 (Windows/20090605)
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: gcc-4.3.2(beta) - Invalid conversion to pointer to protected base class
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

The following code compiles successfully using gcc-4.3.2 (Cygwin,
gcc 4.3.2 20080827 (beta) 2) running under Windows Vista (Ver 6.0
Build 6002 Service Pack 2).

    // inaccessible_test.cpp
    class X { };

    class Y : protected X { };

    class Z : private X {
    public:
        void f(Y *);
    };

    void Z::f(Y *p_y)
    {
        X *p_x = p_y;        // #1
    }

    [compiled with gcc-4 -c inaccessible_test.cpp]

I would have expected this to have failed at the line marked #1 with
an error "'X' is an inaccessible base of 'Y'." If class Y is changed
so that it derives from X using private inheritance, that is:

    class Y : private X { };

compilation then fails (appropriately, in my view) with the above error
message.

Furthermore, if I add the following in main:

    int main()
   {
        Y y;
        X *p_x = &y;        // #2

        return 0;
    }

the error "'X' is an inaccessible base of 'Y'" is reported at line #2.

In my opinion the compiler is falsely interpreting protected
inheritance of Y from X to grant access to the protected base
to any class that likewise derives from X, rather than just
from Y itself and any other class that in turn derives from Y.
(The rejection of line #2 in main appears to indicate that it is
not as simple as that the protected access is ignored in all
cases.)

This issue appears to be closely related to (if not duplicating)
GCC Bugzilla Bug 35640
(http://gcc.gnu.org/bugzilla/show_bug.cgi?id=35640).

Paul Bibbings

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019