Opened 10 years ago

Closed 9 years ago

#7230 closed Bugs (invalid)

access to private method using boost::bind

Reported by: anonymous Owned by: Peter Dimov
Milestone: To Be Determined Component: bind
Version: Boost 1.49.0 Severity: Problem
Keywords: bind Cc: viboes

Description

It appears that the privacy of a class method is violated with the use of boost::bind in a template class.

$ uname -a

Linux myhost.mydomain 2.6.32-220.13.1.el6.x86_64 #1 SMP Thu Mar 29 11:46:40 EDT 2012 x86_64 x86_64 x86_64 GNU/Linux

$ g++ --version

g++ (GCC) 4.4.6 20110731 (Red Hat 4.4.6-3)

#include <boost/bind.hpp>
#include <iostream>

class base
{
private:
  void _private() { std::cout << "private" << std::endl; }
};

template<class T>
class templ
{
public:
  void onPrivate(T* t) {
    // boost::bind(&T::_private, t)(); // error: ‘void base::_private()’ is private
    boost::bind(&base::_private, t)();
  }
};

int main(int argc, char **argv)
{
  base b;
  templ<base> ab;
  ab.onPrivate(&b); // got into the private parts :)
  // boost::bind(&base::_private, &b)(); // error: ‘void base::_private()’ is private
}

Change History (2)

comment:1 by viboes, 10 years ago

Cc: viboes added

Isn't this a compiler bug?

comment:2 by Peter Dimov, 9 years ago

Resolution: invalid
Status: newclosed

This is a problem with the specific compiler.

Note: See TracTickets for help on using tickets.