This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/3028: 3.0 Compiler complains about template that used to work under 2.95
I was unable to understand the template description in Stroustrup (3rd
edition)
well enough to tell if 3.0 or 2.9.5 was right. So you may be right that
3.0
is correct. The argument for 3.0 being wrong is that IListNode is
defined
inside IListBase and so has to be effectively "templated" because
IListBase is.
If 3.0 is correct, from a language point of view, then this would be a
candidate for the list of known bugs at
http://gcc.gnu.org/bugs.html#known
(for GCC 2.95) just like the "G++ allows to access private types".
jim
Artem Khodush wrote:
> >
> > template<class ALLOC> class IListBase
> > {
> > protected:
> > struct IListNode
> > {
> > IListNode *next;
> > int datum;
> > };
> >
> > class IListNode *head;
> > class IListNode *tail;
> >
> > int find(int datum);
> > };
> >
> > template<class ALLOC> int IListBase<ALLOC>::find(int d)
> > {
> > IListNode<ALLOC> *node;
> > for(node = head; node != 0; node = node->next)
> > {
> > if(node->datum == d)
> > {
> > return 1;
> > }
> > }
> > return 0;
> > }
> >
> >
> > >Fix:
> > A workaround seems to be to move the inner node class
> > out of the template list class and make it its own template
> > (but that breaks the protection).
>
> Well, the code works if <ALLOC> after the IListNode is omitted.
> I believe gcc 3.0 is right, IListNode is indeed not a template.