This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gcc-4.3.2(beta) - Invalid conversion to pointer to protected base class


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]