Derived classes may access protected members of their base class only on themselves or other instances of the same type or derived type. Here is a link to the relevant section in the draft of the C++ standard: http://www.csci.csusb.edu/dick/c++std/cd2/access.html#class.protected I don't have access to the actual standard, but I figure you do :-). The bug occurs when the protected member is a template member function. If the protected member is a simple data member the code fails to compile as it should. BTW, VC++ 2005 catches this bug and refuses to compile the test program. Test Program (bug.cpp) ---------------------- struct B { protected: template <typename T> T getX() { return T(x); } protected: int x; }; struct D : public B { D(B * b) { //x = b->x; // fails to compile (correct) x = b->getX<int>(); // doesn't fail to compile (bug) } }; int main (int argc, char * const argv[]) { B b; D d(&b); } Output of gcc -v ---------------- Using built-in specs. Target: x86_64-unknown-linux-gnu Configured with: ../src/gcc-4.0.2/configure : (reconfigured) ../src/gcc-4.0.2/configure Thread model: posix gcc version 4.0.2 Build command ------------- g++ -Wall bug.cpp -o bug
Confirmed, a regression apparently introduced in 3.4.x.
Change target milestone to 4.2.3, as 4.2.2 has been released.
4.2.3 is being released now, changing milestones of open bugs to 4.2.4.
4.2.4 is being released, changing milestones to 4.2.5.
Closing 4.1 branch.
There is a patch here: http://gcc.gnu.org/ml/gcc-patches/2008-09/msg00474.html
Subject: Bug 32519 Author: jason Date: Fri Nov 28 22:24:49 2008 New Revision: 142264 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=142264 Log: PR c++/32519 * g++.dg/template/pr32519.C: New test. Added: trunk/gcc/testsuite/g++.dg/template/pr32519.C
Fixed a while back; ChangeLog entry had wrong PR number.