GCC Bugzilla has been upgraded from version 4.4.9 to 5.0rc3. If you see any problem, please report it to bug 64968.
Bug 32519 - [4.2/4.3/4.4 regression] g++ allows access to protected template member functions of base class
Summary: [4.2/4.3/4.4 regression] g++ allows access to protected template member funct...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.2
: P2 normal
Target Milestone: 4.2.5
Assignee: Not yet assigned to anyone
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: accepts-invalid, patch
Depends on:
Blocks:
 
Reported: 2007-06-27 02:56 UTC by Gigi Sayfan
Modified: 2008-12-04 15:02 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work: 2.95.3 3.2.3 3.3.6
Known to fail: 3.4.3 4.1.0
Last reconfirmed: 2007-06-27 19:01:01


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gigi Sayfan 2007-06-27 02:56:36 UTC
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
Comment 1 Wolfgang Bangerth 2007-06-27 19:01:01 UTC
Confirmed, a regression apparently introduced in 3.4.x.
Comment 2 Mark Mitchell 2007-10-09 19:21:30 UTC
Change target milestone to 4.2.3, as 4.2.2 has been released.
Comment 3 Joseph S. Myers 2008-02-01 16:54:27 UTC
4.2.3 is being released now, changing milestones of open bugs to 4.2.4.
Comment 4 Joseph S. Myers 2008-05-19 20:23:19 UTC
4.2.4 is being released, changing milestones to 4.2.5.
Comment 5 Joseph S. Myers 2008-07-04 22:47:24 UTC
Closing 4.1 branch.
Comment 6 Fabien Chene 2008-09-05 13:22:45 UTC
There is a patch here:
http://gcc.gnu.org/ml/gcc-patches/2008-09/msg00474.html
Comment 7 Jason Merrill 2008-11-28 22:26:15 UTC
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

Comment 8 Jason Merrill 2008-12-04 15:02:40 UTC
Fixed a while back; ChangeLog entry had wrong PR number.