Topic: BUG in AT&T 3.0 ? (Was problem with template friend ?)
Author: cbarghie@watcgl.waterloo.edu (Chris Barghiel)
Date: Thu, 7 May 1992 00:34:12 GMT Raw View
In article <22749@alice.att.com>, bs@alice.att.com (Bjarne Stroustrup) writes:
>
> [...] Then try this:
>
> #include<iostream.h>
> template <class T, int sz>
> class stack {
> friend ostream& operator<< (ostream& os, stack<T,sz>);
> public:
> stack () { index = 0; }
> void push (T elem) { tab[index++] = elem; }
> T pop (void) { return tab[--index]; }
> private:
> T tab[sz];
> int index;
> };
>
> template <class T>
> ostream& operator<< (ostream& os, T st)
> {
> for (int i=0; i<st.index; i++)
> os << st.tab[i] << endl;
> return os;
> }
>
> It works.
Yes, it does. But now try this: replace the signature of pop() with one that
takes a default argument:
T pop (int x=5) { return tab[--index]; }
and run the code through your AT&T 3.0 compiler. It does NOT work anymore.
Please refer to article #23736 of comp.lang.c++, in which I presented the
problem in detail and offered a similar piece of code to support the case.
For short, if a templated class contains member functions with one or more
default arguments, and is in a 1:1 relationship with a friend function
whose argument(s) is/are templated, AT&T 3.0 complains with the message:
"error: function templates do not support default arguments".
I seriously doubt the validity of this error message, and I hope somebody
from AT&T can provide a definite explanation. If what I have encountered
is indeed a bug, is it a known one? Will a patch be available in the near
future? For the time being, how can one avoid it while still using default
arguments and 1:1 relationships with templated friend functions?
-Chris Barghiel
P.S. I am told that BC++ compiles the code without making any complaints.
--
Cristin Barghiel DC 2134, (519)885-1211 x3389
cbarghie@watcgl.waterloo.edu Dept. of Computer Science
cbarghie@watcgl.uwaterloo.ca University of Waterloo, Canada