c++/264: access to private template member functions possible

r.spatschek@fz-juelich.de r.spatschek@fz-juelich.de
Tue May 30 01:36:00 GMT 2000


>Number:         264
>Category:       c++
>Synopsis:       access to private template member functions possible
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          accepts-illegal
>Submitter-Id:   net
>Arrival-Date:   Tue May 30 01:36:01 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     Robert Spatschek
>Release:        2.95; 2.96 20000529 (experimental)
>Organization:
>Environment:
Linux
>Description:
By specialization it is possible to call private template
member functions from outside. This allows to manipulate
private data of the object. As far as I understand this
is not consistent with the encapsulation principle.
For comparison: The code fragment below is rejected by
DEC C++ (which is correct to my mind).
>How-To-Repeat:
class A
{
private:
  template <class T> void g(T t)  {}
  int i;
};

template <>
void A::g<int>(int t)
{
  i = 1;  // through specialization access to private data becomes possible
}

int main()
{
  A a;
 
  a.g<int>(0);         // accepted by compiler!!!!!!
  // a.g<double>(0);   // rejected by compiler: ok
}
>Fix:

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


More information about the Gcc-prs mailing list