This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
c++/5930: Incorrect access control checking on static data members
- From: adc at ee dot port dot ac dot uk
- To: gcc-gnats at gcc dot gnu dot org
- Date: 12 Mar 2002 23:16:43 -0000
- Subject: c++/5930: Incorrect access control checking on static data members
- Reply-to: adc at ee dot port dot ac dot uk
>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: