This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Bug in 1.0.3


Turns out that the example I submitted last night wasn't quite
correct.  The difference is that the apply function taken by
helper0<T> takes a NON-const reference to T.  However, the apply
function taken by foo<T> takes a const reference to T.  The cast is
required to remove the const.

[2(rlk)||{!21}<rlk-ppp-1>/tmp]
% g++ -c foo.C
foo.C: In method `void foo<void *>::apply(void (*)(void *const &, void *), void *)':
foo.C:40: Internal compiler error.
foo.C:40: Please submit a full bug report to `egcs-bugs@cygnus.com'.


template<class T>
class helper0
{
public:
  void apply(void (*appfun)(T&, void *), void*);
  T content_;
};

template<class T>
void helper0<T>::apply(void (*appfun)(T&, void *), void* data)
{
  appfun(content_, data);
}

template<class T>
class helper1
{
public:
  T* operator()(int i) { return contents_[i]; }
private:
  T* contents_[10];
};

template<class T>
class foo
{
public:
  void apply(void (*appfun)(const T&, void *), void *data);
private:
  helper1<helper0<T> > contents_;
};


template<class T>
void
foo<T>::apply(void (*appfun)(const T&, void *), void *data)
{
  int i;
  for (i = 0; i < 10; i++)
    contents_(i)->apply((void (*)(T&, void *))appfun, data);
}

template class foo<void *>;


If I remove the cast, I get the following error:

% g++ -c foo.C
foo.C: In method `void foo<void *>::apply(void (*)(void *const &, void *), void *)':
foo.C:40: no matching function for call to `helper0<void *>::apply (void (*&)(void *const &, void *), void *&)'
foo.C:11: candidates are: helper0<void *>::apply(void (*)(void *&, void *), void *)

template<class T>
void
foo<T>::apply(void (*appfun)(const T&, void *), void *data)
{
  int i;
  for (i = 0; i < 10; i++)
    contents_(i)->apply(/*(void (*)(T&, void *))*/appfun, data);
}

-- 
Robert Krawitz <rlk@tiac.net>	       http://www.tiac.net/users/rlk/

Tall Clubs International  --  http://www.tall.org/ or 1-888-IM-TALL-2
Member of the League for Programming Freedom -- mail lpf@uunet.uu.net

"Linux doesn't dictate how I work, I dictate how Linux works."
--Eric Crampton


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]