User account creation filtered due to spam.

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...
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
Keywords: accepts-invalid, patch
Depends on:
Reported: 2007-06-27 02:56 UTC by Gigi Sayfan
Modified: 2008-12-04 15:02 UTC (History)
6 users (show)

See Also:
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


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:

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
  template <typename T>
  T getX()
    return T(x);
  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:
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

        PR c++/32519
        * g++.dg/template/pr32519.C: New test.


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