c++/5930: Incorrect access control checking on static data members

adc@ee.port.ac.uk adc@ee.port.ac.uk
Tue Mar 12 15:26:00 GMT 2002


>Number:         5930
>Category:       c++
>Synopsis:       Incorrect access control checking on static data members
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          accepts-illegal
>Submitter-Id:   net
>Arrival-Date:   Tue Mar 12 15:26:00 PST 2002
>Closed-Date:
>Last-Modified:
>Originator:     Alastair Channon
>Release:        3.0.2 (and 2.96)
>Organization:
>Environment:
Red Hat Linux release 7.2
>Description:
The following program is invalid, but is accepted by
g++, without even a warning (even with -pedantic -Wall).

As I understand it, Child::childFunc() should not be allowed
access to Parent::parentVar, which is private in Parent.

This is probably related to Problem Report 3664.

#include <iostream>
using namespace std;

class Parent { private: static int parentVar; }; // parentVar is **private**
int Parent::parentVar=999;

class Child : public Parent { public: void childFunc(); };
void Child::childFunc() { cout << parentVar << endl; } // can access parentVar (**BAD**)
//nb same bug with protected and private inheritance

int main(int argc,char* argv[])
{
  Child child;
  // cout << child.parentVar << endl; // cannot access parentVar (good)
  child.childFunc();
  return 0;
}
>How-To-Repeat:

>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list