[Bug c++/26838] Legal program rejection - protected base method addressing fails from grandchild class

2006-04-18 Thread Simon80 at gmail dot com


--- Comment #5 from Simon80 at gmail dot com  2006-04-19 04:54 ---
(In reply to comment #4)
> This is not a bug. While the name in a function call is looked up from
> inside the class, the name of a member function is looked up in the
> global scope. There, the member in question here is inaccessible.
> 
> W.
> 

If that were the case, wouldn't the program in comment #3 fail as well? or am I
misunderstanding something?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26838



[Bug c++/26838] New: Legal program rejection - protected base method addressing fails from grandchild class

2006-03-23 Thread Simon80 at gmail dot com
This seems to be similar to a really old bug on one of the mailing lists,
assuming that it's actually a bug:

class A
{
protected:
  void f(){}
};

class B :
  public A
{
int c;
};

class C :
  public B
{
protected:
  void f()
  {
  A::f();  // ok - see http://gcc.gnu.org/ml/gcc-bugs/1997-10/msg00221.html
  &A::f; // error here
  }
};

int main ()
{
C x;
}



# g++ -v
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.0 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-awt=gtk-default --enable-gtk-cairo
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-4.0-1.4.2.0/jre --enable-mpfr
--disable-werror --with-tune=pentium4 --enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.0.3 (Ubuntu 4.0.3-1ubuntu3)


-- 
   Summary: Legal program rejection - protected base method
addressing fails from grandchild class
   Product: gcc
   Version: 4.0.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: Simon80 at gmail dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26838



[Bug c++/26838] Legal program rejection - protected base method addressing fails from grandchild class

2006-03-23 Thread Simon80 at gmail dot com


--- Comment #1 from Simon80 at gmail dot com  2006-03-23 23:44 ---
Sorry for double posting, but here's the g++ output:

# g++ testcase.cpp
testcase.cpp: In member function 'void C::f()':
testcase.cpp:4: error: 'void A::f()' is protected
testcase.cpp:20: error: within this context

Also, this occurs on gcc-3.4.5 as well.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26838



[Bug c++/26838] Legal program rejection - protected base method addressing fails from grandchild class

2006-03-23 Thread Simon80 at gmail dot com


--- Comment #3 from Simon80 at gmail dot com  2006-03-24 07:01 ---
(In reply to comment #2)
> IIRC (there is a bug about this but I cannot find it) pointer to member
> functions are special as you cannot use them to evade accessibility.
> 

I thought of this after I reported the bug, and then I thought of wrapping a
function around the protected one, which apparently can have its address
grabbed just fine:

class A
{
protected:
  void f(){}
};

class B :
  public A
{
int c;
};

class C :
  public B
{
protected:
  void g(){A::f();};
  void f()
  {
  A::f();  // ok - see
http://gcc.gnu.org/ml/gcc-bugs/1997-10/msg00221.html
  //&A::f; // error here
  &C::g;   // ok
  }
};

int main ()
{
C x;
}


Does the above lend some validity to this bug?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26838